mirror of
https://github.com/troglobit/finit.git
synced 2026-11-23 20:11:44 +00:00
A C entry leaves a directory alone when there is something in it. In
tmpfiles.d(5) a C+ entry copies to it anyway: what the directory lacks
is added, and what it has is not overwritten.
C+ /etc/skel - - - - /usr/share/factory/etc/skel
tmpfiles reads C+ as C. Let the + through to copy_tree().
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
66 lines
2.3 KiB
Bash
Executable File
66 lines
2.3 KiB
Bash
Executable File
#!/bin/sh
|
|
# Verify the C and C+ entries of tmpfiles, copy a file or a tree
|
|
set -eu
|
|
|
|
TEST_DIR=$(dirname "$0")
|
|
|
|
DIR=/tmp/copy
|
|
SRC=/tmp/copy-src
|
|
CONF=/tmp/copy.conf
|
|
|
|
content()
|
|
{
|
|
texec sh -c "cat $1 2>/dev/null || echo none"
|
|
}
|
|
|
|
test_teardown()
|
|
{
|
|
say "Running test teardown."
|
|
run "rm -rf $DIR $SRC $CONF"
|
|
}
|
|
|
|
# shellcheck source=/dev/null
|
|
. "$TEST_DIR/lib/setup.sh"
|
|
|
|
run "mkdir -p $SRC/sub $DIR/empty $DIR/full/sub $DIR/merge/sub"
|
|
run "echo new > $SRC/file; echo new > $SRC/sub/file; echo new > $SRC/sub/other; ln -s file $SRC/link; chmod 640 $SRC/file"
|
|
run "echo old > $DIR/full/file; echo old > $DIR/merge/sub/file; echo old > $DIR/one-old"
|
|
run "mkdir $SRC/away $DIR/out; echo new > $SRC/away/file; ln -s ../out $DIR/merge/away"
|
|
|
|
run "cat > $CONF" <<CONF
|
|
C $DIR/tree - - - - $SRC
|
|
C $DIR/empty - - - - $SRC
|
|
C $DIR/full - - - - $SRC
|
|
C+ $DIR/merge - - - - $SRC
|
|
C $DIR/one 0600 - - - $SRC/file
|
|
C $DIR/one-old - - - - $SRC/file
|
|
C $DIR/missing - - - - /no/such/path
|
|
CONF
|
|
run "/libexec/finit/tmpfiles --create $CONF"
|
|
|
|
say 'C copies a tree, links are not followed'
|
|
assert "File" "$(content $DIR/tree/file)" = "new"
|
|
assert "File in subdir" "$(content $DIR/tree/sub/file)" = "new"
|
|
assert "Mode is kept" "$(texec stat -c %a $DIR/tree/file)" = "640"
|
|
assert "Link is a link" "$(texec readlink $DIR/tree/link)" = "file"
|
|
|
|
sep
|
|
say 'C fills a directory that is empty, and leaves one that is not'
|
|
assert "Empty directory" "$(content $DIR/empty/sub/file)" = "new"
|
|
assert "Existing file" "$(content $DIR/full/file)" = "old"
|
|
assert "Nothing added" "$(content $DIR/full/sub/file)" = "none"
|
|
|
|
sep
|
|
say 'C+ adds what is missing and overwrites nothing'
|
|
assert "Existing file" "$(content $DIR/merge/sub/file)" = "old"
|
|
assert "Missing file" "$(content $DIR/merge/sub/other)" = "new"
|
|
assert "Missing at top" "$(content $DIR/merge/file)" = "new"
|
|
assert "Not through a link" "$(content $DIR/out/file)" = "none"
|
|
|
|
sep
|
|
say 'C copies a file, unless it is there'
|
|
assert "New file" "$(content $DIR/one)" = "new"
|
|
assert "Mode of entry" "$(texec stat -c %a $DIR/one)" = "600"
|
|
assert "Existing file" "$(content $DIR/one-old)" = "old"
|
|
assert "No source" "$(texec sh -c "ls $DIR | grep -c missing")" = "0"
|