1#!/usr/bin/env bash
2# SPDX-License-Identifier: LGPL-2.1-or-later
3set -e
4set -x
5
6rm -fr /tmp/x
7mkdir  /tmp/x
8
9#
10# 'x'
11#
12mkdir -p /tmp/x/{1,2}
13touch /tmp/x/1/{x1,x2} /tmp/x/2/{y1,y2} /tmp/x/{z1,z2}
14
15systemd-tmpfiles --clean - <<EOF
16d /tmp/x - - - 0
17x /tmp/x/1
18EOF
19
20find /tmp/x | sort
21test -d /tmp/x/1
22test -f /tmp/x/1/x1
23test -f /tmp/x/1/x2
24test ! -d /tmp/x/2
25test ! -f /tmp/x/2/x1
26test ! -f /tmp/x/2/x2
27test ! -f /tmp/x/z1
28test ! -f /tmp/x/z2
29
30#
31# 'X'
32#
33
34mkdir -p /tmp/x/{1,2}
35touch /tmp/x/1/{x1,x2} /tmp/x/2/{y1,y2} /tmp/x/{z1,z2}
36
37systemd-tmpfiles --clean - <<EOF
38d /tmp/x - - - 0
39X /tmp/x/1
40EOF
41
42find /tmp/x | sort
43test -d /tmp/x/1
44test ! -f /tmp/x/1/x1
45test ! -f /tmp/x/1/x2
46test ! -d /tmp/x/2
47test ! -f /tmp/x/2/x1
48test ! -f /tmp/x/2/x2
49test ! -f /tmp/x/z1
50test ! -f /tmp/x/z2
51
52#
53# 'x' with glob
54#
55
56mkdir -p /tmp/x/{1,2}
57touch /tmp/x/1/{x1,x2} /tmp/x/2/{y1,y2} /tmp/x/{z1,z2}
58
59systemd-tmpfiles --clean - <<EOF
60d /tmp/x - - - 0
61x /tmp/x/[1345]
62x /tmp/x/z*
63EOF
64
65find /tmp/x | sort
66test -d /tmp/x/1
67test -f /tmp/x/1/x1
68test -f /tmp/x/1/x2
69test ! -d /tmp/x/2
70test ! -f /tmp/x/2/x1
71test ! -f /tmp/x/2/x2
72test -f /tmp/x/z1
73test -f /tmp/x/z2
74
75#
76# 'X' with glob
77#
78
79mkdir -p /tmp/x/{1,2}
80touch /tmp/x/1/{x1,x2} /tmp/x/2/{y1,y2} /tmp/x/{z1,z2}
81
82systemd-tmpfiles --clean - <<EOF
83d /tmp/x - - - 0
84X /tmp/x/[1345]
85X /tmp/x/?[12]
86EOF
87
88find /tmp/x | sort
89test -d /tmp/x/1
90test ! -f /tmp/x/1/x1
91test ! -f /tmp/x/1/x2
92test ! -d /tmp/x/2
93test ! -f /tmp/x/2/x1
94test ! -f /tmp/x/2/x2
95test -f /tmp/x/z1
96test -f /tmp/x/z2
97
98#
99# 'x' with 'r'
100#
101
102mkdir -p /tmp/x/{1,2}/a
103touch /tmp/x/1/a/{x1,x2} /tmp/x/2/a/{y1,y2}
104
105systemd-tmpfiles --clean - <<EOF
106# x/X is not supposed to influence r
107x /tmp/x/1/a
108X /tmp/x/2/a
109r /tmp/x/1
110r /tmp/x/2
111EOF
112
113find /tmp/x | sort
114test -d /tmp/x/1
115test -d /tmp/x/1/a
116test -f /tmp/x/1/a/x1
117test -f /tmp/x/1/a/x2
118test -f /tmp/x/2/a/y1
119test -f /tmp/x/2/a/y2
120
121#
122# 'x' with 'R'
123#
124
125mkdir -p /tmp/x/{1,2}/a
126touch /tmp/x/1/a/{x1,x2} /tmp/x/2/a/{y1,y2}
127
128systemd-tmpfiles --remove - <<EOF
129# X is not supposed to influence R
130X /tmp/x/1/a
131X /tmp/x/2/a
132R /tmp/x/1
133EOF
134
135find /tmp/x | sort
136test ! -d /tmp/x/1
137test ! -d /tmp/x/1/a
138test ! -f /tmp/x/1/a/x1
139test ! -f /tmp/x/1/a/x2
140test -f /tmp/x/2/a/y1
141test -f /tmp/x/2/a/y2
142