Add the unlink_file function to file_utils. This fills in a gap between
python 3.6 and features provided in pathlib.Path in later versions of
python. Adds an option to ignore all errors for good measure.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
def make_run_dir(fsid: str, uid: int, gid: int) -> None:
makedirs(f'/var/run/ceph/{fsid}', uid, gid, 0o770)
+
+
+def unlink_file(
+ path: Union[str, Path],
+ missing_ok: bool = False,
+ ignore_errors: bool = False,
+) -> None:
+ """Wrapper around unlink that can either ignore missing files or all
+ errors.
+ """
+ try:
+ Path(path).unlink()
+ except FileNotFoundError:
+ if not missing_ok and not ignore_errors:
+ raise
+ except Exception:
+ if not ignore_errors:
+ raise