aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndré Erdmann <dywi@mailerd.de>2013-07-23 11:31:34 +0200
committerAndré Erdmann <dywi@mailerd.de>2013-07-23 11:31:34 +0200
commiteb054c34b1af6b908d4df808742113d42e218d12 (patch)
treeb834731a1ff83ca4925ff12483b22ded96bc1eea
parentroverlay/remote/rsync: minor fixup (diff)
downloadR_overlay-eb054c34b1af6b908d4df808742113d42e218d12.tar.gz
R_overlay-eb054c34b1af6b908d4df808742113d42e218d12.tar.bz2
R_overlay-eb054c34b1af6b908d4df808742113d42e218d12.zip
roverlay/util/common: try_unlink()
Remove a file if it exists and ignore errors caused by non-existence.
-rw-r--r--roverlay/util/common.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/roverlay/util/common.py b/roverlay/util/common.py
index a2c155a..f27593a 100644
--- a/roverlay/util/common.py
+++ b/roverlay/util/common.py
@@ -8,9 +8,10 @@
__all__= [
'dodir', 'for_all_files', 'get_dict_hash', 'keepenv', 'priosort', 'sysnop',
- 'getsize', 'is_vcs_dir', 'headtail'
+ 'getsize', 'is_vcs_dir', 'headtail', 'try_unlink',
]
+import errno
import os
import sys
import logging
@@ -26,6 +27,21 @@ def headtail ( iterable ):
return ( iterable[0], iterable[1:] )
# --- end of headtail #py2 (...) ---
+def try_unlink ( fspath ):
+ """Tries to remove a file. Does not fail if the file did not exist.
+
+ arguments:
+ * fspath --
+ """
+ try:
+ os.unlink ( fspath )
+ except OSError as oserr:
+ if oserr.errno == errno.ENOENT:
+ pass
+ else:
+ raise
+# --- end of try_unlink (...) ---
+
def for_all_files (
files_or_dirs, func,
args=(), kwargs={}, file_filter=None, ignore_missing=False