Adjust special handling of existing read-only output files
Instead of duplicating the permissions on the temp file, the permissions are duplicated on the output file directly. If the output file exists as read-only, it is made writeable first. There are some environments which don't allow the mv to work if the file itself is read-only.
This commit is contained in:
parent
39773765ab
commit
216aed2f87
4 changed files with 25 additions and 12 deletions
|
@ -127,6 +127,12 @@ def test_template_default(runner, yadm, tmpdir):
|
|||
input_file.chmod(FILE_MODE)
|
||||
output_file = tmpdir.join('output')
|
||||
|
||||
# ensure overwrite works when file exists as read-only (there is some
|
||||
# special processing when this is encountered because some environments do
|
||||
# not properly overwrite read-only files)
|
||||
output_file.write('existing')
|
||||
output_file.chmod(0o400)
|
||||
|
||||
script = f"""
|
||||
YADM_TEST=1 source {yadm}
|
||||
set_awk
|
||||
|
|
|
@ -86,6 +86,12 @@ def test_template_esh(runner, yadm, tmpdir):
|
|||
input_file.chmod(FILE_MODE)
|
||||
output_file = tmpdir.join('output')
|
||||
|
||||
# ensure overwrite works when file exists as read-only (there is some
|
||||
# special processing when this is encountered because some environments do
|
||||
# not properly overwrite read-only files)
|
||||
output_file.write('existing')
|
||||
output_file.chmod(0o400)
|
||||
|
||||
script = f"""
|
||||
YADM_TEST=1 source {yadm}
|
||||
local_class="{LOCAL_CLASS}"
|
||||
|
|
|
@ -88,6 +88,12 @@ def test_template_j2(runner, yadm, tmpdir, processor):
|
|||
input_file.chmod(FILE_MODE)
|
||||
output_file = tmpdir.join('output')
|
||||
|
||||
# ensure overwrite works when file exists as read-only (there is some
|
||||
# special processing when this is encountered because some environments do
|
||||
# not properly overwrite read-only files)
|
||||
output_file.write('existing')
|
||||
output_file.chmod(0o400)
|
||||
|
||||
script = f"""
|
||||
YADM_TEST=1 source {yadm}
|
||||
local_class="{LOCAL_CLASS}"
|
||||
|
|
19
yadm
19
yadm
|
@ -489,20 +489,15 @@ function move_file() {
|
|||
local output=$2
|
||||
local temp_file=$3
|
||||
|
||||
if [ ! -f "$temp_file" ] ; then
|
||||
return 0
|
||||
fi
|
||||
[ ! -f "$temp_file" ] && return
|
||||
|
||||
# if the output files already exists as read-only, change it to be writable.
|
||||
# there are some environments in which a read-only file will prevent the move
|
||||
# from being successful.
|
||||
[[ -e "$output" && ! -w "$output" ]] && chmod u+w "$output"
|
||||
|
||||
local read_only
|
||||
copy_perms "$input" "$temp_file"
|
||||
if [[ -e "$output" && ! -w "$output" ]]; then
|
||||
read_only=1
|
||||
chmod u+w "$output"
|
||||
fi
|
||||
mv -f "$temp_file" "$output"
|
||||
if [ -n "$read_only" ]; then
|
||||
chmod u-w "$output"
|
||||
fi
|
||||
copy_perms "$input" "$output"
|
||||
}
|
||||
|
||||
# ****** yadm Commands ******
|
||||
|
|
Loading…
Reference in a new issue