From 200d1dec29a47dd98cb3ecb6ab4797ed21738bda Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Sat, 10 Mar 2018 19:14:32 +0200 Subject: [PATCH] dvc: move remove_untracked_hardlinks to inside the project Signed-off-by: Ruslan Kuprieiev --- dvc/command/checkout.py | 20 -------------------- dvc/project.py | 22 +++++++++++++++++++++- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/dvc/command/checkout.py b/dvc/command/checkout.py index cab8201ef..b29b77eda 100644 --- a/dvc/command/checkout.py +++ b/dvc/command/checkout.py @@ -8,25 +8,5 @@ from dvc.logger import Logger class CmdCheckout(CmdBase): def run(self): - self.remove_untracked_hardlinks() self.project.checkout() return 0 - - def remove_untracked_hardlinks(self): - untracked = self.project.scm.untracked_files() - cache = dict((System.inode(c), c) for c in self.project.cache.all()) - for file in untracked: - inode = System.inode(file) - if inode not in cache.keys(): - continue - - Logger.info(u'Remove \'{}\''.format(file)) - os.chmod(file, stat.S_IWRITE) - os.remove(file) - os.chmod(cache[inode], stat.S_IREAD) - - dir = os.path.dirname(file) - if len(dir) != 0 and not os.listdir(dir): - Logger.info(u'Remove empty directory \'{}\''.format(dir)) - os.removedirs(dir) - pass diff --git a/dvc/project.py b/dvc/project.py index 7c147182e..7028e5634 100644 --- a/dvc/project.py +++ b/dvc/project.py @@ -11,6 +11,7 @@ from dvc.lock import Lock from dvc.scm import SCM from dvc.cache import Cache from dvc.cloud.data_cloud import DataCloud +from dvc.system import System class StageNotFoundError(DvcException): @@ -149,7 +150,26 @@ class Project(object): raise ReproductionError(stages[n].relpath, ex) return result + def _remove_untracked_hardlinks(self): + untracked = self.scm.untracked_files() + cache = dict((System.inode(c), c) for c in self.cache.all()) + for file in untracked: + inode = System.inode(file) + if inode not in cache.keys(): + continue + + Logger.info(u'Remove \'{}\''.format(file)) + os.chmod(file, stat.S_IWRITE) + os.remove(file) + os.chmod(cache[inode], stat.S_IREAD) + + dir = os.path.dirname(file) + if len(dir) != 0 and not os.listdir(dir): + Logger.info(u'Remove empty directory \'{}\''.format(dir)) + os.removedirs(dir) + def checkout(self): + self._remove_untracked_hardlinks() for stage in self.stages(): stage.checkout() @@ -173,7 +193,7 @@ class Project(object): return list(cache_set) def _remove_cache_file(self, cache): - os.chmod(cache, stat.S_IWRITE) + os.chmod(cache, stat.S_IWRITE | stat.S_IREAD) os.unlink(cache) def gc(self):