1
0
mirror of https://github.com/TheLocehiliosan/yadm synced 2026-03-02 03:49:29 +00:00

Don't always run auto-alt (and -perms) after invoking git command

Improve performance (#505) by only running auto-alt (and auto-perms)
when HEAD has changed after calling a git command, e.g. after committing
or pulling new changes.

Also use this new information to remove stale symlinks when an alt file
has been removed.
This commit is contained in:
Erik Flodin
2025-04-06 08:58:40 +02:00
parent bbb58e6625
commit 66e509d2e4
5 changed files with 81 additions and 27 deletions

View File

@@ -248,7 +248,12 @@ def test_auto_alt(runner, yadm_cmd, paths, autoalt):
os.system(" ".join(yadm_cmd("config", "yadm.auto-alt", autoalt)))
utils.create_alt_files(paths, "##default")
run = runner(yadm_cmd("status"))
# Add and commit a file to trigger auto alt
paths.work.join("somefile").write("somedata")
runner(yadm_cmd("add", "somefile"), report=False)
run = runner(yadm_cmd("commit", "-m", "msg"))
assert run.success
assert run.err == ""
linked = utils.parse_alt_output(run.out)
@@ -353,6 +358,26 @@ def test_stale_link_removal(runner, yadm_cmd, paths):
assert str(source_file) not in linked
@pytest.mark.usefixtures("ds1_copy")
def test_deleted_file_link_removal(runner, yadm_cmd, paths):
"""Link to deleted file is removed"""
utils.create_alt_files(paths, "##default")
run = runner(yadm_cmd("alt", "-d"))
assert run.success
# Remove one alt file
run = runner(yadm_cmd("rm", TEST_PATHS[0] + "##default"))
assert run.success
run = runner(yadm_cmd("commit", "-m", "remove"))
assert run.success
# And verify that the symlink has been removed
link_file = paths.work.join(TEST_PATHS[0])
with pytest.raises(OSError):
link_file.lstat()
@pytest.mark.usefixtures("ds1_copy")
def test_legacy_dir_link_removal(runner, yadm_cmd, paths):
"""Legacy link to alternative dir is removed
@@ -414,6 +439,8 @@ def test_template_overwrite_symlink(runner, yadm_cmd, paths, tst_sys):
assert run.success
assert run.err == ""
assert run.out == ""
run = runner(yadm_cmd("commit", "-m", "msg"))
assert run.success
assert not link.islink()
assert target.read().strip() == "target"
assert link.read().strip() == "test-data"
@@ -432,6 +459,8 @@ def test_ensure_alt_path(runner, paths, style):
assert run.success
assert run.err == ""
assert run.out == ""
run = runner([paths.pgm, "-Y", yadm_dir, "--yadm-data", yadm_data, "commit", "-m", "msg"])
assert run.success
assert paths.work.join(filename).read().strip() == "test-data"

View File

@@ -32,12 +32,12 @@ def test_config_read_missing(runner, yadm_cmd):
"""Read missing attribute
Display an empty value
Exit with 0
Exit with 1
"""
run = runner(yadm_cmd("config", TEST_KEY))
assert run.success
assert not run.success
assert run.err == ""
assert run.out == ""

View File

@@ -35,13 +35,15 @@ def test_perms(runner, yadm_cmd, paths, ds1, autoperms):
for private in privatepaths + insecurepaths:
assert not oct(private.stat().mode).endswith("00"), "Path started secured"
cmd = "perms"
cmd = ["perms"]
if autoperms != "notest":
cmd = "status"
run = runner(yadm_cmd(cmd), env={"HOME": paths.work})
run = runner(yadm_cmd("add", "efile1"), report=False)
assert run.success
cmd = ["-c", "user.name=Yadm", "commit", "-m", "msg"]
run = runner(yadm_cmd(*cmd), env={"HOME": paths.work})
assert run.success
assert run.err == ""
if cmd == "perms":
if autoperms == "notest":
assert run.out == ""
# these paths should be secured if processing perms

View File

@@ -22,7 +22,7 @@ def test_report_invalid_alts(runner, yadm, valid, previous):
report_invalid_alts
"""
run = runner(command=["bash"], inp=script)
assert run.success
assert run.success == (valid and not previous)
assert run.out == ""
if not valid and not previous:
assert "WARNING" in run.err