summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/chase.c31
-rw-r--r--src/basic/chase.h2
-rw-r--r--src/basic/os-util.c4
-rw-r--r--src/basic/path-util.c28
-rw-r--r--src/basic/path-util.h1
5 files changed, 35 insertions, 31 deletions
diff --git a/src/basic/chase.c b/src/basic/chase.c
index 96b59e7845..373252b645 100644
--- a/src/basic/chase.c
+++ b/src/basic/chase.c
@@ -583,6 +583,37 @@ int chase(const char *path, const char *root, ChaseFlags flags, char **ret_path,
return r;
}
+int chaseat_prefix_root(const char *path, const char *root, char **ret) {
+ char *q;
+ int r;
+
+ assert(path);
+ assert(ret);
+
+ /* This is mostly for prefixing the result of chaseat(). */
+
+ if (!path_is_absolute(path)) {
+ _cleanup_free_ char *root_abs = NULL;
+
+ /* If the dir_fd points to the root directory, chaseat() always returns an absolute path. */
+ assert(!empty_or_root(root));
+
+ r = path_make_absolute_cwd(root, &root_abs);
+ if (r < 0)
+ return r;
+
+ root = path_simplify(root_abs);
+
+ q = path_join(root, path + (path[0] == '.' && IN_SET(path[1], '/', '\0')));
+ } else
+ q = strdup(path);
+ if (!q)
+ return -ENOMEM;
+
+ *ret = q;
+ return 0;
+}
+
int chase_and_open(const char *path, const char *root, ChaseFlags chase_flags, int open_flags, char **ret_path) {
_cleanup_close_ int path_fd = -EBADF;
_cleanup_free_ char *p = NULL, *fname = NULL;
diff --git a/src/basic/chase.h b/src/basic/chase.h
index 40121f7d70..f37e836822 100644
--- a/src/basic/chase.h
+++ b/src/basic/chase.h
@@ -42,6 +42,8 @@ bool unsafe_transition(const struct stat *a, const struct stat *b);
int chase(const char *path_with_prefix, const char *root, ChaseFlags chase_flags, char **ret_path, int *ret_fd);
+int chaseat_prefix_root(const char *path, const char *root, char **ret);
+
int chase_and_open(const char *path, const char *root, ChaseFlags chase_flags, int open_flags, char **ret_path);
int chase_and_opendir(const char *path, const char *root, ChaseFlags chase_flags, char **ret_path, DIR **ret_dir);
int chase_and_stat(const char *path, const char *root, ChaseFlags chase_flags, char **ret_path, struct stat *ret_stat);
diff --git a/src/basic/os-util.c b/src/basic/os-util.c
index dd8faf2376..5d06e20871 100644
--- a/src/basic/os-util.c
+++ b/src/basic/os-util.c
@@ -155,7 +155,7 @@ int open_os_release(const char *root, char **ret_path, int *ret_fd) {
return r;
if (ret_path) {
- r = path_prefix_root_cwd(p, root, ret_path);
+ r = chaseat_prefix_root(p, root, ret_path);
if (r < 0)
return r;
}
@@ -292,7 +292,7 @@ int open_extension_release(
return r;
if (ret_path) {
- r = path_prefix_root_cwd(p, root, ret_path);
+ r = chaseat_prefix_root(p, root, ret_path);
if (r < 0)
return r;
}
diff --git a/src/basic/path-util.c b/src/basic/path-util.c
index fa2e26789f..0b0f0da760 100644
--- a/src/basic/path-util.c
+++ b/src/basic/path-util.c
@@ -100,34 +100,6 @@ int path_make_absolute_cwd(const char *p, char **ret) {
return 0;
}
-int path_prefix_root_cwd(const char *p, const char *root, char **ret) {
- _cleanup_free_ char *root_abs = NULL;
- char *c;
- int r;
-
- assert(p);
- assert(ret);
-
- /* Unlike path_make_absolute(), this always prefixes root path if specified.
- * The root path is always simplified, but the provided path will not.
- * This is useful for prefixing the result of chaseat(). */
-
- if (empty_or_root(root))
- return path_make_absolute_cwd(p, ret);
-
- r = path_make_absolute_cwd(root, &root_abs);
- if (r < 0)
- return r;
-
- path_simplify(root_abs);
- c = path_join(root_abs, p);
- if (!c)
- return -ENOMEM;
-
- *ret = c;
- return 0;
-}
-
int path_make_relative(const char *from, const char *to, char **ret) {
_cleanup_free_ char *result = NULL;
unsigned n_parents;
diff --git a/src/basic/path-util.h b/src/basic/path-util.h
index a0af9de674..7843599816 100644
--- a/src/basic/path-util.h
+++ b/src/basic/path-util.h
@@ -60,7 +60,6 @@ int path_split_and_make_absolute(const char *p, char ***ret);
char* path_make_absolute(const char *p, const char *prefix);
int safe_getcwd(char **ret);
int path_make_absolute_cwd(const char *p, char **ret);
-int path_prefix_root_cwd(const char *p, const char *root, 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);
char *path_startswith_full(const char *path, const char *prefix, bool accept_dot_dot) _pure_;