Merge pull request #454 from efiop/master

'add dir' bugfixes and tests
This commit is contained in:
Ruslan Kuprieiev
2018-02-03 15:14:35 +02:00
committed by GitHub
3 changed files with 30 additions and 2 deletions
+9 -2
View File
@@ -284,10 +284,17 @@ class Output(Dependency):
md5 = file_md5(path)[0]
cache = self.project.cache.get(md5)
cache_info = os.path.join(self.cache, relpath)
cache_dir = os.path.dirname(cache_info)
self.hardlink(path, cache)
if os.path.exists(cache):
self._remove(path, None)
self.hardlink(cache, path)
else:
self.hardlink(path, cache)
if not os.path.exists(cache_dir):
os.makedirs(cache_dir)
os.makedirs(os.path.dirname(cache_info))
with open(cache_info, 'w') as fd:
yaml.safe_dump({self.PARAM_MD5: md5}, fd, default_flow_style=False)
+1
View File
@@ -2,3 +2,4 @@ coverage==4.3.1
codeclimate-test-reporter==0.2.3
xmltodict==0.11.0
awscli==1.14.18
pywin32; sys_platform == 'nt'
+20
View File
@@ -1,4 +1,5 @@
import os
import stat
import shutil
import filecmp
from checksumdir import dirhash
@@ -59,6 +60,25 @@ class TestAddTrackedFile(TestDvc):
self.dvc.add(fname)
class TestAddDirWithExistingCache(TestDvc):
def test(self):
dname = 'a'
fname = os.path.join(dname, 'b')
os.mkdir(dname)
shutil.copyfile(self.FOO, fname)
self.dvc.add(self.FOO)
self.dvc.add(dname)
class TestAddModifiedDir(TestDvc):
def test(self):
self.dvc.add(self.DATA_DIR)
os.chmod(self.DATA, stat.S_IWRITE)
os.unlink(self.DATA)
self.dvc.add(self.DATA_DIR)
class TestCmdAdd(TestDvc):
def test(self):
ret = main(['add',