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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
|
import dataclasses
import textwrap
from typing import Tuple, List, Optional, Union, Sequence
import pytest
from debputy.filesystem_scan import PathDef, build_virtual_fs
from debputy.highlevel_manifest_parser import (
YAMLManifestParser,
)
from debputy.intermediate_manifest import PathType, IntermediateManifest, TarMember
from debputy.plugin.api import virtual_path_def
from debputy.plugin.api.test_api import build_virtual_file_system
from debputy.transformation_rules import TransformationRuntimeError
@pytest.fixture()
def manifest_parser_pkg_foo(
amd64_dpkg_architecture_variables,
dpkg_arch_query,
source_package,
package_single_foo_arch_all_cxt_amd64,
amd64_substitution,
no_profiles_or_build_options,
debputy_plugin_feature_set,
) -> YAMLManifestParser:
# We need an empty directory to avoid triggering packager provided files.
debian_dir = build_virtual_file_system([])
return YAMLManifestParser(
"debian/test-debputy.manifest",
source_package,
package_single_foo_arch_all_cxt_amd64,
amd64_substitution,
amd64_dpkg_architecture_variables,
dpkg_arch_query,
no_profiles_or_build_options,
debputy_plugin_feature_set,
"full",
debian_dir=debian_dir,
)
@dataclasses.dataclass(slots=True, kw_only=True)
class Expected:
mtime: Optional[float]
mode: Optional[int] = None
link_target: Optional[str] = None
owner: str = "root"
group: str = "root"
has_fs_path: bool = True
def _show_name_on_error(_: str) -> bool:
return False
def _has_fs_path(tm: TarMember) -> bool:
return tm.fs_path is not None
def verify_paths(
intermediate_manifest: IntermediateManifest,
expected_results: Sequence[Tuple[Union[str, PathDef], Expected]],
) -> None:
result = {tm.member_path: tm for tm in intermediate_manifest}
expected_table = {
f"./{p}" if isinstance(p, str) else f"./{p.path_name}": e
for p, e in expected_results
}
for path_name, expected in expected_table.items():
tm = result[path_name]
if tm.path_type == PathType.SYMLINK:
assert tm.link_target == expected.link_target or _show_name_on_error(
path_name
)
else:
assert tm.link_target == "" or _show_name_on_error(path_name)
if expected.mode is not None:
assert oct(tm.mode) == oct(expected.mode) or _show_name_on_error(path_name)
if expected.mtime is not None:
assert tm.mtime == expected.mtime or _show_name_on_error(path_name)
assert tm.owner == expected.owner or _show_name_on_error(path_name)
assert tm.group == expected.group or _show_name_on_error(path_name)
assert _has_fs_path(tm) == expected.has_fs_path or _show_name_on_error(
path_name
)
del result["./"]
if len(result) != len(expected_results):
for tm in result.values():
assert tm.member_path in expected_table
def test_mtime_clamp_and_builtin_dir_mode(
manifest_parser_pkg_foo: YAMLManifestParser,
) -> None:
manifest = manifest_parser_pkg_foo.build_manifest()
claim_mtime_to = 255
path_defs: List[Tuple[PathDef, Expected]] = [
(
virtual_path_def("usr/", mode=0o700, mtime=10, fs_path="/nowhere/usr/"),
Expected(mode=0o755, mtime=10),
),
(
virtual_path_def(
"usr/bin/", mode=0o2534, mtime=5000, fs_path="/nowhere/usr/bin/"
),
Expected(mode=0o755, mtime=claim_mtime_to),
),
(
virtual_path_def(
"usr/bin/my-exec",
mtime=5000,
fs_path="/nowhere/usr/bin/my-exec",
link_target="../../some/where/else",
),
# Implementation detail; symlinks do not refer to their FS path in the intermediate manifest.
Expected(
mtime=claim_mtime_to, link_target="/some/where/else", has_fs_path=False
),
),
]
fs_root = build_virtual_fs([d[0] for d in path_defs], read_write_fs=True)
assert [p.name for p in manifest.all_packages] == ["foo"]
intermediate_manifest = manifest.apply_to_binary_staging_directory(
"foo", fs_root, claim_mtime_to
)
verify_paths(intermediate_manifest, path_defs)
def test_transformations_create_symlink(
manifest_parser_pkg_foo: YAMLManifestParser,
) -> None:
content = textwrap.dedent(
"""\
manifest-version: '0.1'
packages:
foo:
transformations:
- create-symlink:
path: 'usr/bin/my-exec'
target: '../../some/where/else'
- create-symlink:
path: 'usr/bin/{{PACKAGE}}'
target: '/usr/lib/{{DEB_HOST_MULTIARCH}}/{{PACKAGE}}/tool'
"""
)
manifest = manifest_parser_pkg_foo.parse_manifest(fd=content)
claim_mtime_to = 255
fs_root = build_virtual_fs(["./"], read_write_fs=True)
expected_results = [
("usr/", Expected(mode=0o755, mtime=claim_mtime_to, has_fs_path=False)),
("usr/bin/", Expected(mode=0o755, mtime=claim_mtime_to, has_fs_path=False)),
(
"usr/bin/my-exec",
Expected(
mtime=claim_mtime_to, link_target="/some/where/else", has_fs_path=False
),
),
(
"usr/bin/foo",
Expected(
mtime=claim_mtime_to,
# Test is using a "static" dpkg-architecture, so it will always be `x86_64-linux-gnu`
link_target="../lib/x86_64-linux-gnu/foo/tool",
has_fs_path=False,
),
),
]
assert [p.name for p in manifest.all_packages] == ["foo"]
intermediate_manifest = manifest.apply_to_binary_staging_directory(
"foo", fs_root, claim_mtime_to
)
verify_paths(intermediate_manifest, expected_results)
def test_transformations_create_symlink_replace_success(
manifest_parser_pkg_foo: YAMLManifestParser,
) -> None:
content = textwrap.dedent(
"""\
manifest-version: '0.1'
packages:
foo:
transformations:
- create-symlink:
path: 'usr/bin/my-exec'
target: '../../some/where/else'
"""
)
manifest = manifest_parser_pkg_foo.parse_manifest(fd=content)
clamp_mtime_to = 255
fs_root = build_virtual_fs(["./usr/bin/my-exec"], read_write_fs=True)
expected_results = [
("usr/", Expected(mode=0o755, mtime=clamp_mtime_to, has_fs_path=False)),
("usr/bin/", Expected(mode=0o755, mtime=clamp_mtime_to, has_fs_path=False)),
(
"usr/bin/my-exec",
Expected(
mtime=clamp_mtime_to, link_target="/some/where/else", has_fs_path=False
),
),
]
assert [p.name for p in manifest.all_packages] == ["foo"]
intermediate_manifest = manifest.apply_to_binary_staging_directory(
"foo", fs_root, clamp_mtime_to
)
verify_paths(intermediate_manifest, expected_results)
@pytest.mark.parametrize(
"replacement_rule, reason",
[
(
"abort-on-non-empty-directory",
"the path is a non-empty directory",
),
(
"error-if-directory",
"the path is a directory",
),
(
"error-if-exists",
"the path exists",
),
],
)
def test_transformations_create_symlink_replace_failure(
manifest_parser_pkg_foo: YAMLManifestParser,
replacement_rule: str,
reason: str,
) -> None:
content = textwrap.dedent(
f"""\
manifest-version: '0.1'
packages:
foo:
transformations:
- create-symlink:
path: 'usr/share/foo'
target: 'somewhere-else'
replacement-rule: {replacement_rule}
"""
)
manifest = manifest_parser_pkg_foo.parse_manifest(fd=content)
clamp_mtime_to = 255
fs_root = build_virtual_fs(["./usr/share/foo/bar"], read_write_fs=True)
assert [p.name for p in manifest.all_packages] == ["foo"]
with pytest.raises(TransformationRuntimeError) as e_info:
manifest.apply_to_binary_staging_directory("foo", fs_root, clamp_mtime_to)
msg = (
f"Refusing to replace ./usr/share/foo with a symlink; {reason} and the active"
f" replacement-rule was {replacement_rule}. You can set the replacement-rule to"
' "discard-existing", if you are not interested in the contents of ./usr/share/foo. This error'
# Ideally, this would be reported for line 5.
" was triggered by packages.foo.transformations[0].create-symlink [Line 6 column 18]."
)
assert e_info.value.args[0] == msg
def test_transformations_create_symlink_replace_with_explicit_remove(
manifest_parser_pkg_foo: YAMLManifestParser,
) -> None:
content = textwrap.dedent(
"""\
manifest-version: '0.1'
packages:
foo:
transformations:
- remove: usr/share/foo
- create-symlink:
path: 'usr/share/foo'
target: 'somewhere-else'
"""
)
manifest = manifest_parser_pkg_foo.parse_manifest(fd=content)
clamp_mtime_to = 255
fs_root = build_virtual_fs(["./usr/share/foo/bar"], read_write_fs=True)
expected_results = [
("usr/", Expected(mode=0o755, mtime=clamp_mtime_to, has_fs_path=False)),
("usr/share/", Expected(mode=0o755, mtime=clamp_mtime_to, has_fs_path=False)),
(
"usr/share/foo",
Expected(
mtime=clamp_mtime_to, link_target="somewhere-else", has_fs_path=False
),
),
]
assert [p.name for p in manifest.all_packages] == ["foo"]
intermediate_manifest = manifest.apply_to_binary_staging_directory(
"foo", fs_root, clamp_mtime_to
)
verify_paths(intermediate_manifest, expected_results)
def test_transformations_create_symlink_replace_with_replacement_rule(
manifest_parser_pkg_foo: YAMLManifestParser,
) -> None:
content = textwrap.dedent(
"""\
manifest-version: '0.1'
packages:
foo:
transformations:
- remove: usr/share/foo
- create-symlink:
path: 'usr/share/foo'
target: 'somewhere-else'
replacement-rule: 'discard-existing'
"""
)
manifest = manifest_parser_pkg_foo.parse_manifest(fd=content)
clamp_mtime_to = 255
fs_root = build_virtual_fs(["./usr/share/foo/bar"], read_write_fs=True)
expected_results = [
("usr/", Expected(mode=0o755, mtime=clamp_mtime_to, has_fs_path=False)),
("usr/share/", Expected(mode=0o755, mtime=clamp_mtime_to, has_fs_path=False)),
(
"usr/share/foo",
Expected(
mtime=clamp_mtime_to, link_target="somewhere-else", has_fs_path=False
),
),
]
assert [p.name for p in manifest.all_packages] == ["foo"]
intermediate_manifest = manifest.apply_to_binary_staging_directory(
"foo", fs_root, clamp_mtime_to
)
verify_paths(intermediate_manifest, expected_results)
def test_transformations_path_metadata(
manifest_parser_pkg_foo: YAMLManifestParser,
) -> None:
content = textwrap.dedent(
"""\
manifest-version: '0.1'
packages:
foo:
transformations:
- path-metadata:
path: 'usr/bin/my-exec'
mode: "-x"
owner: "bin"
group: 2
"""
)
manifest = manifest_parser_pkg_foo.parse_manifest(fd=content)
claim_mtime_to = 255
fs_root = build_virtual_fs(
[
virtual_path_def(
"./usr/bin/my-exec", fs_path="/no-where", mode=0o755, mtime=10
),
],
read_write_fs=True,
)
expected_results = [
("usr/", Expected(mode=0o755, mtime=claim_mtime_to, has_fs_path=False)),
("usr/bin/", Expected(mode=0o755, mtime=claim_mtime_to, has_fs_path=False)),
(
"usr/bin/my-exec",
Expected(
mtime=10,
has_fs_path=True,
mode=0o644,
owner="bin",
group="bin",
),
),
]
assert [p.name for p in manifest.all_packages] == ["foo"]
intermediate_manifest = manifest.apply_to_binary_staging_directory(
"foo", fs_root, claim_mtime_to
)
verify_paths(intermediate_manifest, expected_results)
def test_transformations_directories(
manifest_parser_pkg_foo: YAMLManifestParser,
) -> None:
content = textwrap.dedent(
"""\
manifest-version: '0.1'
packages:
foo:
transformations:
- create-directories:
path: some/empty/directory
mode: "0700"
- create-directories: another/empty/directory
- create-directories:
path: a/third-empty/directory
owner: www-data
group: www-data
"""
)
manifest = manifest_parser_pkg_foo.parse_manifest(fd=content)
claim_mtime_to = 255
paths = [
virtual_path_def("some/", mtime=10, fs_path="/nowhere/some"),
virtual_path_def("some/empty/", mtime=10, fs_path="/nowhere/some/empty"),
virtual_path_def(
"some/empty/directory/",
mode=0o755,
mtime=10,
fs_path="/nowhere/some/empty/directory",
),
]
fs_root = build_virtual_fs(paths, read_write_fs=True)
expected_results = [
("some/", Expected(mode=0o755, mtime=10, has_fs_path=True)),
("some/empty/", Expected(mode=0o755, mtime=10, has_fs_path=True)),
(
"some/empty/directory/",
Expected(mode=0o700, mtime=10, has_fs_path=True),
),
("another/", Expected(mode=0o755, mtime=claim_mtime_to, has_fs_path=False)),
(
"another/empty/",
Expected(mode=0o755, mtime=claim_mtime_to, has_fs_path=False),
),
(
"another/empty/directory/",
Expected(mode=0o755, mtime=claim_mtime_to, has_fs_path=False),
),
("a/", Expected(mode=0o755, mtime=claim_mtime_to, has_fs_path=False)),
(
"a/third-empty/",
Expected(mode=0o755, mtime=claim_mtime_to, has_fs_path=False),
),
(
"a/third-empty/directory/",
Expected(
mode=0o755,
mtime=claim_mtime_to,
owner="www-data",
group="www-data",
has_fs_path=False,
),
),
]
assert [p.name for p in manifest.all_packages] == ["foo"]
intermediate_manifest = manifest.apply_to_binary_staging_directory(
"foo", fs_root, claim_mtime_to
)
verify_paths(intermediate_manifest, expected_results)
def test_transformation_remove(
manifest_parser_pkg_foo: YAMLManifestParser,
) -> None:
content = textwrap.dedent(
"""\
manifest-version: '0.1'
packages:
foo:
transformations:
- remove: some/empty
"""
)
manifest = manifest_parser_pkg_foo.parse_manifest(fd=content)
claim_mtime_to = 255
paths = [
virtual_path_def("some/", mode=0o700, mtime=10, fs_path="/nowhere/some"),
virtual_path_def(
"some/empty/", mode=0o700, mtime=10, fs_path="/nowhere/some/empty"
),
virtual_path_def(
"some/empty/directory/",
mode=0o755,
mtime=10,
fs_path="/nowhere/some/empty/directory",
),
]
fs_root = build_virtual_fs(paths, read_write_fs=True)
expected_results = []
assert [p.name for p in manifest.all_packages] == ["foo"]
intermediate_manifest = manifest.apply_to_binary_staging_directory(
"foo", fs_root, claim_mtime_to
)
verify_paths(intermediate_manifest, expected_results)
def test_transformation_remove_keep_empty(
manifest_parser_pkg_foo: YAMLManifestParser,
) -> None:
content = textwrap.dedent(
"""\
manifest-version: '0.1'
packages:
foo:
transformations:
- remove:
path: some/empty
keep-empty-parent-dirs: true
"""
)
manifest = manifest_parser_pkg_foo.parse_manifest(fd=content)
claim_mtime_to = 255
paths = [
virtual_path_def("some/", mode=0o700, mtime=10, fs_path="/nowhere/some"),
virtual_path_def(
"some/empty/", mode=0o700, mtime=10, fs_path="/nowhere/some/empty"
),
virtual_path_def(
"some/empty/directory/",
mode=0o755,
mtime=10,
fs_path="/nowhere/some/empty/directory",
),
]
fs_root = build_virtual_fs(paths, read_write_fs=True)
expected_results = [
("some/", Expected(mode=0o755, mtime=10)),
]
assert [p.name for p in manifest.all_packages] == ["foo"]
intermediate_manifest = manifest.apply_to_binary_staging_directory(
"foo", fs_root, claim_mtime_to
)
verify_paths(intermediate_manifest, expected_results)
def test_transformation_remove_glob(
manifest_parser_pkg_foo: YAMLManifestParser,
) -> None:
content = textwrap.dedent(
"""\
manifest-version: '0.1'
packages:
foo:
transformations:
- remove: some/*.json
"""
)
manifest = manifest_parser_pkg_foo.parse_manifest(fd=content)
claim_mtime_to = 255
paths = [
virtual_path_def("some/", mode=0o700, mtime=10, fs_path="/nowhere/some"),
virtual_path_def(
"some/foo.json",
mode=0o600,
mtime=10,
),
virtual_path_def(
"some/bar.json",
mode=0o600,
mtime=10,
),
virtual_path_def(
"some/empty/", mode=0o700, mtime=10, fs_path="/nowhere/some/empty"
),
virtual_path_def(
"some/bar.txt", mode=0o600, mtime=10, fs_path="/nowhere/some/bar.txt"
),
virtual_path_def(
"some/bar.JSON", mode=0o600, mtime=10, fs_path="/nowhere/some/bar.JSON"
),
]
fs_root = build_virtual_fs(paths, read_write_fs=True)
expected_results = [
("some/", Expected(mode=0o755, mtime=10)),
("some/empty/", Expected(mode=0o755, mtime=10)),
("some/bar.txt", Expected(mode=0o644, mtime=10)),
# Survives because pattern is case-sensitive
("some/bar.JSON", Expected(mode=0o644, mtime=10)),
]
assert [p.name for p in manifest.all_packages] == ["foo"]
intermediate_manifest = manifest.apply_to_binary_staging_directory(
"foo", fs_root, claim_mtime_to
)
verify_paths(intermediate_manifest, expected_results)
def test_transformation_remove_no_match(
manifest_parser_pkg_foo: YAMLManifestParser,
) -> None:
content = textwrap.dedent(
"""\
manifest-version: '0.1'
packages:
foo:
transformations:
- remove: some/non-existing-path
"""
)
manifest = manifest_parser_pkg_foo.parse_manifest(fd=content)
claim_mtime_to = 255
paths = [
virtual_path_def("some/", mode=0o700, mtime=10, fs_path="/nowhere/some"),
virtual_path_def(
"some/empty/", mode=0o700, mtime=10, fs_path="/nowhere/some/empty"
),
virtual_path_def(
"some/empty/directory/",
mode=0o755,
mtime=10,
fs_path="/nowhere/some/empty/directory",
),
]
fs_root = build_virtual_fs(paths, read_write_fs=True)
assert [p.name for p in manifest.all_packages] == ["foo"]
with pytest.raises(TransformationRuntimeError) as e_info:
manifest.apply_to_binary_staging_directory("foo", fs_root, claim_mtime_to)
expected = (
'The match rule "./some/non-existing-path" in transformation'
' "packages.foo.transformations[0].remove [Line 5 column 18]" did not match any paths. Either'
" the definition is redundant (and can be omitted) or the match rule is incorrect."
)
assert expected == e_info.value.args[0]
def test_transformation_move_basic(
manifest_parser_pkg_foo: YAMLManifestParser,
) -> None:
content = textwrap.dedent(
"""\
manifest-version: '0.1'
packages:
foo:
transformations:
- move:
source: some/dir
target: new/dir/where-else
"""
)
manifest = manifest_parser_pkg_foo.parse_manifest(fd=content)
claim_mtime_to = 255
paths = [
virtual_path_def("some/", mode=0o700, mtime=10, fs_path="/nowhere/some"),
virtual_path_def(
"some/dir/", mode=0o700, mtime=10, fs_path="/nowhere/some/empty"
),
virtual_path_def(
"some/dir/some-dir-symlink1", mtime=10, link_target="/abs/some-target1"
),
virtual_path_def(
"some/dir/some-dir-symlink2", mtime=10, link_target="../some-target2"
),
virtual_path_def(
"some/dir/some-dir-symlink3",
mtime=10,
link_target="/new/dir/where-else/some-target3",
),
]
fs_root = build_virtual_fs(paths, read_write_fs=True)
assert [p.name for p in manifest.all_packages] == ["foo"]
expected_results = [
("some/", Expected(mode=0o755, mtime=10)),
("new/", Expected(mode=0o755, mtime=claim_mtime_to, has_fs_path=False)),
("new/dir/", Expected(mode=0o755, mtime=claim_mtime_to, has_fs_path=False)),
("new/dir/where-else/", Expected(mode=0o755, mtime=10)),
# FIXME: should be 10
(
"new/dir/where-else/some-dir-symlink1",
Expected(mtime=None, link_target="/abs/some-target1", has_fs_path=False),
),
(
"new/dir/where-else/some-dir-symlink2",
Expected(mtime=None, link_target="../some-target2", has_fs_path=False),
),
(
"new/dir/where-else/some-dir-symlink3",
Expected(mtime=None, link_target="some-target3", has_fs_path=False),
),
]
assert [p.name for p in manifest.all_packages] == ["foo"]
intermediate_manifest = manifest.apply_to_binary_staging_directory(
"foo", fs_root, claim_mtime_to
)
print(intermediate_manifest)
verify_paths(intermediate_manifest, expected_results)
def test_transformation_move_no_match(
manifest_parser_pkg_foo: YAMLManifestParser,
) -> None:
content = textwrap.dedent(
"""\
manifest-version: '0.1'
packages:
foo:
transformations:
- move:
source: some/non-existing-path
target: some/where-else
"""
)
manifest = manifest_parser_pkg_foo.parse_manifest(fd=content)
claim_mtime_to = 255
paths = [
virtual_path_def("some/", mode=0o700, mtime=10, fs_path="/nowhere/some"),
virtual_path_def(
"some/empty/", mode=0o700, mtime=10, fs_path="/nowhere/some/empty"
),
virtual_path_def(
"some/empty/directory/",
mode=0o755,
mtime=10,
fs_path="/nowhere/some/empty/directory",
),
]
fs_root = build_virtual_fs(paths, read_write_fs=True)
assert [p.name for p in manifest.all_packages] == ["foo"]
with pytest.raises(TransformationRuntimeError) as e_info:
manifest.apply_to_binary_staging_directory("foo", fs_root, claim_mtime_to)
expected = (
'The match rule "./some/non-existing-path" in transformation'
' "packages.foo.transformations[0].move [Line 6 column 12]" did not match any paths. Either'
" the definition is redundant (and can be omitted) or the match rule is incorrect."
)
assert expected == e_info.value.args[0]
def test_builtin_mode_normalization_shell_scripts(
manifest_parser_pkg_foo: YAMLManifestParser,
) -> None:
manifest = manifest_parser_pkg_foo.build_manifest()
claim_mtime_to = 255
sh_script_content = "#!/bin/sh"
python_script_content = "#! /usr/bin/python"
unrelated_content = "... random stuff ..."
paths = [
virtual_path_def("some/", mode=0o700, mtime=10, fs_path="/nowhere/some"),
virtual_path_def(
"some/dir/", mode=0o700, mtime=10, fs_path="/nowhere/some/empty"
),
virtual_path_def(
"some/dir/script.sh",
mode=0o600,
mtime=10,
fs_path="/nowhere/script.sh",
content=sh_script_content,
),
virtual_path_def(
"some/dir/script.py",
mode=0o600,
mtime=10,
fs_path="/nowhere/script.py",
content=python_script_content,
),
virtual_path_def(
"some/dir/non-script-file",
mode=0o600,
mtime=10,
fs_path="/nowhere/non-script-file",
content=unrelated_content,
),
]
fs_root = build_virtual_fs(paths, read_write_fs=True)
assert [p.name for p in manifest.all_packages] == ["foo"]
expected_results = [
("some/", Expected(mode=0o755, mtime=10)),
("some/dir/", Expected(mode=0o755, mtime=10)),
("some/dir/script.sh", Expected(mode=0o755, mtime=10)),
("some/dir/script.py", Expected(mode=0o755, mtime=10)),
("some/dir/non-script-file", Expected(mode=0o644, mtime=10)),
]
assert [p.name for p in manifest.all_packages] == ["foo"]
intermediate_manifest = manifest.apply_to_binary_staging_directory(
"foo", fs_root, claim_mtime_to
)
print(intermediate_manifest)
verify_paths(intermediate_manifest, expected_results)
def test_builtin_mode_normalization(
manifest_parser_pkg_foo: YAMLManifestParser,
) -> None:
manifest = manifest_parser_pkg_foo.build_manifest()
claim_mtime_to = 255
paths = [
virtual_path_def("usr/", mode=0o755, mtime=10, fs_path="/nowhere/usr"),
virtual_path_def(
"usr/share/", mode=0o755, mtime=10, fs_path="/nowhere/usr/share"
),
virtual_path_def(
"usr/share/perl5/", mode=0o755, mtime=10, fs_path="/nowhere/usr/share/perl5"
),
virtual_path_def(
"usr/share/perl5/Foo.pm",
# #1076346
mode=0o444,
mtime=10,
fs_path="/nowhere/Foo.pm",
),
virtual_path_def(
"usr/share/perl5/Bar.pm",
mode=0o755,
mtime=10,
fs_path="/nowhere/Bar.pm",
),
]
fs_root = build_virtual_fs(paths, read_write_fs=True)
assert [p.name for p in manifest.all_packages] == ["foo"]
expected_results = [
("usr/", Expected(mode=0o755, mtime=10)),
("usr/share/", Expected(mode=0o755, mtime=10)),
("usr/share/perl5/", Expected(mode=0o755, mtime=10)),
("usr/share/perl5/Bar.pm", Expected(mode=0o644, mtime=10)),
("usr/share/perl5/Foo.pm", Expected(mode=0o644, mtime=10)),
]
assert [p.name for p in manifest.all_packages] == ["foo"]
intermediate_manifest = manifest.apply_to_binary_staging_directory(
"foo", fs_root, claim_mtime_to
)
print(intermediate_manifest)
verify_paths(intermediate_manifest, expected_results)
|