-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update makedirs function to not supress OSErrors #3404
base: proton_4.11
Are you sure you want to change the base?
Changes from 5 commits
0c2bd15
02d0377
eb08e1f
09be8ef
da569c1
644a257
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,9 +45,12 @@ def file_is_wine_fake_dll(path): | |
|
||
def makedirs(path): | ||
try: | ||
if os.path.lexists(path): | ||
return | ||
|
||
os.makedirs(path) | ||
except OSError: | ||
#already exists | ||
except OSError as err: | ||
log("Error when creating directory {0}: {1}".format(path, err)) | ||
pass | ||
|
||
def try_copy(src, dst): | ||
|
@@ -165,9 +168,10 @@ class CompatData: | |
dirs.append(path) | ||
for d in dirs: | ||
try: | ||
os.rmdir(d) | ||
except OSError: | ||
#not empty | ||
if not any(os.scandir(d)): | ||
os.rmdir(d) | ||
except OSError as err: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I could gather checking if the directory is empty before attempting to do the operation is less expensive than letting it throw an exception and catching it. Would we still prefer going with the latter approach? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no measurable performance difference between the two (although the deletion and seeing whether it fails is most likely faster as it results in less syscalls on average) but with the exception handling race conditions are impossible. That's typically recommended way to handle these things. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. I hadn't considered race conditions. I'll make the changes in a bit :) |
||
log("Error deleting directory {0}: {1}".format(d, err)) | ||
pass | ||
|
||
os.remove(self.tracked_files_file) | ||
|
@@ -257,7 +261,7 @@ class CompatData: | |
rel_dir = rel_dir + "/" | ||
dst_dir = src_dir.replace(g_proton.default_pfx_dir, self.prefix_dir, 1) | ||
if not os.path.exists(dst_dir): | ||
os.makedirs(dst_dir) | ||
makedirs(dst_dir) | ||
tracked_files.write(rel_dir + "\n") | ||
for dir_ in dirs: | ||
src_file = os.path.join(src_dir, dir_) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use FileExistsError instead of OSError