Esempio n. 1
0
def test_ensure_copy(tmp_path):
    tmp = Path(str(tmp_path))
    s = tmp.join('s')
    with s.open('w') as fd:
        fd.write('f')
    d = tmp.join('d')
    assert s.exists() and s.isfile()
    assert not d.exists() and not d.isfile()
    ensure_copy(d, s)
    assert s.exists() and s.isfile()
    assert d.exists() and d.isfile()
Esempio n. 2
0
def test_farmdbg_reverse(tmp_path, capsys, a, b, c):
    root = Path(str(tmp_path))
    r1 = farmfs_ui(['mkfs'], root)
    captured = capsys.readouterr()
    assert r1 == 0
    a_path = Path(a, root)
    with a_path.open('w') as a_fd:
        a_fd.write('a')
    a_csum = str(a_path.checksum())
    bc_path = Path(b, root).join(c)
    ensure_copy(bc_path, a_path)
    r2 = farmfs_ui(['freeze'], root)
    captured = capsys.readouterr()
    r3 = farmfs_ui(['snap', 'make', 'mysnap'], root)
    assert r3 == 0
    r4 = dbg_ui(['walk', 'root'], root)
    captured = capsys.readouterr()
    assert r4 == 0
    assert captured.out == ".\tdir\t\n%s\tlink\t%s\n%s\tdir\t\n%s/%s\tlink\t%s\n" % (
        a, a_csum, b, b, c, a_csum)
    assert captured.err == ''
    r5 = dbg_ui(['walk', 'userdata'], root)
    captured = capsys.readouterr()
    assert r5 == 0
    assert captured.out == a_csum + '\n'
    assert captured.err == ''
    r6 = dbg_ui(['reverse', a_csum], root)
    captured = capsys.readouterr()
    assert r6 == 0
    assert captured.out == "<tree> " + a + "\n<tree> " + b + "/" + c + "\n"
    assert captured.err == ''
    r7 = dbg_ui(['reverse', '--all', a_csum], root)
    captured = capsys.readouterr()
    assert r7 == 0
    assert captured.out == "<tree> " + a + "\n<tree> " + b + "/" + c + "\nmysnap " + a + "\nmysnap " + b + "/" + c + "\n"
    assert captured.err == ''
    r8 = dbg_ui(['reverse', '--snap', 'mysnap', a_csum], root)
    captured = capsys.readouterr()
    assert r8 == 0
    assert captured.out == "mysnap " + a + "\nmysnap " + b + "/" + c + "\n"
    assert captured.err == ''
Esempio n. 3
0
def test_farmdbg_reverse(vol, capsys, a, b, c):
    a_path = Path(a, vol)
    with a_path.open('w') as a_fd:
        a_fd.write('a')
    a_csum = str(a_path.checksum())
    bc_path = Path(b, vol).join(c)
    ensure_copy(bc_path, a_path)
    r = farmfs_ui(['freeze'], vol)
    captured = capsys.readouterr()
    r = farmfs_ui(['snap', 'make', 'mysnap'], vol)
    assert r == 0
    r = dbg_ui(['walk', 'root'], vol)
    captured = capsys.readouterr()
    assert r == 0
    assert captured.out == ".\tdir\t\n%s\tlink\t%s\n%s\tdir\t\n%s/%s\tlink\t%s\n" % (
        a, a_csum, b, b, c, a_csum)
    assert captured.err == ''
    r = dbg_ui(['walk', 'userdata'], vol)
    captured = capsys.readouterr()
    assert r == 0
    assert captured.out == a_csum + '\n'
    assert captured.err == ''
    r = dbg_ui(['reverse', a_csum], vol)
    captured = capsys.readouterr()
    assert r == 0
    assert captured.out == "<tree> " + a + "\n<tree> " + b + "/" + c + "\n"
    assert captured.err == ''
    r = dbg_ui(['reverse', '--all', a_csum], vol)
    captured = capsys.readouterr()
    assert r == 0
    assert captured.out == "<tree> " + a + "\n<tree> " + b + "/" + c + "\nmysnap " + a + "\nmysnap " + b + "/" + c + "\n"
    assert captured.err == ''
    r = dbg_ui(['reverse', '--snap', 'mysnap', a_csum], vol)
    captured = capsys.readouterr()
    assert r == 0
    assert captured.out == "mysnap " + a + "\nmysnap " + b + "/" + c + "\n"
    assert captured.err == ''
Esempio n. 4
0
 def fetch_blob(self, remote, csum):
     src_blob = remote.csum_to_path(csum)
     dst_blob = self.csum_to_path(csum)
     duplicate = dst_blob.exists()
     if not duplicate:
         ensure_copy(dst_blob, src_blob)