fs-util: Drop unlink_noerrno()

This commit is contained in:
Daan De Meyer
2023-03-15 11:55:44 +01:00
parent a45332500d
commit 39eb3ffaaa
6 changed files with 12 additions and 36 deletions

View File

@@ -33,11 +33,6 @@
#include "umask-util.h"
#include "user-util.h"
int unlink_noerrno(const char *path) {
PROTECT_ERRNO;
return RET_NERRNO(unlink(path));
}
int rmdir_parents(const char *path, const char *stop) {
char *p;
int r;
@@ -674,7 +669,7 @@ void unlink_tempfilep(char (*p)[]) {
* successfully created. We ignore both the rare case where the
* original suffix is used and unlink failures. */
if (!endswith(*p, ".XXXXXX"))
(void) unlink_noerrno(*p);
(void) unlink(*p);
}
int unlinkat_deallocate(int fd, const char *name, UnlinkDeallocateFlags flags) {

View File

@@ -22,8 +22,6 @@
#define PTR_TO_MODE(p) ((mode_t) ((uintptr_t) (p)-1))
#define MODE_TO_PTR(u) ((void *) ((uintptr_t) (u)+1))
int unlink_noerrno(const char *path);
int rmdir_parents(const char *path, const char *stop);
int rename_noreplace(int olddirfd, const char *oldpath, int newdirfd, const char *newpath);
@@ -99,7 +97,7 @@ static inline char* unlink_and_free(char *p) {
if (!p)
return NULL;
(void) unlink_noerrno(p);
(void) unlink(p);
return mfree(p);
}
DEFINE_TRIVIAL_CLEANUP_FUNC(char*, unlink_and_free);

View File

@@ -100,7 +100,7 @@ void release_lock_file(LockFile *f) {
f->operation = LOCK_EX|LOCK_NB;
if ((f->operation & ~LOCK_NB) == LOCK_EX)
unlink_noerrno(f->path);
(void) unlink(f->path);
f->path = mfree(f->path);
}

View File

@@ -262,13 +262,14 @@ static int copy_file_with_version_check(const char *from, const char *to, bool f
r = fsync_full(fd_to);
if (r < 0) {
(void) unlink_noerrno(t);
(void) unlink(t);
return log_error_errno(r, "Failed to copy data from \"%s\" to \"%s\": %m", from, t);
}
if (renameat(AT_FDCWD, t, AT_FDCWD, to) < 0) {
(void) unlink_noerrno(t);
return log_error_errno(errno, "Failed to rename \"%s\" to \"%s\": %m", t, to);
r = RET_NERRNO(renameat(AT_FDCWD, t, AT_FDCWD, to));
if (r < 0) {
(void) unlink(t);
return log_error_errno(r, "Failed to rename \"%s\" to \"%s\": %m", t, to);
}
log_info("Copied \"%s\" to \"%s\".", from, to);

View File

@@ -1456,9 +1456,10 @@ static int manager_generate_key_pair(Manager *m) {
return log_error_errno(errno, "Failed to move public key file into place: %m");
temp_public = mfree(temp_public);
if (rename(temp_private, "/var/lib/systemd/home/local.private") < 0) {
(void) unlink_noerrno("/var/lib/systemd/home/local.public"); /* try to remove the file we already created */
return log_error_errno(errno, "Failed to move private key file into place: %m");
r = RET_NERRNO(rename(temp_private, "/var/lib/systemd/home/local.private"));
if (r < 0) {
(void) unlink("/var/lib/systemd/home/local.public"); /* try to remove the file we already created */
return log_error_errno(r, "Failed to move private key file into place: %m");
}
temp_private = mfree(temp_private);

View File

@@ -508,25 +508,6 @@ TEST(chase_symlinks_at) {
fd = safe_close(fd);
}
TEST(unlink_noerrno) {
char *name;
int fd;
name = strjoina(arg_test_dir ?: "/tmp", "/test-close_nointr.XXXXXX");
fd = mkostemp_safe(name);
assert_se(fd >= 0);
assert_se(close_nointr(fd) >= 0);
{
PROTECT_ERRNO;
errno = 42;
assert_se(unlink_noerrno(name) >= 0);
assert_se(errno == 42);
assert_se(unlink_noerrno(name) < 0);
assert_se(errno == 42);
}
}
TEST(readlink_and_make_absolute) {
const char *tempdir, *name, *name2, *name_alias;
_cleanup_free_ char *r1 = NULL, *r2 = NULL, *pwd = NULL;