def link(self, checkout=False): if not self.use_cache: raise OutputNoCacheError(self.path) if not os.path.exists(self.path) and not os.path.exists(self.cache): raise OutputNoCacheError(self.path) if os.path.exists(self.path) and \ os.path.exists(self.cache) and \ System.samefile(self.path, self.cache) and \ os.stat(self.cache).st_mode & stat.S_IREAD: return if os.path.exists(self.cache): if os.path.exists(self.path): # This means that we already have cache for this data. # We remove data and link it to existing cache to save # some space. os.unlink(self.path) src = self.cache link = self.path elif not checkout: src = self.path link = self.cache else: raise OutputNoCacheError(self.path) System.hardlink(src, link) os.chmod(self.path, stat.S_IREAD)
def _changed_file(self, path, cache): if os.path.isfile(path) and \ os.path.isfile(cache) and \ System.samefile(path, cache) and \ not self._changed_cache(cache): return False return True
def _changed_file(self, path, cache): if os.path.isfile(path) and \ os.path.isfile(cache) and \ System.samefile(path, cache) and \ os.stat(cache).st_mode & stat.S_IREAD: return False return True
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), 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
def cache_ok(item): data = item.data.relative cache = item.cache.relative if not os.path.isfile(data) or not os.path.isfile(cache): return False if not System.samefile(data, cache): return False return True
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
def changed(self): if not self.use_cache: changed = self._changed_md5() else: changed = os.path.exists(self.path) \ and os.path.exists(self.cache) \ and not System.samefile(self.path, self.cache) if changed: self.project.logger.debug('{} changed'.format(self.path)) return changed
def changed(self): ret = True if not self.use_cache: ret = super(Output, self).changed() elif os.path.exists(self.path) and \ os.path.exists(self.cache) and \ System.samefile(self.path, self.cache) and \ os.stat(self.cache).st_mode & stat.S_IREAD: ret = False msg = "Data {} with cache {} " if ret: msg += "changed" else: msg += "didn't change" self.project.logger.debug(msg.format(self.path, self.cache)) return ret