From 2c18a54e4d7786b992bb550a0974aa4b98e8068b Mon Sep 17 00:00:00 2001 From: David Rheinsberg Date: Mon, 19 Dec 2022 10:23:10 +0100 Subject: [PATCH] util/fscache: avoid RENAME_NOREPLACE on commit We used to commit cache-entries with a rename+RENAME_NOREPLACE. This, however, is not available on NFS. Change the code to use `os.rename()` and rely on the _documented_ kernel behavior that non-empty target directories cannot be replaced. Signed-off-by: David Rheinsberg --- osbuild/util/fscache.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/osbuild/util/fscache.py b/osbuild/util/fscache.py index ed901d87..f8804ec5 100644 --- a/osbuild/util/fscache.py +++ b/osbuild/util/fscache.py @@ -900,12 +900,16 @@ class FsCache(contextlib.AbstractContextManager, os.PathLike): # As last step move the entry to the desired location. If the # target name is already taken, we bail out and pretend the # entry was immediately overwritten by another one. + # + # Preferably, we used RENAME_NOREPLACE, but this is not + # available on all file-systems. Hence, we rely on the fact + # that non-empty directories cannot be replaced, so we + # automatically get RENAME_NOREPLACE behavior. path_name = self._path(self._dirname_objects, name) try: - self._libc.renameat2( - oldpath=path_uuid.encode(), - newpath=path_name.encode(), - flags=self._libc.RENAME_NOREPLACE, + os.rename( + src=path_uuid, + dst=path_name, ) except OSError as e: ignore = [errno.EEXIST, errno.ENOTDIR, errno.ENOTEMPTY]