From e1917654af98842cf8e0e3b170565ef3fc97c5fe Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 21 Dec 2021 20:55:43 -0600 Subject: [PATCH] Attempt to make --preserve=xattr,context work together and individually. Note: context should really be using setfscreatecon(), but that involves scanning (cacheing) xattrs before creating the output file, and what do you do about overwriting an existing file in non-mv mode? --- toys/posix/cp.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/toys/posix/cp.c b/toys/posix/cp.c index fe021cde..cd589c4c 100644 --- a/toys/posix/cp.c +++ b/toys/posix/cp.c @@ -257,7 +257,7 @@ static int cp_node(struct dirtree *try) // Copy contents of file. } else { - int fdin; + int fdin, ii; fdin = openat(tfd, try->name, O_RDONLY); if (fdin < 0) { @@ -282,8 +282,9 @@ static int cp_node(struct dirtree *try) xattr_flist(fdin, list, listlen); list[listlen-1] = 0; // I do not trust this API. for (name = list; name-list < listlen; name += strlen(name)+1) { - if (!(TT.pflags&_CP_context) && (strncmp(name, "security.", 9) == 0)) - continue; + // context copies security, xattr copies everything else + ii = strncmp(name, "security.", 9) ? _CP_xattr : _CP_context; + if (!(TT.pflags&ii)) continue; if ((len = xattr_fget(fdin, name, 0, 0))>0) { value = xmalloc(len); if (len == xattr_fget(fdin, name, value, len)) -- 2.39.2