@@ -187,11 +187,28 @@ def _system_info():
187187 raise NotImplementedError
188188
189189
190- def generate_id ():
190+ def _generate_id ():
191191 """A randomly generated ID string"""
192192 return str (uuid .uuid4 ()) # TODO: CI env-based ID
193193
194194
195+ def _read_user_id (config_file : Path ):
196+ try :
197+ with config_file .open (encoding = "utf8" ) as fobj :
198+ return json .load (fobj )["user_id" ]
199+ except (FileNotFoundError , ValueError , KeyError ):
200+ pass
201+ return None
202+
203+
204+ def _read_user_id_locked (config_file : Path ):
205+ lockfile = str (config_file .with_suffix (".lock" ))
206+ if config_file .parent .is_dir ():
207+ with FileLock (lockfile , timeout = 5 ):
208+ return _read_user_id (config_file )
209+ return None
210+
211+
195212@lru_cache (None )
196213def _find_or_create_user_id ():
197214 """
@@ -209,19 +226,16 @@ def _find_or_create_user_id():
209226 config_file_old = Path (
210227 user_config_dir (os .path .join ("dvc" , "user_id" ), "iterative" )
211228 )
212- lockfile_old = str (config_file_old .with_suffix (".lock" ))
213229
214230 try :
215231 with FileLock ( # pylint: disable=abstract-class-instantiated
216232 lockfile , timeout = 5
217233 ):
218- user_id = read_user_id (config_file )
234+ user_id = _read_user_id (config_file )
219235 if user_id is None :
220- if config_file_old .parent .is_dir ():
221- with FileLock (lockfile_old , timeout = 5 ):
222- user_id = read_user_id (config_file_old )
223- if user_id is None :
224- user_id = generate_id ()
236+ user_id = _read_user_id_locked (config_file_old )
237+ if user_id is None :
238+ user_id = _generate_id ()
225239 with config_file .open (mode = "w" , encoding = "utf8" ) as fobj :
226240 json .dump ({"user_id" : user_id }, fobj )
227241
@@ -230,12 +244,3 @@ def _find_or_create_user_id():
230244 except Timeout :
231245 logger .debug ("Failed to acquire %s" , lockfile )
232246 return None
233-
234-
235- def read_user_id (config_file : Path ):
236- try :
237- with config_file .open (encoding = "utf8" ) as fobj :
238- return json .load (fobj )["user_id" ]
239- except (FileNotFoundError , ValueError , KeyError ):
240- pass
241- return None
0 commit comments