Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11208)

Unified Diff: client/utils/file_path.py

Issue 2066913002: swarming-cipd: fix for Windows (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@master
Patch Set: file_path.remove Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « client/cipd.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/utils/file_path.py
diff --git a/client/utils/file_path.py b/client/utils/file_path.py
index 85491e8f7459a8cf51592511dc4291f21d6dd6ee..8675e3b1754dbe8277dac8841feab9265411555f 100644
--- a/client/utils/file_path.py
+++ b/client/utils/file_path.py
@@ -726,18 +726,23 @@ def set_read_only_swallow(path, read_only):
return e
+def remove(filepath):
+ """Removes a file, even if it is read-only."""
+ # TODO(maruel): Not do it unless necessary since it slows this function
+ # down.
+ if sys.platform == 'win32':
+ # Deleting a read-only file will fail if it is read-only.
+ set_read_only(filepath, False)
+ else:
+ # Deleting a read-only file will fail if the directory is read-only.
+ set_read_only(os.path.dirname(filepath), False)
+ fs.remove(filepath)
+
+
def try_remove(filepath):
"""Removes a file without crashing even if it doesn't exist."""
try:
- # TODO(maruel): Not do it unless necessary since it slows this function
- # down.
- if sys.platform == 'win32':
- # Deleting a read-only file will fail if it is read-only.
- set_read_only(filepath, False)
- else:
- # Deleting a read-only file will fail if the directory is read-only.
- set_read_only(os.path.dirname(filepath), False)
- fs.remove(filepath)
+ remove(filepath)
except OSError:
pass
« no previous file with comments | « client/cipd.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698