Fixed a race condition in media-monitor

* Prevent exception if files are copied in very quickly
This commit is contained in:
Albert Santoni 2014-01-30 15:58:52 -05:00
parent c9d98e4e10
commit 2525c0dbd6
1 changed files with 7 additions and 1 deletions

View File

@ -114,7 +114,13 @@ def clean_empty_dirs(path):
full_paths = ( os.path.join(root, d) for d in dirs )
for d in full_paths:
if os.path.exists(d):
if not os.listdir(d): os.removedirs(d)
#Try block avoids a race condition where a file is added AFTER listdir
#is run but before removedirs. (Dir is not empty and removedirs throws
#an exception in that case then.)
try:
if not os.listdir(d): os.removedirs(d)
except OSError:
pass
def extension(path):
"""