Exemplo n.º 1
0
def _dir_output_paths(repo_fs, output, targets=None):
    from dvc.config import NoRemoteError

    try:
        for fname in repo_fs.walk_files(output.path_info):
            if targets is None or any(
                    fname.isin_or_eq(target) for target in targets):
                yield str(fname), get_file_hash(fname, repo_fs, "md5").value
    except NoRemoteError:
        logger.warning("dir cache entry for '%s' is missing", output)
Exemplo n.º 2
0
def test_get_hash_dirty_file(tmp_dir, dvc):
    from dvc.objects import check
    from dvc.objects.errors import ObjectFormatError
    from dvc.objects.stage import get_file_hash

    tmp_dir.dvc_gen("file", "file")
    file_hash_info = HashInfo("md5", "8c7dd922ad47494fc02c388e12c00eac")

    (tmp_dir / "file").write_text("something")
    something_hash_info = HashInfo("md5", "437b930db84b8079c2dd804a71936b5f")

    clean_staging()

    # file is modified in workspace
    # get_file_hash(file) should return workspace hash, not DVC cached hash
    fs = RepoFileSystem(repo=dvc)
    assert fs.info(PathInfo(tmp_dir) / "file").get("md5") is None
    staging, _, obj = stage(dvc.odb.local,
                            PathInfo(tmp_dir) / "file", fs, "md5")
    assert obj.hash_info == something_hash_info
    check(staging, obj)

    # file is removed in workspace
    # any staged object referring to modified workspace obj is now invalid
    (tmp_dir / "file").unlink()
    with pytest.raises(ObjectFormatError):
        check(staging, obj)

    # get_file_hash(file) should return DVC cached hash
    assert fs.info(PathInfo(tmp_dir) / "file")["md5"] == file_hash_info.value
    _, hash_info = get_file_hash(PathInfo(tmp_dir) / "file",
                                 fs,
                                 "md5",
                                 state=dvc.state)
    assert hash_info == file_hash_info

    # tmp_dir/file can be staged even though it is missing in workspace since
    # repofs will use the DVC cached hash (and refer to the local cache object)
    _, _, obj = stage(dvc.odb.local, PathInfo(tmp_dir) / "file", fs, "md5")
    assert obj.hash_info == file_hash_info