nspkg / tests / file_conflict_mount_probe.v
50 lines · 47 sloc · 1.8 KB · c01b0795d1db56c7bce2539b2c46b110637fdc1a
Raw
1module main
2
3import nspkg.engine
4import nspkg.tests.archivefixtures
5import nspkg.tests.signaturefixtures
6import os
7
8fn main() {
9 run() or {
10 eprintln(err)
11 exit(1)
12 }
13}
14
15fn run() ! {
16 if os.args.len != 3 || os.readlink('/proc/self/ns/mnt')! == os.args[2] {
17 return error('requires a private mount namespace')
18 }
19 signaturefixtures.command('mount', ['--make-rprivate', '/'])!
20 base := os.args[1]
21 root := os.join_path(base, 'root')
22 parent := os.join_path(root, 'f')
23 child := os.join_path(parent, 'self')
24 entry := os.join_path(base, 'db', 'local', 'app-1-1')
25 os.mkdir_all(child)!
26 os.mkdir_all(entry)!
27 os.write_file(os.join_path(base, 'db', 'local', 'ALPM_DB_VERSION'), '9\n')!
28 os.write_file(os.join_path(entry, 'desc'), '%DESC%\nInstalled\n\n')!
29 os.write_file(os.join_path(entry, 'files'), '%FILES%\nf/\nf/self/\n\n')!
30 archive := os.join_path(base, 'app.pkg.tar')
31 archivefixtures.write(archive, [
32 archivefixtures.Entry{ name: '.PKGINFO', text: 'pkgname = app\npkgver = 2-1\n' },
33 archivefixtures.Entry{ name: 'f', text: 'replacement' },
34 ], false)!
35 signaturefixtures.command('mount', ['--bind', parent, child])!
36 defer { signaturefixtures.command('umount', [child]) or { eprintln(err) } }
37 mut handle := engine.initialize(root, os.join_path(base, 'db'))!
38 defer { handle.release() or { eprintln(err) } }
39 handle.start_transaction(.no_deps | .no_hooks | .no_scriptlet | .nolock)!
40 defer { handle.release_transaction() or { eprintln(err) } }
41 handle.add_package(handle.load_package(archive, true, 0)!)!
42 assert handle.prepare_transaction()!.success
43 result := handle.check_file_conflicts()!
44 assert !result.success
45 assert result.conflicts.len == 1
46 assert result.conflicts[0].kind == .filesystem
47 assert os.is_dir(parent)
48 assert os.is_dir(entry)
49 println('native file preflight rejects cyclic bind mounts without mutation')
50}
51