Exemplo n.º 1
0
def test_add_dir():
    mtree = MtreeFile(verbose=False)
    mtree.add_dir("bin")
    expected = """#mtree 2.0
. type=dir uname=root gname=wheel mode=0755
./bin type=dir uname=root gname=wheel mode=0755
# END
"""
    assert expected == _get_as_str(mtree)
    mtree = MtreeFile(verbose=False)
    # same with a trailing slash
    mtree.add_dir("bin/", mode="0755")
    assert expected == _get_as_str(mtree)
Exemplo n.º 2
0
def test_add_dir_infer_mode():
    mtree = MtreeFile(verbose=False)
    with tempfile.TemporaryDirectory() as td:
        parent_dir = _create_dir(Path(td), "parent", 0o750)
        testdir = _create_dir(parent_dir, "testdir", 0o700)
        mtree.add_dir("foo/bar", reference_dir=testdir)
        expected = """#mtree 2.0
. type=dir uname=root gname=wheel mode=0755
./foo type=dir uname=root gname=wheel mode=0750
./foo/bar type=dir uname=root gname=wheel mode=0700
# END
"""
        assert expected == _get_as_str(mtree)
Exemplo n.º 3
0
def test_normalize_paths():
    # The makefs for cheribsd was failing because mtree contained the following lines:
    # ./usr/lib/debug//usr/tests and then later on
    # ./usr/lib/debug/usr/tests
    # One of the two was added by cheribuild because a file with the double slash was added so
    # the mtree code assumed the file did not exist:
    mtree = MtreeFile(verbose=False)
    assert len(mtree._mtree) == 0
    mtree.add_dir("usr/lib/debug/usr/tests")
    assert len(mtree._mtree) == 6
    mtree.add_dir("usr/lib/debug//usr/tests")
    # This should not add another entry!
    assert len(mtree._mtree) == 6
    assert normalized_usr_tests_duplicate_mtree == _get_as_str(mtree)