dvc: properly handle relative symlinks (#4275)

Fix #4160
This commit is contained in:
Ruslan Kuprieiev
2020-07-24 14:44:04 +03:00
committed by GitHub
parent 1fd8b47936
commit 39c0bdbe79
2 changed files with 21 additions and 2 deletions
+1 -2
View File
@@ -96,8 +96,7 @@ def move(src, dst, mode=None):
tmp = f"{dst}.{uuid()}"
if os.path.islink(src):
# readlink does not accept path-like obj for Windows in Python <3.8
shutil.copy(os.readlink(os.fspath(src)), tmp)
shutil.copy(src, tmp)
os.unlink(src)
else:
shutil.move(src, tmp)
+20
View File
@@ -806,3 +806,23 @@ def test_add_pipeline_file(tmp_dir, dvc, run_copy):
with pytest.raises(OutputIsStageFileError):
dvc.add(PIPELINE_FILE)
def test_add_symlink(tmp_dir, dvc):
tmp_dir.gen({"dir": {"bar": "bar"}})
(tmp_dir / "dir" / "foo").symlink_to(os.path.join(".", "bar"))
dvc.add(os.path.join("dir", "foo"))
assert not (tmp_dir / "dir" / "foo").is_symlink()
assert not (tmp_dir / "dir" / "bar").is_symlink()
assert (tmp_dir / "dir" / "foo").read_text() == "bar"
assert (tmp_dir / "dir" / "bar").read_text() == "bar"
assert (tmp_dir / ".dvc" / "cache").read_text() == {
"37": {"b51d194a7513e45b56f6524f2d51f2": "bar"}
}
assert not (
tmp_dir / ".dvc" / "cache" / "37" / "b51d194a7513e45b56f6524f2d51f2"
).is_symlink()