diff options
-rw-r--r-- | src/python/gudhi/datasets/remote.py | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/python/gudhi/datasets/remote.py b/src/python/gudhi/datasets/remote.py index fdd20f74..b266467d 100644 --- a/src/python/gudhi/datasets/remote.py +++ b/src/python/gudhi/datasets/remote.py @@ -60,20 +60,24 @@ def fetch(url, filename, dirname = "remote_datasets", file_checksum = None): file_path: string Full path of the created file. """ - if not exists(dirname): - makedirs(dirname) file_path = join(dirname, filename) - urlretrieve(url, file_path) - - if file_checksum is not None: - checksum = _checksum_sha256(file_path) - if file_checksum != checksum: - raise IOError("{} has a SHA256 checksum : {}, " - "different from expected : {}." - "The file may be corrupted or the given url may be wrong !".format(file_path, checksum, - file_checksum)) + # Check that an existing file does not already exist at file_path + if not exists(file_path): + # Create directory if not existing + if not exists(dirname): + makedirs(dirname) + + urlretrieve(url, file_path) + + if file_checksum is not None: + checksum = _checksum_sha256(file_path) + if file_checksum != checksum: + raise IOError("{} has a SHA256 checksum : {}, " + "different from expected : {}." + "The file may be corrupted or the given url may be wrong !".format(file_path, checksum, + file_checksum)) return file_path |