diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2021-03-04 02:06:20 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2021-03-04 02:06:20 +0000 |
commit | d2c9cce93e05993fd24978f8e9104a6c387836dd (patch) | |
tree | 393087b0db7f5bfd0f88e61f5ee3cdfd77bc8949 | |
parent | c9241ea6bb74b225d0e04c7a5318fb43e5505d55 (diff) | |
parent | 30776183a02e13331a75437e5c2c031708affb59 (diff) | |
download | toybox-d2c9cce93e05993fd24978f8e9104a6c387836dd.tar.gz |
Snap for 7183400 from 30776183a02e13331a75437e5c2c031708affb59 to sc-release
Change-Id: I4e8a64ff1b8900478161f25218b95576853cdb0d
-rw-r--r-- | android/device/generated/help.h | 2 | ||||
-rw-r--r-- | android/linux/generated/help.h | 2 | ||||
-rw-r--r-- | android/mac/generated/help.h | 2 | ||||
-rw-r--r-- | kconfig/macos_miniconfig | 1 | ||||
-rw-r--r-- | lib/lib.c | 7 | ||||
-rwxr-xr-x | tests/cpio.test | 18 | ||||
-rw-r--r-- | tests/tar.test | 6 | ||||
-rw-r--r-- | toys/pending/dd.c | 18 | ||||
-rw-r--r-- | toys/posix/cpio.c | 9 | ||||
-rw-r--r-- | toys/posix/tar.c | 6 |
10 files changed, 46 insertions, 25 deletions
diff --git a/android/device/generated/help.h b/android/device/generated/help.h index c5738fdd..5467f97e 100644 --- a/android/device/generated/help.h +++ b/android/device/generated/help.h @@ -602,7 +602,7 @@ #define HELP_cut "usage: cut [-Ds] [-bcfF LIST] [-dO DELIM] [FILE...]\n\nPrint selected parts of lines from each FILE to standard output.\n\nEach selection LIST is comma separated, either numbers (counting from 1)\nor dash separated ranges (inclusive, with X- meaning to end of line and -X\nfrom start). By default selection ranges are sorted and collated, use -D\nto prevent that.\n\n-b Select bytes\n-c Select UTF-8 characters\n-C Select unicode columns\n-d Use DELIM (default is TAB for -f, run of whitespace for -F)\n-D Don't sort/collate selections or match -fF lines without delimiter\n-f Select fields (words) separated by single DELIM character\n-F Select fields separated by DELIM regex\n-O Output delimiter (default one space for -F, input delim for -f)\n-s Skip lines without delimiters" -#define HELP_cpio "usage: cpio -{o|t|i|p DEST} [-v] [--verbose] [-F FILE] [--no-preserve-owner]\n [ignored: -mdu -H newc]\n\nCopy files into and out of a \"newc\" format cpio archive.\n\n-F FILE Use archive FILE instead of stdin/stdout\n-p DEST Copy-pass mode, copy stdin file list to directory DEST\n-i Extract from archive into file system (stdin=archive)\n-o Create archive (stdin=list of files, stdout=archive)\n-t Test files (list only, stdin=archive, stdout=list of files)\n-d Create directories if needed\n-v Verbose\n--no-preserve-owner (don't set ownership during extract)" +#define HELP_cpio "usage: cpio -{o|t|i|p DEST} [-v] [--verbose] [-F FILE] [--no-preserve-owner]\n [ignored: -m -H newc]\n\nCopy files into and out of a \"newc\" format cpio archive.\n\n-F FILE Use archive FILE instead of stdin/stdout\n-p DEST Copy-pass mode, copy stdin file list to directory DEST\n-i Extract from archive into file system (stdin=archive)\n-o Create archive (stdin=list of files, stdout=archive)\n-t Test files (list only, stdin=archive, stdout=list of files)\n-d Create directories if needed\n-u unlink existing files when extracting\n-v Verbose\n--no-preserve-owner (don't set ownership during extract)" #define HELP_install "usage: install [-dDpsv] [-o USER] [-g GROUP] [-m MODE] [-t TARGET] [SOURCE...] [DEST]\n\nCopy files and set attributes.\n\n-d Act like mkdir -p\n-D Create leading directories for DEST\n-g Make copy belong to GROUP\n-m Set permissions to MODE\n-o Make copy belong to USER\n-p Preserve timestamps\n-s Call \"strip -p\"\n-t Copy files to TARGET dir (no DEST)\n-v Verbose" diff --git a/android/linux/generated/help.h b/android/linux/generated/help.h index f66cbc73..b740726f 100644 --- a/android/linux/generated/help.h +++ b/android/linux/generated/help.h @@ -608,7 +608,7 @@ #define HELP_cut "usage: cut [-Ds] [-bcfF LIST] [-dO DELIM] [FILE...]\n\nPrint selected parts of lines from each FILE to standard output.\n\nEach selection LIST is comma separated, either numbers (counting from 1)\nor dash separated ranges (inclusive, with X- meaning to end of line and -X\nfrom start). By default selection ranges are sorted and collated, use -D\nto prevent that.\n\n-b Select bytes\n-c Select UTF-8 characters\n-C Select unicode columns\n-d Use DELIM (default is TAB for -f, run of whitespace for -F)\n-D Don't sort/collate selections or match -fF lines without delimiter\n-f Select fields (words) separated by single DELIM character\n-F Select fields separated by DELIM regex\n-O Output delimiter (default one space for -F, input delim for -f)\n-s Skip lines without delimiters" -#define HELP_cpio "usage: cpio -{o|t|i|p DEST} [-v] [--verbose] [-F FILE] [--no-preserve-owner]\n [ignored: -mdu -H newc]\n\nCopy files into and out of a \"newc\" format cpio archive.\n\n-F FILE Use archive FILE instead of stdin/stdout\n-p DEST Copy-pass mode, copy stdin file list to directory DEST\n-i Extract from archive into file system (stdin=archive)\n-o Create archive (stdin=list of files, stdout=archive)\n-t Test files (list only, stdin=archive, stdout=list of files)\n-d Create directories if needed\n-v Verbose\n--no-preserve-owner (don't set ownership during extract)" +#define HELP_cpio "usage: cpio -{o|t|i|p DEST} [-v] [--verbose] [-F FILE] [--no-preserve-owner]\n [ignored: -m -H newc]\n\nCopy files into and out of a \"newc\" format cpio archive.\n\n-F FILE Use archive FILE instead of stdin/stdout\n-p DEST Copy-pass mode, copy stdin file list to directory DEST\n-i Extract from archive into file system (stdin=archive)\n-o Create archive (stdin=list of files, stdout=archive)\n-t Test files (list only, stdin=archive, stdout=list of files)\n-d Create directories if needed\n-u unlink existing files when extracting\n-v Verbose\n--no-preserve-owner (don't set ownership during extract)" #define HELP_install "usage: install [-dDpsv] [-o USER] [-g GROUP] [-m MODE] [-t TARGET] [SOURCE...] [DEST]\n\nCopy files and set attributes.\n\n-d Act like mkdir -p\n-D Create leading directories for DEST\n-g Make copy belong to GROUP\n-m Set permissions to MODE\n-o Make copy belong to USER\n-p Preserve timestamps\n-s Call \"strip -p\"\n-t Copy files to TARGET dir (no DEST)\n-v Verbose" diff --git a/android/mac/generated/help.h b/android/mac/generated/help.h index f66cbc73..b740726f 100644 --- a/android/mac/generated/help.h +++ b/android/mac/generated/help.h @@ -608,7 +608,7 @@ #define HELP_cut "usage: cut [-Ds] [-bcfF LIST] [-dO DELIM] [FILE...]\n\nPrint selected parts of lines from each FILE to standard output.\n\nEach selection LIST is comma separated, either numbers (counting from 1)\nor dash separated ranges (inclusive, with X- meaning to end of line and -X\nfrom start). By default selection ranges are sorted and collated, use -D\nto prevent that.\n\n-b Select bytes\n-c Select UTF-8 characters\n-C Select unicode columns\n-d Use DELIM (default is TAB for -f, run of whitespace for -F)\n-D Don't sort/collate selections or match -fF lines without delimiter\n-f Select fields (words) separated by single DELIM character\n-F Select fields separated by DELIM regex\n-O Output delimiter (default one space for -F, input delim for -f)\n-s Skip lines without delimiters" -#define HELP_cpio "usage: cpio -{o|t|i|p DEST} [-v] [--verbose] [-F FILE] [--no-preserve-owner]\n [ignored: -mdu -H newc]\n\nCopy files into and out of a \"newc\" format cpio archive.\n\n-F FILE Use archive FILE instead of stdin/stdout\n-p DEST Copy-pass mode, copy stdin file list to directory DEST\n-i Extract from archive into file system (stdin=archive)\n-o Create archive (stdin=list of files, stdout=archive)\n-t Test files (list only, stdin=archive, stdout=list of files)\n-d Create directories if needed\n-v Verbose\n--no-preserve-owner (don't set ownership during extract)" +#define HELP_cpio "usage: cpio -{o|t|i|p DEST} [-v] [--verbose] [-F FILE] [--no-preserve-owner]\n [ignored: -m -H newc]\n\nCopy files into and out of a \"newc\" format cpio archive.\n\n-F FILE Use archive FILE instead of stdin/stdout\n-p DEST Copy-pass mode, copy stdin file list to directory DEST\n-i Extract from archive into file system (stdin=archive)\n-o Create archive (stdin=list of files, stdout=archive)\n-t Test files (list only, stdin=archive, stdout=list of files)\n-d Create directories if needed\n-u unlink existing files when extracting\n-v Verbose\n--no-preserve-owner (don't set ownership during extract)" #define HELP_install "usage: install [-dDpsv] [-o USER] [-g GROUP] [-m MODE] [-t TARGET] [SOURCE...] [DEST]\n\nCopy files and set attributes.\n\n-d Act like mkdir -p\n-D Create leading directories for DEST\n-g Make copy belong to GROUP\n-m Set permissions to MODE\n-o Make copy belong to USER\n-p Preserve timestamps\n-s Call \"strip -p\"\n-t Copy files to TARGET dir (no DEST)\n-v Verbose" diff --git a/kconfig/macos_miniconfig b/kconfig/macos_miniconfig index 775d8d6b..26c21b15 100644 --- a/kconfig/macos_miniconfig +++ b/kconfig/macos_miniconfig @@ -14,6 +14,7 @@ CONFIG_CP=y CONFIG_CPIO=y CONFIG_CUT=y CONFIG_DATE=y +CONFIG_DF=y CONFIG_DIRNAME=y CONFIG_DU=y CONFIG_ECHO=y @@ -911,9 +911,10 @@ void exit_signal(int sig) xexit(); } -// Install the same handler on every signal that defaults to killing the -// process, calling the handler on the way out. Calling multiple times -// adds the handlers to a list, to be called in order. +// Install an atexit handler. Also install the same handler on every signal +// that defaults to killing the process, calling the handler on the way out. +// Calling multiple times adds the handlers to a list, to be called in LIFO +// order. void sigatexit(void *handler) { struct arg_list *al = 0; diff --git a/tests/cpio.test b/tests/cpio.test index 6ab3665a..7e2955a1 100755 --- a/tests/cpio.test +++ b/tests/cpio.test @@ -42,4 +42,20 @@ touch a; chmod a-rwx a; ln -s a/cant b toyonly testing "archives unreadable empty files" "cpio -o -H newc|cpio -it" "b\na\n" "" "b\na\n" chmod u+rw a; rm -f a b - +mkdir a +echo "old" >a/b +echo "a/b" | cpio -o -H newc >a.cpio +rm -rf a +testing "-i doesn't create leading directories" "cpio -i <a.cpio 2>/dev/null; [ -e a ] || echo yes" "yes\n" "" "" +rm -rf a +testing "-id creates leading directories" "cpio -id <a.cpio && cat a/b" "old\n" "" "" +rm -rf a a.cpio + +mkdir a +echo "old" >a/b +find a | cpio -o -H newc >a.cpio +testing "-i keeps existing files" "echo new >a/b && cpio -i <a.cpio 2>/dev/null; cat a/b" "new\n" "" "" +testing "-id keeps existing files" "echo new >a/b && cpio -id <a.cpio 2>/dev/null; cat a/b" "new\n" "" "" +testing "-iu replaces existing files; no error" "echo new >a/b && cpio -iu <a.cpio && cat a/b" "old\n" "" "" +testing "-idu replaces existing files; no error" "echo new >a/b && cpio -idu <a.cpio && cat a/b" "old\n" "" "" +rm -rf a a.cpio diff --git a/tests/tar.test b/tests/tar.test index dbe28d78..4b2f2120 100644 --- a/tests/tar.test +++ b/tests/tar.test @@ -274,6 +274,12 @@ testcmd 'exclude' '--exclude skip -cvf tar.tar folder && echo yes' \ 'folder/\nyes\n' '' '' rm -rf folder tar.tar +mkdir -p one/two; echo hello > one/two/three; tar czf test.tar one/two/three +rm one/two/three; mkdir one/two/three +testcmd 'replace dir with file' '-xf test.tar && cat one/two/three' \ + 'hello\n' '' '' +rm -rf one test.tar + if false then diff --git a/toys/pending/dd.c b/toys/pending/dd.c index 8f4e711e..199e5914 100644 --- a/toys/pending/dd.c +++ b/toys/pending/dd.c @@ -98,8 +98,8 @@ static void status() } } -static void dd_sigint(int sig) { - status(); +static void dd_sigint(int sig) +{ toys.exitval = sig|128; xexit(); } @@ -174,8 +174,9 @@ void dd_main() } if (bs) TT.in.sz = TT.out.sz = bs; - signal(SIGINT, dd_sigint); - signal(SIGUSR1, generic_signal); + sigatexit(status); + xsignal(SIGINT, dd_sigint); + xsignal(SIGUSR1, status); gettimeofday(&TT.start, NULL); // For bs=, in/out is done as it is. so only in.sz is enough. @@ -238,13 +239,6 @@ void dd_main() int chunk = bytes_left < TT.in.sz ? bytes_left : TT.in.sz; ssize_t n; - // Show progress and exit on SIGINT or just continue on SIGUSR1. - if (toys.signal) { - status(); - if (toys.signal==SIGINT) exit_signal(toys.signal); - toys.signal = 0; - } - TT.in.bp = TT.in.buff + TT.in.count; if (TT.conv & _DD_conv_sync) memset(TT.in.bp, 0, TT.in.sz); if (!(n = read(TT.in.fd, TT.in.bp, chunk))) break; @@ -288,6 +282,4 @@ void dd_main() close(TT.in.fd); close(TT.out.fd); if (TT.in.buff) free(TT.in.buff); - - status(); } diff --git a/toys/posix/cpio.c b/toys/posix/cpio.c index 04700ddb..b60e19b4 100644 --- a/toys/posix/cpio.c +++ b/toys/posix/cpio.c @@ -22,7 +22,7 @@ config CPIO default y help usage: cpio -{o|t|i|p DEST} [-v] [--verbose] [-F FILE] [--no-preserve-owner] - [ignored: -mdu -H newc] + [ignored: -m -H newc] Copy files into and out of a "newc" format cpio archive. @@ -32,6 +32,7 @@ config CPIO -o Create archive (stdin=list of files, stdout=archive) -t Test files (list only, stdin=archive, stdout=list of files) -d Create directories if needed + -u unlink existing files when extracting -v Verbose --no-preserve-owner (don't set ownership during extract) */ @@ -137,6 +138,8 @@ void cpio_main(void) // (This output is unaffected by --quiet.) if (FLAG(t) || FLAG(v)) puts(name); + if (FLAG(u) && !test) if (unlink(name) && errno == EISDIR) rmdir(name); + if (!test && FLAG(d) && strrchr(name, '/') && mkpath(name)) { perror_msg("mkpath '%s'", name); test++; @@ -146,7 +149,7 @@ void cpio_main(void) // properly aligned with next file. if (S_ISDIR(mode)) { - if (!test) err = mkdir(name, mode); + if (!test) err = mkdir(name, mode) && !FLAG(u); } else if (S_ISLNK(mode)) { data = strpad(afd, size, 0); if (!test) err = symlink(data, name); @@ -155,7 +158,7 @@ void cpio_main(void) if (!err && !geteuid() && !FLAG(no_preserve_owner)) err = lchown(name, uid, gid); } else if (S_ISREG(mode)) { - int fd = test ? 0 : open(name, O_CREAT|O_WRONLY|O_TRUNC|O_NOFOLLOW, mode); + int fd = test ? 0 : open(name, O_CREAT|O_WRONLY|O_EXCL|O_NOFOLLOW, mode); // If write fails, we still need to read/discard data to continue with // archive. Since doing so overwrites errno, report error now diff --git a/toys/posix/tar.c b/toys/posix/tar.c index 66547613..f31640c5 100644 --- a/toys/posix/tar.c +++ b/toys/posix/tar.c @@ -485,8 +485,10 @@ static void extract_to_disk(void) return perror_msg(":%s: can't mkdir", name); // remove old file, if exists - if (!FLAG(k) && !S_ISDIR(ala) && unlink(name) && errno!=ENOENT) - return perror_msg("can't remove: %s", name); + if (!FLAG(k) && !S_ISDIR(ala) && unlink(name)) { + if (errno==EISDIR && !rmdir(name)); + else if (errno!=ENOENT) return perror_msg("can't remove: %s", name); + } if (S_ISREG(ala)) { // hardlink? |