mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
Refactoring: move find_cache() to Cache class
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import os
|
||||
|
||||
from dvc.system import System
|
||||
|
||||
|
||||
class Cache(object):
|
||||
CACHE_DIR = 'cache'
|
||||
@@ -23,3 +25,12 @@ class Cache(object):
|
||||
|
||||
def get(self, md5):
|
||||
return os.path.join(self.cache_dir, md5)
|
||||
|
||||
def find_cache(self, files):
|
||||
file_set = set(files)
|
||||
cached = {}
|
||||
for cache_file in self.all():
|
||||
cached_files = list(filter(lambda f: System.samefile(cache_file, f, True), file_set))
|
||||
cached.update(dict((f, os.path.basename(cache_file)) for f in cached_files))
|
||||
file_set = file_set - set(cached_files)
|
||||
return cached
|
||||
|
||||
+2
-13
@@ -2,7 +2,6 @@ import os
|
||||
|
||||
from dvc.command.common.base import CmdBase
|
||||
from dvc.logger import Logger
|
||||
from dvc.system import System
|
||||
|
||||
|
||||
class CmdCheckout(CmdBase):
|
||||
@@ -12,9 +11,9 @@ class CmdCheckout(CmdBase):
|
||||
return 0
|
||||
|
||||
def remove_untracked_hardlinks(self):
|
||||
untracked_cache_files = self.untracked_hardlinks_files()
|
||||
untracked = self.project.scm.untracked_files()
|
||||
|
||||
for file in untracked_cache_files:
|
||||
for file in self.project.cache.find_cache(untracked).keys():
|
||||
Logger.info(u'Remove \'{}\''.format(file))
|
||||
os.remove(file)
|
||||
|
||||
@@ -23,13 +22,3 @@ class CmdCheckout(CmdBase):
|
||||
Logger.info(u'Remove empty directory \'{}\''.format(dir))
|
||||
os.removedirs(dir)
|
||||
pass
|
||||
|
||||
def untracked_hardlinks_files(self):
|
||||
untracked_files = set(self.project.scm.untracked_files())
|
||||
cached_files = []
|
||||
for cache_file in self.project.cache.all():
|
||||
hardlinks = list(filter(lambda f: System.samefile(cache_file, f), untracked_files))
|
||||
cached_files.extend(hardlinks)
|
||||
untracked_files = untracked_files - set(hardlinks)
|
||||
|
||||
return cached_files
|
||||
|
||||
Reference in New Issue
Block a user