mirror of
https://github.com/TheLocehiliosan/yadm
synced 2024-10-27 20:34:27 +00:00
Ensure base directories for alternates before creation
This commit is contained in:
parent
6d5467951a
commit
f3249e00b5
@ -235,6 +235,22 @@ def test_template_overwrite_symlink(runner, yadm_y, paths, tst_sys):
|
|||||||
assert link.read().strip() == 'test-data'
|
assert link.read().strip() == 'test-data'
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures('ds1_copy')
|
||||||
|
@pytest.mark.parametrize('style', ['symlink', 'template'])
|
||||||
|
def test_ensure_alt_path(runner, paths, style):
|
||||||
|
"""Test that directories are created before making alternates"""
|
||||||
|
yadm_dir = setup_standard_yadm_dir(paths)
|
||||||
|
suffix = 'default' if style == 'symlink' else 'template'
|
||||||
|
filename = 'a/b/c/file'
|
||||||
|
source = yadm_dir.join(f'alt/{filename}##{suffix}')
|
||||||
|
source.write('test-data', ensure=True)
|
||||||
|
run = runner([paths.pgm, '-Y', yadm_dir, 'add', source])
|
||||||
|
assert run.success
|
||||||
|
assert run.err == ''
|
||||||
|
assert run.out == ''
|
||||||
|
assert paths.work.join(filename).read().strip() == 'test-data'
|
||||||
|
|
||||||
|
|
||||||
def setup_standard_yadm_dir(paths):
|
def setup_standard_yadm_dir(paths):
|
||||||
"""Configure a yadm home within the work tree"""
|
"""Configure a yadm home within the work tree"""
|
||||||
std_yadm_dir = paths.work.mkdir('.config').mkdir('yadm')
|
std_yadm_dir = paths.work.mkdir('.config').mkdir('yadm')
|
||||||
|
5
yadm
5
yadm
@ -505,10 +505,13 @@ function alt_future_linking() {
|
|||||||
filename="${alt_filenames[$index]}"
|
filename="${alt_filenames[$index]}"
|
||||||
target="${alt_targets[$index]}"
|
target="${alt_targets[$index]}"
|
||||||
template_cmd="${alt_template_cmds[$index]}"
|
template_cmd="${alt_template_cmds[$index]}"
|
||||||
|
basedir=${filename%/*}
|
||||||
if [ -n "$template_cmd" ]; then
|
if [ -n "$template_cmd" ]; then
|
||||||
# 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"
|
||||||
|
# ensure the destination path exists
|
||||||
|
[ -e "$basedir" ] || mkdir -p "$basedir"
|
||||||
# remove any existing symlink before processing template
|
# remove any existing symlink before processing template
|
||||||
[ -L "$filename" ] && rm -f "$filename"
|
[ -L "$filename" ] && rm -f "$filename"
|
||||||
"$template_cmd" "$target" "$filename"
|
"$template_cmd" "$target" "$filename"
|
||||||
@ -516,6 +519,8 @@ function alt_future_linking() {
|
|||||||
# 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"
|
||||||
|
# ensure the destination path exists
|
||||||
|
[ -e "$basedir" ] || mkdir -p "$basedir"
|
||||||
if [ "$do_copy" -eq 1 ]; then
|
if [ "$do_copy" -eq 1 ]; then
|
||||||
# remove any existing symlink before copying
|
# remove any existing symlink before copying
|
||||||
[ -L "$filename" ] && rm -f "$filename"
|
[ -L "$filename" ] && rm -f "$filename"
|
||||||
|
Loading…
Reference in New Issue
Block a user