diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-03-12 07:59:49 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-03-12 07:59:49 +0000 |
commit | 95fa88b76a45cf751c3746231105d9de81aa13b2 (patch) | |
tree | 9fd5c8871addbdeeaf60f5f55ed7c9fbd02f103c | |
parent | 2a46a1122938e0ffcf28ded131997a405ad67055 (diff) | |
parent | 664636f9f2d5e04e12dbd98aa747247a7e1a3298 (diff) | |
download | obnam2-95fa88b76a45cf751c3746231105d9de81aa13b2.tar.gz |
Merge branch 'symlink' into 'main'
fix backup and restore of symlinks
Closes #87
See merge request larswirzenius/obnam!113
-rw-r--r-- | obnam.md | 19 | ||||
-rw-r--r-- | src/cmd/restore.rs | 6 | ||||
-rw-r--r-- | src/fsiter.rs | 2 | ||||
-rw-r--r-- | subplot/data.py | 33 | ||||
-rw-r--r-- | subplot/data.yaml | 3 |
5 files changed, 48 insertions, 15 deletions
@@ -1189,7 +1189,7 @@ when I run obnam --config smoke.yaml list then generation list contains <GEN> when I invoke obnam --config smoke.yaml restore <GEN> 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 <GEN> 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 <GEN> 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 @@ -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 <GEN> 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 @@ -1384,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 @@ -1404,7 +1405,7 @@ when I run obnam --config metadata.yaml backup then backup generation is GEN when I invoke obnam --config metadata.yaml restore <GEN> 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 @@ -1449,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 @@ -1471,8 +1472,8 @@ then backup generation is GEN when I invoke obnam --config roots.yaml restore <GEN> 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} 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<FilesystemEntry> { 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, diff --git a/subplot/data.py b/subplot/data.py index 0c1a4a5..9396215 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): @@ -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 |