diff options
author | Lennart Poettering <lennart@poettering.net> | 2019-11-19 15:16:46 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2019-11-19 15:44:58 +0100 |
commit | 83412d39de2a6927b4b6266c6972cf6a999dc292 (patch) | |
tree | 9cab4d9eb326101c3e5b69e9aeaca7832361c846 /src/test | |
parent | f9bbb4dcecd4285d44b66308f0892333d0d2f5ad (diff) | |
download | systemd-83412d39de2a6927b4b6266c6972cf6a999dc292.tar.gz systemd-83412d39de2a6927b4b6266c6972cf6a999dc292.tar.bz2 systemd-83412d39de2a6927b4b6266c6972cf6a999dc292.zip |
test-copy: test that xattrs are properly copied
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/test-copy.c | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/src/test/test-copy.c b/src/test/test-copy.c index ffabf95663..68905c662d 100644 --- a/src/test/test-copy.c +++ b/src/test/test-copy.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ +#include <sys/xattr.h> #include <unistd.h> #include "alloc-util.h" @@ -7,6 +8,7 @@ #include "fd-util.h" #include "fileio.h" #include "fs-util.h" +#include "hexdecoct.h" #include "log.h" #include "macro.h" #include "mkdir.h" @@ -18,6 +20,7 @@ #include "tmpfile-util.h" #include "user-util.h" #include "util.h" +#include "xattr-util.h" static void test_copy_file(void) { _cleanup_free_ char *buf = NULL; @@ -75,14 +78,16 @@ static void test_copy_file_fd(void) { } static void test_copy_tree(void) { - char original_dir[] = "/tmp/test-copy_tree/"; - char copy_dir[] = "/tmp/test-copy_tree-copy/"; + char original_dir[] = "/var/tmp/test-copy_tree/"; + char copy_dir[] = "/var/tmp/test-copy_tree-copy/"; char **files = STRV_MAKE("file", "dir1/file", "dir1/dir2/file", "dir1/dir2/dir3/dir4/dir5/file"); char **links = STRV_MAKE("link", "file", "link2", "dir1/file"); - char **p, **link; const char *unixsockp; + char **p, **link; struct stat st; + int xattr_worked = -1; /* xattr support is optional in temporary directories, hence use it if we can, + * but don't fail if we can't */ log_info("%s", __func__); @@ -90,12 +95,19 @@ static void test_copy_tree(void) { (void) rm_rf(original_dir, REMOVE_ROOT|REMOVE_PHYSICAL); STRV_FOREACH(p, files) { - _cleanup_free_ char *f; + _cleanup_free_ char *f, *c; + int k; assert_se(f = path_join(original_dir, *p)); assert_se(mkdir_parents(f, 0755) >= 0); assert_se(write_string_file(f, "file", WRITE_STRING_FILE_CREATE) == 0); + + assert_se(base64mem(*p, strlen(*p), &c) >= 0); + + k = setxattr(f, "user.testxattr", c, strlen(c), 0); + assert_se(xattr_worked < 0 || ((k >= 0) == !!xattr_worked)); + xattr_worked = k >= 0; } STRV_FOREACH_PAIR(link, p, links) { @@ -114,14 +126,25 @@ static void test_copy_tree(void) { assert_se(copy_tree(original_dir, copy_dir, UID_INVALID, GID_INVALID, COPY_REFLINK|COPY_MERGE) == 0); STRV_FOREACH(p, files) { - _cleanup_free_ char *buf, *f; + _cleanup_free_ char *buf, *f, *c = NULL; size_t sz; + int k; assert_se(f = path_join(copy_dir, *p)); assert_se(access(f, F_OK) == 0); assert_se(read_full_file(f, &buf, &sz) == 0); assert_se(streq(buf, "file\n")); + + k = getxattr_malloc(f, "user.testxattr", &c, false); + assert_se(xattr_worked < 0 || ((k >= 0) == !!xattr_worked)); + + if (k >= 0) { + _cleanup_free_ char *d = NULL; + + assert_se(base64mem(*p, strlen(*p), &d) >= 0); + assert_se(streq(d, c)); + } } STRV_FOREACH_PAIR(link, p, links) { |