Esempio n. 1
0
def _make_mutate_ops_subvolume(
    subvols: TempSubvolumes,
    create_ops: Subvol,
    path: bytes,
) -> Subvol:
    'Exercise the send-stream ops that are unique to snapshots.'
    subvol = subvols.snapshot(create_ops, path)  # snapshot
    run = partial(subvol.run_as_root, cwd=subvol.path())

    run(['rm', 'hello/world'])  # unlink
    run(['rmdir', 'dir_to_remove/'])  # rmdir
    run([  # remove_xattr
        'setfattr',
        '--remove=user.test_attr',
        'hello/',
    ])
    # You would think this would emit a `rename`, but for files, the
    # sendstream instead `link`s to the new location, and unlinks the old.
    run(['mv', 'goodbye', 'farewell'])  # NOT a rename, {,un}link
    run(['mv', 'hello/', 'hello_renamed/'])  # yes, a rename!
    run(  # write
        ['dd', 'of=hello_renamed/een'],
        input=b'push\n',
    )
    # This is a no-op because `btfs send` does not support `chattr` at
    # present.  However, it's good to have a canary so that our tests start
    # failing the moment it is supported -- that will remind us to update
    # the mock VFS.  NB: The absolute path to `chattr` is a clowny hack to
    # work around a clowny hack, to work around clowny hacks.  Don't ask.
    run(['/usr/bin/chattr', '+a', 'hello_renamed/een'])

    return subvol
Esempio n. 2
0
def _make_mutate_ops_subvolume(
    subvols: TempSubvolumes,
    create_ops: Subvol,
    path: bytes,
) -> Subvol:
    'Exercise the send-stream ops that are unique to snapshots.'
    subvol = subvols.snapshot(create_ops, path)  # snapshot
    run = subvol.run_as_root

    # `cwd` is intentionally prohibited with `run_as_root`
    def p(sv_path):
        return subvol.path(sv_path).decode()

    run(['rm', p('hello/world')])  # unlink
    run(['rmdir', p('dir_to_remove/')])  # rmdir
    run([  # remove_xattr
        'setfattr',
        '--remove=user.test_attr',
        p('hello/'),
    ])
    # You would think this would emit a `rename`, but for files, the
    # sendstream instead `link`s to the new location, and unlinks the old.
    run(['mv', p('goodbye'), p('farewell')])  # NOT a rename, {,un}link
    run(['mv', p('hello/'), p('hello_renamed/')])  # yes, a rename!
    run(  # write
        ['dd', 'of=' + p('hello_renamed/een')],
        input=b'push\n',
    )
    # This is a no-op because `btfs send` does not support `chattr` at
    # present.  However, it's good to have a canary so that our tests start
    # failing the moment it is supported -- that will remind us to update
    # the mock VFS.  NB: The absolute path to `chattr` is a clowny hack to
    # work around a clowny hack, to work around clowny hacks.  Don't ask.
    run(['/usr/bin/chattr', '+a', p('hello_renamed/een')])
    # Besides files with trailing holes, one can also get `truncate`
    # sendstream commands in incremental sendstreams by having a snapshot
    # truncate relative a file relative to the parent.
    run(['truncate', '-s', '2', p('hello_big_hole')])

    return subvol