Mercurial > hg > toybox
view scripts/test/chgrp.test @ 1087:b73a61542297 draft
I've finally gotten 'cpio' into a shape where it could be useable.
This version can archive and extract directories, sockets, FIFOs, devices,
symlinks, and regular files.
Supported options are -iot, -H FMT (which is a dummy right now).
It only writes newc, and could read newc or newcrc.
This does NOT implement -d, which essentially is equivalent to
mkdir -p $(dirname $FILE)
for every file that needs it.
Hard links are not supported, though it would be easy to add them given
a hash table or something like that.
I also have not implemented the "<n> blocks" output on stderr.
If desired, I can add it pretty simply.
There is one assumption this makes: that the mode of a file, as mode_t,
is bitwise equivalent to the mode as defined for the cpio format.
This is true of Linux, but is not mandated by POSIX.
If it is compiled for a system where that is false, the archives will
not be portable.
author | Isaac Dunham <ibid.ag@gmail.com> |
---|---|
date | Mon, 14 Oct 2013 11:15:22 -0500 |
parents | 3d7526f6115b |
children |
line wrap: on
line source
#!/bin/bash [ -f testing.sh ] && . testing.sh if [ "$(id -u)" -ne 0 ] then echo "SKIPPED: chgrp (not root)" continue 2>/dev/null exit fi # We chgrp between "root" and the last group in /etc/group. GRP="$(sed -n '$s/:.*//p' /etc/group)" # Set up a little testing hierarchy rm -rf testdir && mkdir -p testdir/dir/dir/dir testdir/dir2 && touch testdir/dir/file && ln -s ../dir/dir testdir/dir2/dir && ln -s ../dir/file testdir/dir2/file || exit 1 # Wrapper to reset groups and return results IN="cd testdir && chgrp -R $GRP dir dir2 &&" OUT="&& cd .. && echo \$(ls -lR testdir | awk '{print \$4}')" # The groups returned by $OUT are, in order: # dir dir2 dir/dir dir/file dir/dir/dir dir2/dir dir2/file #testing "name" "command" "result" "infile" "stdin" # Basic smoketest testing "chgrp dir" "$IN chgrp root dir $OUT" \ "root $GRP $GRP $GRP $GRP $GRP $GRP\n" "" "" testing "chgrp file" "$IN chgrp root dir/file $OUT" \ "$GRP $GRP $GRP root $GRP $GRP $GRP\n" "" "" testing "chgrp dir and file" "$IN chgrp root dir dir/file $OUT" \ "root $GRP $GRP root $GRP $GRP $GRP\n" "" "" # symlinks (affect target, not symlink) testing "chgrp symlink->file" "$IN chgrp root dir2/file $OUT" \ "$GRP $GRP $GRP root $GRP $GRP $GRP\n" "" "" testing "chgrp symlink->dir" "$IN chgrp root dir2/dir $OUT" \ "$GRP $GRP root $GRP $GRP $GRP $GRP\n" "" "" testing "chgrp -h symlink->dir" "$IN chgrp -h root dir2/dir $OUT" \ "$GRP $GRP $GRP $GRP $GRP root $GRP\n" "" "" # What does -h do (affect symlink, not target) testing "chgrp -h symlink->file" "$IN chgrp -h root dir2/file $OUT" \ "$GRP $GRP $GRP $GRP $GRP $GRP root\n" "" "" testing "chgrp -h symlink->dir" "$IN chgrp -h root dir2/dir $OUT" \ "$GRP $GRP $GRP $GRP $GRP root $GRP\n" "" "" # chgrp -R (note, -h is implied by -R) testing "chgrp -R dir" "$IN chgrp -R root dir $OUT" \ "root $GRP root root root $GRP $GRP\n" "" "" testing "chgrp -R dir2" "$IN chgrp -R root dir2 $OUT" \ "$GRP root $GRP $GRP $GRP root root\n" "" "" testing "chgrp -R symlink->dir" "$IN chgrp -R root dir2/dir $OUT" \ "$GRP $GRP $GRP $GRP $GRP root $GRP\n" "" "" testing "chgrp -R symlink->file" "$IN chgrp -R root dir2/file $OUT" \ "$GRP $GRP $GRP $GRP $GRP $GRP root\n" "" "" # chgrp -RP (same as -R by itself) testing "chgrp -RP dir2" "$IN chgrp -RP root dir2 $OUT" \ "$GRP root $GRP $GRP $GRP root root\n" "" "" testing "chgrp -RP symlink->dir" "$IN chgrp -RP root dir2/dir $OUT" \ "$GRP $GRP $GRP $GRP $GRP root $GRP\n" "" "" testing "chgrp -RP symlink->file" "$IN chgrp -RP root dir2/file $OUT" \ "$GRP $GRP $GRP $GRP $GRP $GRP root\n" "" "" # chgrp -RH (change target but only recurse through symlink->dir on cmdline) testing "chgrp -RH dir2" "$IN chgrp -RH root dir2 $OUT" \ "$GRP root root root $GRP $GRP $GRP\n" "" "" testing "chgrp -RH symlink->dir" "$IN chgrp -RH root dir2/dir $OUT" \ "$GRP $GRP root $GRP root $GRP $GRP\n" "" "" testing "chgrp -RH symlink->file" "$IN chgrp -RH root dir2/file $OUT" \ "$GRP $GRP $GRP root $GRP $GRP $GRP\n" "" "" # chgrp -RL (change target and always recurse through symlink->dir) testing "chgrp -RL dir2" "$IN chgrp -RL root dir2 $OUT" \ "$GRP root root root root $GRP $GRP\n" "" "" testing "chgrp -RL symlink->dir" "$IN chgrp -RL root dir2/dir $OUT" \ "$GRP $GRP root $GRP root $GRP $GRP\n" "" "" testing "chgrp -RL symlink->file" "$IN chgrp -RL root dir2/file $OUT" \ "$GRP $GRP $GRP root $GRP $GRP $GRP\n" "" "" # -HLP are NOPs without -R testing "chgrp -H without -R" "$IN chgrp -H root dir2/dir $OUT" \ "$GRP $GRP root $GRP $GRP $GRP $GRP\n" "" "" testing "chgrp -L without -R" "$IN chgrp -L root dir2/dir $OUT" \ "$GRP $GRP root $GRP $GRP $GRP $GRP\n" "" "" testing "chgrp -P without -R" "$IN chgrp -P root dir2/dir $OUT" \ "$GRP $GRP root $GRP $GRP $GRP $GRP\n" "" "" rm -rf testdir