def test_update(self): path = os.path.join(self.dvc.root_dir, self.FOO) md5 = file_md5(path)[0] mtime = os.path.getmtime(path) inode = System.inode(path) state = State(self.dvc.root_dir, self.dvc.dvc_dir) state.update(path) entry = state.get(path) self.assertIsInstance(entry, StateEntry) self.assertEqual(entry.md5, md5) self.assertEqual(entry.mtime, mtime) self.assertEqual(entry.inode, inode) os.chmod(path, stat.S_IWRITE) os.unlink(path) with open(path, 'w+') as fd: fd.write('1') md5 = file_md5(path)[0] mtime = os.path.getmtime(path) inode = System.inode(path) entry = state.update(path) self.assertIsInstance(entry, StateEntry) self.assertEqual(entry.md5, md5) self.assertEqual(entry.mtime, mtime) self.assertEqual(entry.inode, inode)
def test_update(self): path = os.path.join(self.dvc.root_dir, self.FOO) md5 = file_md5(path)[0] mtime = os.path.getmtime(path) inode = System.inode(path) state = State(self.dvc.root_dir, self.dvc.dvc_dir) entry_md5 = state.update(path) self.assertEqual(entry_md5, md5) # Sleep some time to simulate realistic behavior. # Some filesystems have a bad date resolution for # mtime(i.e. 1sec for HFS) that cause problems with # our 'state' system not being able to distinguish # files that were modified within that delta. time.sleep(1) os.unlink(path) with open(path, 'w+') as fd: fd.write('1') md5 = file_md5(path)[0] mtime = os.path.getmtime(path) inode = System.inode(path) entry_md5 = state.update(path) self.assertEqual(entry_md5, md5) # Reload state db to make sure that it stays the same old_db = state._db state = State(self.dvc.root_dir, self.dvc.dvc_dir) new_db = state._db self.assertEqual(old_db, new_db)
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.remove(file) 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 outs_info(self, stage): FileInfo = collections.namedtuple("FileInfo", "path inode") paths = [ path for output in stage.outs for path in walk_files(output.path) ] return [ FileInfo(path=path, inode=System.inode(path)) for path in paths ]
def outs_info(self, stage): FileInfo = collections.namedtuple("FileInfo", "path inode") paths = [ path for output in stage["outs"] for path in self.dvc.tree.walk_files(output["path"]) ] return [ FileInfo(path=path, inode=System.inode(path)) for path in paths ]
def outs_info(self, stage): FileInfo = collections.namedtuple('FileInfo', 'path inode') paths = [ os.path.join(root, file) for output in stage.outs for root, _, files in os.walk(output.path) for file in files ] return [ FileInfo(path=path, inode=System.inode(path)) for path in paths ]
def update(self, path): mtime = os.path.getmtime(path) inode = System.inode(path) state = self._get(inode, mtime) if state: return state md5 = self.compute_md5(path) state = StateEntry(md5, mtime, inode) d = state.dumpd() if self._db.contains(self._q.inode == inode): self._db.update(d, self._q.inode == inode) else: self._db.insert(d) return state
def update(self, path, dump=True): mtime = os.path.getmtime(path) inode = System.inode(path) md5 = self._get(inode, mtime) if md5: return md5 md5 = self.compute_md5(path) state = StateEntry(md5, mtime) d = state.dumpd() self._db[inode] = d if dump: self.dump() return md5
def get_inode(path): inode = System.inode(path) logger.debug("Path {} inode {}".format(path, inode)) return inode
def inode(path): Logger.debug('Path {} inode {}'.format(path, System.inode(path))) return System.inode(path)
def _inode(path): logger.debug("Path {} inode {}".format(path, System.inode(path))) return System.inode(path)
def get_inode(path): inode = System.inode(path) logger.debug("Path '%s' inode '%d'", path, inode) return inode
def inode(path): return System.inode(path)
def inode(path): return str(System.inode(path))
def get(self, path): mtime = os.path.getmtime(path) inode = System.inode(path) return self._get(inode, mtime)