From 755c18a11f87040245964cf411ea8f518b61e0f5 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 12 Mar 2021 09:23:47 +0200 Subject: fix: create symlink as requested in test data Link name/target were swapped. I keep making this mistake even when checking that I'm doing it the right way. --- subplot/data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subplot/data.py b/subplot/data.py index 0c1a4a5..8817909 100644 --- a/subplot/data.py +++ b/subplot/data.py @@ -39,7 +39,7 @@ def chmod_file(ctx, filename=None, mode=None): def create_symlink(ctx, linkname=None, target=None): - os.symlink(linkname, target) + os.symlink(target, linkname) def create_manifest_of_live(ctx, dirname=None, manifest=None): -- cgit v1.2.1 From d848a9587748308421b54ad2e3126f8afc7a3b38 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 12 Mar 2021 09:29:15 +0200 Subject: test: give better error messages for file manifests differing This makes it easier to see what the problem is. --- obnam.md | 3 ++- subplot/data.py | 31 +++++++++++++++++++++++++++++++ subplot/data.yaml | 3 +++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/obnam.md b/obnam.md index 6521372..96fca9a 100644 --- a/obnam.md +++ b/obnam.md @@ -1258,12 +1258,13 @@ and a running chunk server and a client config based on metadata.yaml and a file live/data.dat containing some random data and symbolink link live/link that points at data.dat +and symbolink link live/broken that points at does-not-exist and a manifest of the directory live in live.yaml when I run obnam --config metadata.yaml backup then backup generation is GEN when I invoke obnam --config metadata.yaml restore rest given a manifest of the directory live restored in rest in rest.yaml -then files live.yaml and rest.yaml match +then manifests live.yaml and rest.yaml match ~~~ ## Set chunk size diff --git a/subplot/data.py b/subplot/data.py index 8817909..9396215 100644 --- a/subplot/data.py +++ b/subplot/data.py @@ -113,3 +113,34 @@ def match_stdout_to_json_file(ctx, filename=None): if stdout[key] != obj[key]: logging.error(f"stdout value for key is not what was exptected") assert_eq(stdout[key], obj[key]) + + +def manifests_match(ctx, expected=None, actual=None): + assert_eq = globals()["assert_eq"] + assert_dict_eq = globals()["assert_dict_eq"] + + logging.debug(f"comparing manifests {expected} and {actual}") + + expected_objs = list(yaml.safe_load_all(open(expected))) + actual_objs = list(yaml.safe_load_all(open(actual))) + + logging.debug(f"there are {len(expected_objs)} and {len(actual_objs)} objects") + + i = 0 + while expected_objs and actual_objs: + e = expected_objs.pop(0) + a = actual_objs.pop(0) + + logging.debug(f"comparing manifest objects at index {i}:") + logging.debug(f" expected: {e}") + logging.debug(f" actual : {a}") + assert_dict_eq(e, a) + + i += 1 + + logging.debug(f"remaining expected objecvts: {expected_objs}") + logging.debug(f"remaining actual objecvts : {actual_objs}") + assert_eq(expected_objs, []) + assert_eq(actual_objs, []) + + logging.debug(f"manifests {expected} and {actual} match") diff --git a/subplot/data.yaml b/subplot/data.yaml index 0e13abd..64348d6 100644 --- a/subplot/data.yaml +++ b/subplot/data.yaml @@ -36,3 +36,6 @@ - then: "file {filename} is not restored to {restored}" function: file_is_not_restored + +- then: "manifests {expected} and {actual} match" + function: manifests_match -- cgit v1.2.1 From 176442eb1554a674dfa291585abd5eb54aa213d8 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 12 Mar 2021 09:50:39 +0200 Subject: fix: backup and restore of symlink --- src/cmd/restore.rs | 6 ++---- src/fsiter.rs | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/cmd/restore.rs b/src/cmd/restore.rs index cb42114..147c422 100644 --- a/src/cmd/restore.rs +++ b/src/cmd/restore.rs @@ -168,11 +168,9 @@ fn restore_symlink(path: &Path, entry: &FilesystemEntry) -> RestoreResult<()> { debug!(" mkdir {}", parent.display()); if !parent.exists() { std::fs::create_dir_all(parent)?; - { - symlink(path, entry.symlink_target().unwrap())?; - } } - debug!("restored regular {}", path.display()); + symlink(entry.symlink_target().unwrap(), path)?; + debug!("restored symlink {}", path.display()); Ok(()) } diff --git a/src/fsiter.rs b/src/fsiter.rs index f59fb64..57b6fd5 100644 --- a/src/fsiter.rs +++ b/src/fsiter.rs @@ -45,7 +45,7 @@ impl Iterator for FsIterator { fn new_entry(e: &DirEntry) -> FsIterResult { let path = e.path(); - let meta = std::fs::metadata(path); + let meta = std::fs::symlink_metadata(path); debug!("metadata for {:?}: {:?}", path, meta); let meta = match meta { Ok(meta) => meta, -- cgit v1.2.1 From 664636f9f2d5e04e12dbd98aa747247a7e1a3298 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 12 Mar 2021 09:58:39 +0200 Subject: refactor: use new manifest comparison everywhere --- obnam.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/obnam.md b/obnam.md index 96fca9a..bfaff5d 100644 --- a/obnam.md +++ b/obnam.md @@ -1189,7 +1189,7 @@ when I run obnam --config smoke.yaml list then generation list contains when I invoke obnam --config smoke.yaml restore rest given a manifest of the directory live restored in rest in rest.yaml -then files live.yaml and rest.yaml match +then manifests live.yaml and rest.yaml match ~~~ ~~~{#smoke.yaml .file .yaml .numberLines} @@ -1226,7 +1226,7 @@ when I run obnam --config metadata.yaml backup then backup generation is GEN when I invoke obnam --config metadata.yaml restore rest given a manifest of the directory live restored in rest in rest.yaml -then files live.yaml and rest.yaml match +then manifests live.yaml and rest.yaml match ~~~ ### Mode bits @@ -1245,7 +1245,7 @@ when I run obnam --config metadata.yaml backup then backup generation is GEN when I invoke obnam --config metadata.yaml restore rest given a manifest of the directory live restored in rest in rest.yaml -then files live.yaml and rest.yaml match +then manifests live.yaml and rest.yaml match ~~~ ### Symbolic links @@ -1385,7 +1385,7 @@ and a manifest of the directory live in live.yaml when I run obnam --config smoke.yaml backup when I invoke obnam --config smoke.yaml restore latest rest given a manifest of the directory live restored in rest in rest.yaml -then files live.yaml and rest.yaml match +then manifests live.yaml and rest.yaml match ~~~ ## Tricky filenames @@ -1405,7 +1405,7 @@ when I run obnam --config metadata.yaml backup then backup generation is GEN when I invoke obnam --config metadata.yaml restore rest given a manifest of the directory live restored in rest in rest.yaml -then files live.yaml and rest.yaml match +then manifests live.yaml and rest.yaml match ~~~ ## Unreadable file @@ -1450,7 +1450,7 @@ when I run obnam --config metadata.yaml backup when I invoke obnam --config metadata.yaml restore latest rest given a manifest of the directory live restored in rest in rest.yaml -then files second.yaml and rest.yaml match +then manifests second.yaml and rest.yaml match ~~~ ## Back up multiple directories @@ -1472,8 +1472,8 @@ then backup generation is GEN when I invoke obnam --config roots.yaml restore rest given a manifest of the directory live/one restored in rest in rest-one.yaml given a manifest of the directory live/two restored in rest in rest-two.yaml -then files one.yaml and rest-one.yaml match -then files two.yaml and rest-two.yaml match +then manifests one.yaml and rest-one.yaml match +then manifests two.yaml and rest-two.yaml match ~~~ ~~~{#roots.yaml .file .yaml .numberLines} -- cgit v1.2.1