File: copy-file

package info (click to toggle)
initramfs-tools 0.150
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 672 kB
  • sloc: sh: 2,300; ansic: 457; python: 189; makefile: 24
file content (97 lines) | stat: -rwxr-xr-x 2,552 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/sh
set -e

SUPPORTED_FLAVOURS='alpha-smp amd64 arm64 armmp parisc loong64 m68k powerpc64 powerpc64le riscv64 s390x sparc64-smp generic'
. debian/tests/test-common

SOURCEDIR=/usr/lib/initramfs-test-copy-file

mkdir -p "${SOURCEDIR}/dir1"
printf "1" >"${SOURCEDIR}/dir1/file1"
ln -s dir1 "${SOURCEDIR}/dir2"
printf "22" >"${SOURCEDIR}/file2"
printf "333" >"${SOURCEDIR}/file3"

cat >>"${CONFDIR}/initramfs.conf" <<EOF
MODULES=list
BUSYBOX=n
EOF

cat >"${CONFDIR}/hooks/initramfs-test-copy-file" <<EOF
#!/bin/sh
set -e

test "\$1" = prereqs && exit

. /usr/share/initramfs-tools/hook-functions

set -x

# Source named via directory symlink should be symlinked (#1076539)
copy_file test "${SOURCEDIR}/dir1/file1"
copy_file test "${SOURCEDIR}/dir2/file1"

# Usr-merged target must be recognised with or without leading slash
# (#1079276)
copy_file test "${SOURCEDIR#/usr}/file3" "${SOURCEDIR#/usr/}/file3"

# Target that exists as directory must be treated as directory
mkdir "\${DESTDIR}/${SOURCEDIR}/dir3"
copy_file test "${SOURCEDIR}/file2" "${SOURCEDIR}/dir3"

# Target with trailing slash must be treated as directory (#1082647)
copy_file test "${SOURCEDIR}/file2" "${SOURCEDIR}/dir4/"

# Check combination of #1079276 and #1082647 cases
copy_file test "${SOURCEDIR#/usr}/file3" "${SOURCEDIR#/usr/}/dir5/"
EOF
chmod +x "${CONFDIR}/hooks/initramfs-test-copy-file"

build_initramfs
lsinitramfs -l "${INITRAMFS}" >"${AUTOPKGTEST_TMP}/listing"

rc=0

check_file() {
	local ftype="$1"
	local name="$2"
	local extra="$3"
	local size_re='[0-9]*'
	local tail_re=''

	case "$ftype" in
	-)
		# Regular file: extra is size
		size_re="${extra}"
		;;
	l)
		# Symbolic link: extra is link text
		size_re="${#extra}"
		tail_re=" -> $(printf %s "$extra" | sed 's/\./\\./g')"
		;;
	esac

	if ! grep -q "^${ftype}......... *[0-9]* root *root *${size_re} ............ ${name#/}${tail_re}$" "${AUTOPKGTEST_TMP}/listing"; then
		echo >&2 "E: $name did not get copied correctly"
		rc=1
	fi
}

# Check that files, directories, and symlinks were created as expected
check_file d ${SOURCEDIR}/dir1       -
check_file - ${SOURCEDIR}/dir1/file1 1
check_file d ${SOURCEDIR}/dir2       -
check_file l ${SOURCEDIR}/dir2/file1 ../dir1/file1
check_file - ${SOURCEDIR}/file3      3
check_file d ${SOURCEDIR}/dir3       -
check_file - ${SOURCEDIR}/dir3/file2 2
check_file d ${SOURCEDIR}/dir4       -
check_file - ${SOURCEDIR}/dir4/file2 2
check_file - ${SOURCEDIR}/dir5/file3 3

if [ $rc -ne 0 ]; then
	echo "I: Initramfs contents:"
	cat "$AUTOPKGTEST_TMP/listing"
fi

exit $rc