Merge pull request #25338 from DaanDeMeyer/at-fixes

Followups for #24813
This commit is contained in:
Yu Watanabe
2022-11-13 22:59:40 +09:00
committed by GitHub
7 changed files with 8 additions and 50 deletions
-2
View File
@@ -460,9 +460,7 @@ int chase_symlinks(
SYNTHETIC_ERRNO(ECHRNG),
"Specified path '%s' is outside of specified root directory '%s', refusing to resolve.",
absolute, root);
}
if (root) {
fd = open(root, O_CLOEXEC|O_DIRECTORY|O_PATH);
if (fd < 0)
return -errno;
+2
View File
@@ -197,6 +197,8 @@ int readlink_and_make_absolute(const char *p, char **r) {
int chmod_and_chown_at(int dir_fd, const char *path, mode_t mode, uid_t uid, gid_t gid) {
_cleanup_close_ int fd = -1;
assert(dir_fd >= 0 || dir_fd == AT_FDCWD);
if (path) {
/* Let's acquire an O_PATH fd, as precaution to change mode/owner on the same file */
fd = openat(dir_fd, path, O_PATH|O_CLOEXEC|O_NOFOLLOW);
-27
View File
@@ -221,33 +221,6 @@ int path_make_relative_parent(const char *from_child, const char *to, char **ret
return path_make_relative(from, to, ret);
}
int path_make_relative_cwd(const char *p, char **ret) {
char *c;
int r;
assert(p);
assert(ret);
if (path_is_absolute(p)) {
_cleanup_free_ char *cwd = NULL;
r = safe_getcwd(&cwd);
if (r < 0)
return r;
r = path_make_relative(cwd, p, &c);
if (r < 0)
return r;
} else {
c = strdup(p);
if (!c)
return -ENOMEM;
}
*ret = TAKE_PTR(c);
return 0;
}
char* path_startswith_strv(const char *p, char **set) {
STRV_FOREACH(s, set) {
char *t;
-1
View File
@@ -62,7 +62,6 @@ int safe_getcwd(char **ret);
int path_make_absolute_cwd(const char *p, char **ret);
int path_make_relative(const char *from, const char *to, char **ret);
int path_make_relative_parent(const char *from_child, const char *to, char **ret);
int path_make_relative_cwd(const char *from, char **ret);
char *path_startswith_full(const char *path, const char *prefix, bool accept_dot_dot) _pure_;
static inline char* path_startswith(const char *path, const char *prefix) {
return path_startswith_full(path, prefix, true);
+2
View File
@@ -25,6 +25,8 @@ int fopen_temporary_at(int dir_fd, const char *path, FILE **ret_file, char **ret
_cleanup_close_ int fd = -1;
int r;
assert(dir_fd >= 0 || dir_fd == AT_FDCWD);
if (path) {
r = tempfn_random(path, NULL, &t);
if (r < 0)
-17
View File
@@ -5,7 +5,6 @@
#include "alloc-util.h"
#include "errno-util.h"
#include "fd-util.h"
typedef enum RemoveFlags {
REMOVE_ONLY_DIRECTORIES = 1 << 0, /* Only remove empty directories, no files */
@@ -52,19 +51,3 @@ static inline char *rm_rf_subvolume_and_free(char *p) {
return mfree(p);
}
DEFINE_TRIVIAL_CLEANUP_FUNC(char*, rm_rf_subvolume_and_free);
static inline int rm_rf_physical_and_close(int fd) {
_cleanup_free_ char *p = NULL;
if (fd < 0)
return -1;
if (fd_get_path(fd, &p) < 0)
return safe_close(fd);
safe_close(fd);
(void) rm_rf(p, REMOVE_ROOT|REMOVE_PHYSICAL|REMOVE_MISSING_OK|REMOVE_CHMOD);
return -1;
}
DEFINE_TRIVIAL_CLEANUP_FUNC(int, rm_rf_physical_and_close);
+4 -3
View File
@@ -77,11 +77,12 @@ TEST(copy_tree_replace_file) {
}
TEST(copy_tree_replace_dirs) {
_cleanup_(rm_rf_physical_and_closep) int src = -1, dst = -1;
_cleanup_(rm_rf_physical_and_freep) char *srcp = NULL, *dstp = NULL;
_cleanup_close_ int src = -1, dst = -1;
/* Create the random source/destination directories */
assert_se((src = mkdtemp_open(NULL, 0, NULL)) >= 0);
assert_se((dst = mkdtemp_open(NULL, 0, NULL)) >= 0);
assert_se((src = mkdtemp_open(NULL, 0, &srcp)) >= 0);
assert_se((dst = mkdtemp_open(NULL, 0, &dstp)) >= 0);
/* Populate some data to differentiate the files. */
assert_se(write_string_file_at(src, "foo", "src file 1", WRITE_STRING_FILE_CREATE) >= 0);