From 8bf0c1e4f1342703a22960417a9ff31f21271518 Mon Sep 17 00:00:00 2001 From: "John T. Wodder II" Date: Thu, 28 Oct 2021 16:31:11 -0400 Subject: [PATCH 1/3] download: Yield error dict instead of raising when dandiset.yaml already exists --- dandi/download.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dandi/download.py b/dandi/download.py index 122b887eb..0a1ced6ad 100644 --- a/dandi/download.py +++ b/dandi/download.py @@ -385,7 +385,8 @@ def _populate_dandiset_yaml(dandiset_path, dandiset, existing): mtime = dandiset.modified if op.lexists(dandiset_yaml): if existing == "error": - raise FileExistsError(dandiset_yaml) + yield {"status": "error", "message": "already exists"} + return elif existing == "refresh" and op.lexists( op.join(dandiset_path, ".git", "annex") ): From 34a3b93d43f0f88e6b81e4ac435130f8877a49b5 Mon Sep 17 00:00:00 2001 From: "John T. Wodder II" Date: Thu, 28 Oct 2021 16:31:44 -0400 Subject: [PATCH 2/3] Don't reuse variables like that --- dandi/download.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dandi/download.py b/dandi/download.py index 0a1ced6ad..4442808d7 100644 --- a/dandi/download.py +++ b/dandi/download.py @@ -397,10 +397,10 @@ def _populate_dandiset_yaml(dandiset_path, dandiset, existing): ): yield _skip_file("already exists") return - dandiset = Dandiset(dandiset_path, allow_empty=True) - dandiset.path_obj.mkdir(exist_ok=True) # exist_ok in case of parallel race - old_metadata = dandiset.metadata - dandiset.update_metadata(metadata) + ds = Dandiset(dandiset_path, allow_empty=True) + ds.path_obj.mkdir(exist_ok=True) # exist_ok in case of parallel race + old_metadata = ds.metadata + ds.update_metadata(metadata) os.utime(dandiset_yaml, (time.time(), mtime.timestamp())) yield { "status": "done", From 50079f7725c1abc14bc8c144262de88af412090d Mon Sep 17 00:00:00 2001 From: "John T. Wodder II" Date: Thu, 28 Oct 2021 16:33:06 -0400 Subject: [PATCH 3/3] download: Do nothing if dandiset.yaml already has correct contents --- dandi/download.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dandi/download.py b/dandi/download.py index 4442808d7..6d9dec7ca 100644 --- a/dandi/download.py +++ b/dandi/download.py @@ -26,6 +26,7 @@ on_windows, path_is_subpath, pluralize, + yaml_load, ) lgr = get_logger() @@ -384,6 +385,10 @@ def _populate_dandiset_yaml(dandiset_path, dandiset, existing): lgr.debug("Updating %s from obtained dandiset metadata", dandiset_metadata_file) mtime = dandiset.modified if op.lexists(dandiset_yaml): + with open(dandiset_yaml) as fp: + if yaml_load(fp, typ="safe") == metadata: + yield _skip_file("no change") + return if existing == "error": yield {"status": "error", "message": "already exists"} return