]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- improved logging 997/head
authorArvin Schnell <aschnell@suse.de>
Fri, 4 Apr 2025 10:12:01 +0000 (12:12 +0200)
committerArvin Schnell <aschnell@suse.de>
Fri, 4 Apr 2025 10:12:01 +0000 (12:12 +0200)
snapper/Comparison.cc
snapper/FileUtils.cc
snapper/FileUtils.h
snapper/Lvm.cc
snapper/Snapshot.cc

index 7bcd80e5cee281eca3eb083ac15897b5625364f6..ee272ae94eac560d9ae4eaf9bb2a997ad74c9984 100644 (file)
@@ -366,7 +366,7 @@ namespace snapper
        {
            SN_CAUGHT(e);
 
-           info_dir.unlink(tmp_name, 0);
+           info_dir.unlink(tmp_name);
 
            return false;
        }
index ca3f9de3351be8cfe94d6cb8ea6b52a1f637d905..17868232408176208c82ca4e47eb1af5a47d4bfd 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) [2011-2014] Novell, Inc.
- * Copyright (c) [2018-2024] SUSE LLC
+ * Copyright (c) [2018-2025] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -30,7 +30,7 @@
 #include <sys/xattr.h>
 #include <sys/statvfs.h>
 #include <fcntl.h>
-#include <stddef.h>
+#include <cstddef>
 #include <dirent.h>
 #include <unistd.h>
 #include <cerrno>
@@ -335,12 +335,22 @@ namespace snapper
 
 
     int
-    SDir::unlink(const string& name, int flags) const
+    SDir::rmdir(const string& name) const
     {
        assert(name.find('/') == string::npos);
        assert(name != "..");
 
-       return ::unlinkat(dirfd, name.c_str(), flags);
+       return ::unlinkat(dirfd, name.c_str(), AT_REMOVEDIR);
+    }
+
+
+    int
+    SDir::unlink(const string& name) const
+    {
+       assert(name.find('/') == string::npos);
+       assert(name != "..");
+
+       return ::unlinkat(dirfd, name.c_str(), 0);
     }
 
 
@@ -880,8 +890,8 @@ namespace snapper
 
     TmpDir::~TmpDir()
     {
-       if (base_dir.unlink(name, AT_REMOVEDIR) != 0)
-           y2err("unlink failed, errno:" << errno);
+       if (base_dir.rmdir(name) != 0)
+           y2err("rmdir failed, errno:" << errno << " (" << stringerror(errno) << ")");
     }
 
 
index 7cf0d689c6378f95d39127affcbd92b17192ba06..088ab0aa754dcfcd5008dba33b90f2e3e7188b90 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) [2011-2014] Novell, Inc.
- * Copyright (c) [2020-2023] SUSE LLC
+ * Copyright (c) [2020-2025] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -26,6 +26,7 @@
 
 
 #include <fcntl.h>
+#include <sys/types.h>
 #include <string>
 #include <vector>
 #include <functional>
@@ -87,7 +88,8 @@ namespace snapper
        int open(const string& name, int flags, mode_t mode) const;
        ssize_t readlink(const string& name, string& buf) const;
        int mkdir(const string& name, mode_t mode) const;
-       int unlink(const string& name, int flags) const;
+       int rmdir(const string& name) const;
+       int unlink(const string& name) const;
        int chmod(const string& name, mode_t mode, int flags) const;
        int chown(const string& name, uid_t owner, gid_t group, int flags) const;
        int rename(const string& oldname, const string& newname) const;
index 625a98c9efea74f0f03c0b538bc4fc92f512d3e6..2b64bdbec3bd9ec18194a23b58b29921df332579 100644 (file)
@@ -182,10 +182,10 @@ namespace snapper
     {
        SDir subvolume_dir = openSubvolumeDir();
 
-       int r1 = subvolume_dir.unlink(SNAPSHOTS_NAME, AT_REMOVEDIR);
+       int r1 = subvolume_dir.rmdir(SNAPSHOTS_NAME);
        if (r1 != 0)
        {
-           y2err("rmdir failed errno:" << errno << " (" << strerror(errno) << ")");
+           y2err("rmdir '" SNAPSHOTS_NAME "' failed errno:" << errno << " (" << strerror(errno) << ")");
            SN_THROW(DeleteConfigFailedException("rmdir failed"));
        }
     }
