Пример #1
0
def unpack_into(snapshot_path: Path, output_path: Path) -> BaseSnapshot:
    """Unpack a snapshot into the specified output directory.

    Returns the appropriate BaseSnapshot subclass for this snapshot.
    """
    # GNU tar is smart enough to automatically figure out the correct
    # decompression method.
    untar_cmd = ["tar", "-xf", str(snapshot_path.absolute())]
    subprocess.check_call(untar_cmd, cwd=output_path)

    data_dir = output_path / "data"
    try:
        with (data_dir / "info.json").open("r") as info_file:
            info = json.load(info_file)

        type_name = info["type"]
        snapshot_type = snapshot_types.get(type_name)
        if snapshot_type is None:
            raise UnknownSnapshotTypeError(type_name)

        # pyre-fixme[45]: Cannot instantiate abstract class `BaseSnapshot`.
        snapshot = snapshot_type(output_path)
        snapshot.resume()
        return snapshot
    except Exception:
        cleanup_tmp_dir(data_dir)
        raise
Пример #2
0
def unpack_into(snapshot_path: Path, output_path: Path) -> BaseSnapshot:
    """Unpack a snapshot into the specified output directory.

    Returns the appropriate BaseSnapshot subclass for this snapshot.
    """
    # GNU tar is smart enough to automatically figure out the correct
    # decompression method.
    untar_cmd = ["tar", "-xf", str(snapshot_path.absolute())]
    subprocess.check_call(untar_cmd, cwd=output_path)

    data_dir = output_path / "data"
    try:
        with (data_dir / "info.json").open("r") as info_file:
            info = json.load(info_file)

        type_name = info["type"]
        snapshot_type = snapshot_types.get(type_name)
        if snapshot_type is None:
            raise UnknownSnapshotTypeError(type_name)

        snapshot = snapshot_type(output_path)
        snapshot.resume()
        return snapshot
    except Exception as ex:
        cleanup_tmp_dir(data_dir)
        raise
Пример #3
0
def create_tmp_dir() -> typing.Iterator[pathlib.Path]:
    """A helper class to manage temporary directories for snapshots.

    This is similar to the standard tempdir.TemporaryDirectory code,
    but does a better job of cleaning up the directory if some of its contents are
    read-only.
    """
    tmpdir = pathlib.Path(tempfile.mkdtemp(prefix="eden_data."))
    try:
        yield tmpdir
    finally:
        cleanup_tmp_dir(tmpdir)
def create_tmp_dir() -> typing.Iterator[pathlib.Path]:
    """A helper class to manage temporary directories for snapshots.

    This is similar to the standard tempdir.TemporaryDirectory code,
    but does a better job of cleaning up the directory if some of its contents are
    read-only.
    """
    tmpdir = pathlib.Path(tempfile.mkdtemp(prefix="eden_data."))
    try:
        yield tmpdir
    finally:
        cleanup_tmp_dir(tmpdir)
Пример #5
0
 def clean_up(path_str: str) -> None:
     if os.environ.get("EDEN_TEST_NO_CLEANUP"):
         print("Leaving behind eden test directory %r" % path_str)
     else:
         cleanup_tmp_dir(pathlib.Path(path_str))