Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
5fba37a1
Unverified
Commit
5fba37a1
authored
Apr 01, 2021
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
string_utils: move to lxc-copy() sources
It's the only place where it is still used. Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
68dd0ea5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
49 deletions
+35
-49
string_utils.c
src/lxc/string_utils.c
+0
-35
string_utils.h
src/lxc/string_utils.h
+0
-14
lxc_copy.c
src/lxc/tools/lxc_copy.c
+35
-0
No files found.
src/lxc/string_utils.c
View file @
5fba37a1
...
...
@@ -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
)
{
...
...
src/lxc/string_utils.h
View file @
5fba37a1
...
...
@@ -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
);
/*
...
...
src/lxc/tools/lxc_copy.c
View file @
5fba37a1
...
...
@@ -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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment