{
SN_CAUGHT(e);
- info_dir.unlink(tmp_name, 0);
+ info_dir.unlink(tmp_name);
return false;
}
/*
* Copyright (c) [2011-2014] Novell, Inc.
- * Copyright (c) [2018-2024] SUSE LLC
+ * Copyright (c) [2018-2025] SUSE LLC
*
* All Rights Reserved.
*
#include <sys/xattr.h>
#include <sys/statvfs.h>
#include <fcntl.h>
-#include <stddef.h>
+#include <cstddef>
#include <dirent.h>
#include <unistd.h>
#include <cerrno>
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);
}
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) << ")");
}
/*
* Copyright (c) [2011-2014] Novell, Inc.
- * Copyright (c) [2020-2023] SUSE LLC
+ * Copyright (c) [2020-2025] SUSE LLC
*
* All Rights Reserved.
*
#include <fcntl.h>
+#include <sys/types.h>
#include <string>
#include <vector>
#include <functional>
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;
{
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"));
}
}
}
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) << ")");
}
// 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
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) << ")");
}
}
{
SN_CAUGHT(e);
- info_dir.unlink(tmp_name, 0);
+ info_dir.unlink(tmp_name);
SN_RETHROW(e);
}
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);
}
snapshot.deleteFilesystemSnapshot();
SDir infos_dir = snapper->openInfosDir();
- infos_dir.unlink(decString(snapshot.getNum()), AT_REMOVEDIR);
+ infos_dir.rmdir(decString(snapshot.getNum()));
SN_RETHROW(e);
}
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);