TT#17401 Fail if destination file matches an existing directory

If a template named
/etc/ngcp-config/templates/etc/apt/apt.conf.d/71_no_recommended.tt2 exists
the resulting destination file would be
/etc/apt/apt.conf.d/71_no_recommended.  Though if
/etc/apt/apt.conf.d/71_no_recommended exists as directory ngcpcfg should
abort and inform the user about the existing situation with a useful error
message.

Change-Id: I2c6e1e3a4ec485183674c1fe72251631ad9867ac
changes/06/13806/2
Michael Prokop 9 years ago
parent 1acab57856
commit 0441810530

@ -44,6 +44,12 @@ else
fi
# }}}
# ensure we don't try to generate a file where a directory with same name exists already
if [ -d "${output_file}" ] ; then
log_error "Generating file ${output_file} not possible, it's an existing directory." >&2
exit 1
fi
# pre-execution script in template store:
if [ -r "${NGCPCTL_MAIN}/templates/${output_file}.prebuild" ] ; then
log_info "Executing prebuild for ${output_file}"

@ -1,5 +1,6 @@
#!/usr/bin/env py.test-3
import os
import pytest
import re
import tempfile
@ -35,3 +36,20 @@ def test_simple_build_template_ok(ngcpcfgcli):
tmpdir +
r"//etc/apt/apt.conf.d/71_no_recommended: OK")
assert re.search(regex, out.stdout)
@pytest.mark.tt_17401
def test_fail_on_existing_dir_matching_output_filename(ngcpcfgcli, tmpdir):
tmpdir = tempfile.mkdtemp(prefix='ngcp-', suffix='-pytest-output')
output = "/etc/apt/apt.conf.d/71_no_recommended"
os.makedirs(tmpdir + output)
out = ngcpcfgcli("build", "--ignore-branch-check", output,
env={
'NGCP_PORTFILE': '/tmp/ngcpcfg.port',
'OUTPUT_DIRECTORY': tmpdir,
})
regex = re.compile("Error: Generating file " +
tmpdir + "/" + output +
r" not possible, it\'s an existing directory.")
assert re.search(regex, out.stderr)
assert out.returncode == 1

Loading…
Cancel
Save