@@ -293,10 +293,12 @@ namespace snapper
        }
 
        SDir info_dir = openInfoDir(num);
-       info_dir.unlink(SNAPSHOT_NAME, AT_REMOVEDIR);
+       if (info_dir.rmdir(SNAPSHOT_NAME) < 0)
+            y2err("rmdir '" SNAPSHOT_NAME "' failed errno: " << errno << " (" << stringerror(errno) << ")");
 
        SDir infos_dir = openInfosDir();
-       infos_dir.unlink(decString(num), AT_REMOVEDIR);
+       if (infos_dir.rmdir(decString(num)) < 0)
+            y2err("rmdir '" << num << "' failed errno: " << errno << " (" << stringerror(errno) << ")");
     }
 
 
index 200c128e4148e30115d444ef74c8086469d679aa..efee43a0fdc8a5947a613ba6f092996826c5255a 100644 (file)
@@ -215,7 +215,8 @@ namespace snapper
        // remove all filelists in the info directory of this snapshot
        for (const string& name : info_dir.entries(is_filelist_file))
        {
-           info_dir.unlink(name, 0);
+           if (info_dir.unlink(name) < 0)
+               y2err("unlink '" << name << "' failed errno: " << errno << " (" << stringerror(errno) << ")");
        }
 
        // remove all filelists of the snapshot in the info directories of other snapshots
@@ -226,8 +227,11 @@ namespace snapper
 
            SDir tmp = snapshot.openInfoDir();
            string name = filelist_name(snapshot.getNum());
-           tmp.unlink(name, 0);
-           tmp.unlink(name + ".gz", 0);
+
+           if (tmp.unlink(name) < 0 && errno != ENOENT)
+               y2err("unlink '" << name << "' failed errno: " << errno << " (" << stringerror(errno) << ")");
+           if (tmp.unlink(name + ".gz") < 0 && errno != ENOENT)
+               y2err("unlink '" << name << ".gz' failed errno: " << errno << " (" << stringerror(errno) << ")");
        }
     }
 
@@ -571,7 +575,7 @@ namespace snapper
        {
            SN_CAUGHT(e);
 
-           info_dir.unlink(tmp_name, 0);
+           info_dir.unlink(tmp_name);
 
            SN_RETHROW(e);
        }
@@ -776,7 +780,7 @@ namespace snapper
            SN_CAUGHT(e);
 
            SDir infos_dir = snapper->openInfosDir();
-           infos_dir.unlink(decString(snapshot.getNum()), AT_REMOVEDIR);
+           infos_dir.rmdir(decString(snapshot.getNum()));
 
            SN_RETHROW(e);
        }
@@ -791,7 +795,7 @@ namespace snapper
 
            snapshot.deleteFilesystemSnapshot();
            SDir infos_dir = snapper->openInfosDir();
-           infos_dir.unlink(decString(snapshot.getNum()), AT_REMOVEDIR);
+           infos_dir.rmdir(decString(snapshot.getNum()));
 
            SN_RETHROW(e);
        }
@@ -839,10 +843,12 @@ namespace snapper
        snapshot->deleteFilelists();
 
        SDir info_dir = snapshot->openInfoDir();
-       info_dir.unlink("info.xml", 0);
+       if (info_dir.unlink("info.xml") < 0)
+           y2err("unlink 'info.xml' failed errno: " << errno << " (" << stringerror(errno) << ")");
 
        SDir infos_dir = snapper->openInfosDir();
-       infos_dir.unlink(decString(snapshot->getNum()), AT_REMOVEDIR);
+       if (infos_dir.rmdir(decString(snapshot->getNum())) < 0)
+           y2err("rmdir '" << snapshot->getNum() << "' failed errno: " << errno << " (" << stringerror(errno) << ")");
 
        Plugins::delete_snapshot(Plugins::Stage::POST_ACTION, snapper->subvolumeDir(), snapper->getFilesystem(),
                                 *snapshot, report);