diff options
| author | Barry Warsaw | 2016-04-30 13:34:04 -0400 |
|---|---|---|
| committer | GitLab | 2016-04-30 19:54:54 +0000 |
| commit | c6eb7ee3e574b48ee016dd31af2014b0ed083268 (patch) | |
| tree | 14c1f1e7bb382898ee50909333365aab335aa4a1 /src/mailman/utilities/filesystem.py | |
| parent | 465f24ff33e154385322ee894d32d8b7dd9b3941 (diff) | |
| download | mailman-c6eb7ee3e574b48ee016dd31af2014b0ed083268.tar.gz mailman-c6eb7ee3e574b48ee016dd31af2014b0ed083268.tar.zst mailman-c6eb7ee3e574b48ee016dd31af2014b0ed083268.zip | |
Diffstat (limited to 'src/mailman/utilities/filesystem.py')
| -rw-r--r-- | src/mailman/utilities/filesystem.py | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/mailman/utilities/filesystem.py b/src/mailman/utilities/filesystem.py index e8935b92c..e89f2abb8 100644 --- a/src/mailman/utilities/filesystem.py +++ b/src/mailman/utilities/filesystem.py @@ -18,8 +18,8 @@ """Filesystem utilities.""" import os -import errno +from contextlib import suppress from mailman import public @@ -54,18 +54,18 @@ def makedirs(path, mode=0o2775): :param mode: The numeric permission mode to use. :type mode: int """ - try: + with suppress(FileExistsError): with umask(0): os.makedirs(path, mode) - except OSError as error: - # Ignore the exceptions if the directory already exists. - if error.errno != errno.EEXIST: - raise # Some systems such as FreeBSD ignore mkdir's mode, so walk the just # created directories and try to set the mode, ignoring any OSErrors that # occur here. for dirpath, dirnames, filenames in os.walk(path): - try: + with suppress(OSError): os.chmod(dirpath, mode) - except OSError: - pass + + +@public +def safe_remove(path): + with suppress(FileNotFoundError): + os.remove(path) |
