tmpfile-util: turn last parameter of link_tmpfile() into a proper flags
This changes a boolean param into a proper bitflag field. Given this only defines a single flag for now this doesn't look like much of an improvement. But we'll add another flag shortly, where it starts to make more sense.
This commit is contained in:
@@ -349,7 +349,7 @@ static int link_fd(int fd, int newdirfd, const char *newpath) {
|
||||
return RET_NERRNO(linkat(fd, "", newdirfd, newpath, AT_EMPTY_PATH));
|
||||
}
|
||||
|
||||
int link_tmpfile_at(int fd, int dir_fd, const char *path, const char *target, bool replace) {
|
||||
int link_tmpfile_at(int fd, int dir_fd, const char *path, const char *target, LinkTmpfileFlags flags) {
|
||||
_cleanup_free_ char *tmp = NULL;
|
||||
int r;
|
||||
|
||||
@@ -362,14 +362,14 @@ int link_tmpfile_at(int fd, int dir_fd, const char *path, const char *target, bo
|
||||
* is not supported on the directory, and renameat2() is used instead. */
|
||||
|
||||
if (path) {
|
||||
if (replace)
|
||||
if (FLAGS_SET(flags, LINK_TMPFILE_REPLACE))
|
||||
return RET_NERRNO(renameat(dir_fd, path, dir_fd, target));
|
||||
|
||||
return rename_noreplace(dir_fd, path, dir_fd, target);
|
||||
}
|
||||
|
||||
r = link_fd(fd, dir_fd, target);
|
||||
if (r != -EEXIST || !replace)
|
||||
if (r != -EEXIST || !FLAGS_SET(flags, LINK_TMPFILE_REPLACE))
|
||||
return r;
|
||||
|
||||
/* So the target already exists and we were asked to replace it. That sucks a bit, since the kernel's
|
||||
@@ -394,7 +394,7 @@ int link_tmpfile_at(int fd, int dir_fd, const char *path, const char *target, bo
|
||||
return 0;
|
||||
}
|
||||
|
||||
int flink_tmpfile(FILE *f, const char *path, const char *target, bool replace) {
|
||||
int flink_tmpfile(FILE *f, const char *path, const char *target, LinkTmpfileFlags flags) {
|
||||
int fd, r;
|
||||
|
||||
assert(f);
|
||||
@@ -408,7 +408,7 @@ int flink_tmpfile(FILE *f, const char *path, const char *target, bool replace) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return link_tmpfile(fd, path, target, replace);
|
||||
return link_tmpfile(fd, path, target, flags);
|
||||
}
|
||||
|
||||
int mkdtemp_malloc(const char *template, char **ret) {
|
||||
|
||||
Reference in New Issue
Block a user