]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
string_utils: move to lxc-copy() sources
authorChristian Brauner <christian.brauner@ubuntu.com>
Thu, 1 Apr 2021 07:16:14 +0000 (09:16 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Thu, 1 Apr 2021 08:27:40 +0000 (10:27 +0200)
It's the only place where it is still used.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/string_utils.c
src/lxc/string_utils.h
src/lxc/tools/lxc_copy.c

index 18c64c11ef0642547a41480337baad7edde2600d..e5321d826d55d5a241f19cc20278cd3406156071 100644 (file)
@@ -192,41 +192,6 @@ char *lxc_string_join(const char *sep, const char **parts, bool use_as_prefix)
        return result;
 }
 
-char **lxc_normalize_path(const char *path)
-{
-       char **components;
-       size_t components_len = 0;
-       size_t pos = 0;
-
-       components = lxc_string_split(path, '/');
-       if (!components)
-               return NULL;
-
-       /* resolve '.' and '..' */
-       for (pos = 0; pos < components_len;) {
-               if (strequal(components[pos], ".") ||
-                   (strequal(components[pos], "..") && pos == 0)) {
-                       /* eat this element */
-                       free(components[pos]);
-                       memmove(&components[pos], &components[pos + 1],
-                               sizeof(char *) * (components_len - pos));
-                       components_len--;
-               } else if (strequal(components[pos], "..")) {
-                       /* eat this and the previous element */
-                       free(components[pos - 1]);
-                       free(components[pos]);
-                       memmove(&components[pos - 1], &components[pos + 1],
-                               sizeof(char *) * (components_len - pos));
-                       components_len -= 2;
-                       pos--;
-               } else {
-                       pos++;
-               }
-       }
-
-       return components;
-}
-
 /* taken from systemd */
 char *path_simplify(const char *path)
 {
index 1bea9a01cdaed3e6dbcc53f91e7dd11331b48c1e..fefb1f496ea4abcc02fb005cddb6002281177cab 100644 (file)
@@ -30,21 +30,7 @@ __hidden extern char *lxc_string_replace(const char *needle, const char *replace
                                         const char *haystack);
 __hidden extern bool lxc_string_in_array(const char *needle, const char **haystack);
 __hidden extern char *lxc_string_join(const char *sep, const char **parts, bool use_as_prefix);
-/*
- * Normalize and split path: Leading and trailing / are removed, multiple
- * / are compactified, .. and . are resolved (.. on the top level is considered
- * identical to .).
- * Examples:
- *     /            ->   { NULL }
- *     foo/../bar   ->   { bar, NULL }
- *     ../../       ->   { NULL }
- *     ./bar/baz/.. ->   { bar, NULL }
- *     foo//bar     ->   { foo, bar, NULL }
- */
-__hidden extern char **lxc_normalize_path(const char *path);
 
-/* remove multiple slashes from the path, e.g. ///foo//bar -> /foo/bar */
-__hidden extern char *lxc_deslashify(const char *path);
 __hidden extern char *lxc_append_paths(const char *first, const char *second);
 
 /*
index c406929272764fb00e8541b7d130be482f5a597e..a786a300c5bc607c7fc4c0cfb277bbcc93545c2a 100644 (file)
@@ -289,6 +289,41 @@ static int mk_rand_ovl_dirs(struct mnts *mnts, unsigned int num, struct lxc_argu
        return 0;
 }
 
+static char **lxc_normalize_path(const char *path)
+{
+       char **components;
+       size_t components_len = 0;
+       size_t pos = 0;
+
+       components = lxc_string_split(path, '/');
+       if (!components)
+               return NULL;
+
+       /* resolve '.' and '..' */
+       for (pos = 0; pos < components_len;) {
+               if (strequal(components[pos], ".") ||
+                   (strequal(components[pos], "..") && pos == 0)) {
+                       /* eat this element */
+                       free(components[pos]);
+                       memmove(&components[pos], &components[pos + 1],
+                               sizeof(char *) * (components_len - pos));
+                       components_len--;
+               } else if (strequal(components[pos], "..")) {
+                       /* eat this and the previous element */
+                       free(components[pos - 1]);
+                       free(components[pos]);
+                       memmove(&components[pos - 1], &components[pos + 1],
+                               sizeof(char *) * (components_len - pos));
+                       components_len -= 2;
+                       pos--;
+               } else {
+                       pos++;
+               }
+       }
+
+       return components;
+}
+
 static char *construct_path(char *path, bool as_prefix)
 {
        char **components = NULL;