Skip to content

Commit cfd09c8

Browse files
committed
Handle empty dir issue
1 parent f1337aa commit cfd09c8

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

mbed/mbed.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,23 +1358,26 @@ def cache_lock(self, url):
13581358
time.sleep(1)
13591359

13601360
if os.path.exists(lock_dir):
1361-
if os.path.isfile(lock_file):
1362-
with open(lock_file, 'r', 0) as f:
1363-
pid = f.read(8)
1364-
if not pid:
1365-
if int(os.path.getmtime(lock_file)) + timeout < int(time.time()):
1366-
info("Cache lock file exists, but is empty. Cleaning up")
1361+
try:
1362+
if os.path.isfile(lock_file):
1363+
with open(lock_file, 'r', 0) as f:
1364+
pid = f.read(8)
1365+
if not pid:
1366+
if int(os.path.getmtime(lock_file)) + timeout < int(time.time()):
1367+
info("Cache lock file exists, but is empty. Cleaning up")
1368+
os.remove(lock_file)
1369+
os.rmdir(lock_dir)
1370+
elif int(pid) != os.getpid() and self.pid_exists(pid):
1371+
info("Cache lock file exists and process %s is alive." % pid)
1372+
else:
1373+
info("Cache lock file exists, but %s is dead. Cleaning up" % pid)
13671374
os.remove(lock_file)
13681375
os.rmdir(lock_dir)
1369-
elif int(pid) != os.getpid() and self.pid_exists(pid):
1370-
info("Cache lock file exists and process %s is alive." % pid)
13711376
else:
1372-
info("Cache lock file exists, but %s is dead. Cleaning up" % pid)
1373-
os.remove(lock_file)
13741377
os.rmdir(lock_dir)
1375-
else:
1376-
os.rmdir(lock_dir)
1377-
continue
1378+
continue
1379+
except (OSError) as e:
1380+
continue
13781381
else:
13791382
try:
13801383
os.mkdir(lock_dir)

0 commit comments

Comments
 (0)