diff --git a/dvc/remote/base.py b/dvc/remote/base.py index 8738c2d07..34a60e915 100644 --- a/dvc/remote/base.py +++ b/dvc/remote/base.py @@ -108,7 +108,47 @@ class RemoteBase(object): raise NotImplementedError def changed(self, path_info, checksum_info): - raise NotImplementedError + """Checks if data has changed. + + A file is considered changed if: + - It doesn't exist on the working directory (was unlinked) + - Checksum is not computed (saving a new file) + - The checkusm stored in the State is different from the given one + - There's no file in the cache + + Args: + path_info: dict with path information. + checksum: expected checksum for this data. + + Returns: + bool: True if data has changed, False otherwise. + """ + + logger.debug("checking if '{}'('{}') has changed." + .format(path_info, checksum_info)) + + if not self.exists(path_info): + logger.debug("'{}' doesn't exist.".format(path_info)) + return True + + checksum = checksum_info.get(self.PARAM_CHECKSUM) + if checksum is None: + logger.debug("checksum for '{}' is missing.".format(path_info)) + return True + + if self.changed_cache(checksum): + logger.debug("cache for '{}'('{}') has changed." + .format(path_info, checksum)) + return True + + actual = self.save_info(path_info)[self.PARAM_CHECKSUM] + if checksum != actual: + logger.debug("checksum '{}'(actual '{}') for '{}' has changed." + .format(checksum, actual, path_info)) + return True + + logger.debug("'{}' hasn't changed.".format(path_info)) + return False def save(self, path_info): raise NotImplementedError diff --git a/dvc/remote/gs.py b/dvc/remote/gs.py index 8530f36b2..4288bf39a 100644 --- a/dvc/remote/gs.py +++ b/dvc/remote/gs.py @@ -63,19 +63,6 @@ class RemoteGS(RemoteBase): return {self.PARAM_CHECKSUM: self.get_md5(path_info['bucket'], path_info['path'])} - def changed(self, path_info, checksum_info): - if not self.exists(path_info): - return True - - md5 = checksum_info.get(self.PARAM_CHECKSUM, None) - if md5 is None: - return True - - if self.changed_cache(md5): - return True - - return checksum_info != self.save_info(path_info) - def copy(self, from_info, to_info, gs=None): gs = gs if gs else self.gs diff --git a/dvc/remote/hdfs.py b/dvc/remote/hdfs.py index ec1fdf105..fb8c75bd4 100644 --- a/dvc/remote/hdfs.py +++ b/dvc/remote/hdfs.py @@ -84,19 +84,6 @@ class RemoteHDFS(RemoteBase): return {self.PARAM_CHECKSUM: self.checksum(path_info)} - def changed(self, path_info, checksum_info): - if not self.exists(path_info): - return True - - checksum = checksum_info.get(self.PARAM_CHECKSUM, None) - if checksum is None: - return True - - if self.changed_cache(checksum): - return True - - return checksum_info != self.save_info(path_info) - def save(self, path_info): if path_info['scheme'] != 'hdfs': raise NotImplementedError diff --git a/dvc/remote/local.py b/dvc/remote/local.py index 86acc79a0..99e6884a4 100644 --- a/dvc/remote/local.py +++ b/dvc/remote/local.py @@ -429,26 +429,6 @@ class RemoteLOCAL(RemoteBase): return {self.PARAM_CHECKSUM: self.state.update(path_info['path'])} - def changed(self, path_info, checksum_info): - """ - A file is considered changed if: - - It doesn't exist on the working directory (was unlinked) - - Checksum is not computed (saving a new file) - - The checkusm stored in the State is different from the given one - - There's no file in the cache - """ - if not self.exists(path_info): - return True - - md5 = checksum_info.get(self.PARAM_CHECKSUM, None) - if md5 is None: - return True - - if self.changed_cache(md5): - return True - - return checksum_info != self.save_info(path_info) - def remove(self, path_info): if path_info['scheme'] != 'local': raise NotImplementedError diff --git a/dvc/remote/s3.py b/dvc/remote/s3.py index 420985520..75dc3f6aa 100644 --- a/dvc/remote/s3.py +++ b/dvc/remote/s3.py @@ -98,19 +98,6 @@ class RemoteS3(RemoteBase): return {self.PARAM_CHECKSUM: self.get_etag(path_info['bucket'], path_info['path'])} - def changed(self, path_info, checksum_info): - if not self.exists(path_info): - return True - - etag = checksum_info.get(self.PARAM_CHECKSUM, None) - if etag is None: - return True - - if self.changed_cache(etag): - return True - - return checksum_info != self.save_info(path_info) - def copy(self, from_info, to_info, s3=None): s3 = s3 if s3 else self.s3 diff --git a/dvc/remote/ssh.py b/dvc/remote/ssh.py index 2758ef903..54030105d 100644 --- a/dvc/remote/ssh.py +++ b/dvc/remote/ssh.py @@ -218,19 +218,6 @@ class RemoteSSH(RemoteBase): return {self.PARAM_CHECKSUM: self.md5(path_info)} - def changed(self, path_info, checksum_info): - if not self.exists(path_info): - return True - - md5 = checksum_info.get(self.PARAM_CHECKSUM, None) - if md5 is None: - return True - - if self.changed_cache(md5): - return True - - return checksum_info != self.save_info(path_info) - def save(self, path_info): if path_info['scheme'] != 'ssh': raise NotImplementedError