mirror of
https://github.com/TheLocehiliosan/yadm
synced 2024-10-27 20:34:27 +00:00
Remove symlinks before processing a template
This commit is contained in:
parent
117541fd21
commit
3a192db420
@ -193,3 +193,30 @@ def test_stale_link_removal(runner, yadm_y, paths):
|
|||||||
source_file = stale_path + '##class.' + tst_class
|
source_file = stale_path + '##class.' + tst_class
|
||||||
assert not paths.work.join(stale_path).exists()
|
assert not paths.work.join(stale_path).exists()
|
||||||
assert str(paths.work.join(source_file)) not in linked
|
assert str(paths.work.join(source_file)) not in linked
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures('ds1_repo_copy')
|
||||||
|
def test_template_overwrite_symlink(runner, yadm_y, paths, tst_sys):
|
||||||
|
"""Remove symlinks before processing a template
|
||||||
|
|
||||||
|
If a symlink is in the way of the output of a template, the target of the
|
||||||
|
symlink will get the template content. To prevent this, the symlink should
|
||||||
|
be removed just before processing a template.
|
||||||
|
"""
|
||||||
|
|
||||||
|
target = paths.work.join(f'test_link##os.{tst_sys}')
|
||||||
|
target.write('target')
|
||||||
|
|
||||||
|
link = paths.work.join('test_link')
|
||||||
|
link.mksymlinkto(target, absolute=1)
|
||||||
|
|
||||||
|
template = paths.work.join('test_link##template.builtin')
|
||||||
|
template.write('test-data')
|
||||||
|
|
||||||
|
run = runner(yadm_y('add', target, template))
|
||||||
|
assert run.success
|
||||||
|
assert run.err == ''
|
||||||
|
assert run.out == ''
|
||||||
|
assert not link.islink()
|
||||||
|
assert target.read().strip() == 'target'
|
||||||
|
assert link.read().strip() == 'test-data'
|
||||||
|
7
yadm
7
yadm
@ -498,15 +498,16 @@ function alt_future_linking() {
|
|||||||
# a template is defined, process the template
|
# a template is defined, process the template
|
||||||
debug "Creating $filename from template $target"
|
debug "Creating $filename from template $target"
|
||||||
[ -n "$loud" ] && echo "Creating $filename from template $target"
|
[ -n "$loud" ] && echo "Creating $filename from template $target"
|
||||||
|
# remove any existing symlink before processing template
|
||||||
|
[ -L "$filename" ] && rm -f "$filename"
|
||||||
"$template_cmd" "$target" "$filename"
|
"$template_cmd" "$target" "$filename"
|
||||||
elif [ -n "$target" ]; then
|
elif [ -n "$target" ]; then
|
||||||
# a link target is defined, create symlink
|
# a link target is defined, create symlink
|
||||||
debug "Linking $target to $filename"
|
debug "Linking $target to $filename"
|
||||||
[ -n "$loud" ] && echo "Linking $target to $filename"
|
[ -n "$loud" ] && echo "Linking $target to $filename"
|
||||||
if [ "$do_copy" -eq 1 ]; then
|
if [ "$do_copy" -eq 1 ]; then
|
||||||
if [ -L "$filename" ]; then
|
# remove any existing symlink before copying
|
||||||
rm -f "$filename"
|
[ -L "$filename" ] && rm -f "$filename"
|
||||||
fi
|
|
||||||
cp -f "$target" "$filename"
|
cp -f "$target" "$filename"
|
||||||
else
|
else
|
||||||
ln -nfs "$target" "$filename"
|
ln -nfs "$target" "$filename"
|
||||||
|
Loading…
Reference in New Issue
Block a user