Skip to content

Commit

Permalink
file-install modules: Don't destroy original before we know we have a…
Browse files Browse the repository at this point in the history
… backup.

This was revealed by the `test_file_update_module` in integration,
which puts a file in the way of the directory. If it fails that early,
we should not delete the original, since we never created a backup.

More commonly, this problem would happen if there was no space for the
backup, which would obviously be disastrous. So also make sure we have
a *complete* backup.

Changelog: Title

Signed-off-by: Kristian Amlie <kristian.amlie@northern.tech>
  • Loading branch information
kacf committed Apr 16, 2019
1 parent db01aab commit 44b1f48
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
10 changes: 8 additions & 2 deletions support/modules/file-tree-install
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,27 @@ case "$STATE" in
test "$dest_dir" = "/" && \
echo "Error: destination dir is '/', install not supported." && exit 1
mkdir -p $dest_dir
tar -cf ${prev_files_tar} -C ${dest_dir} .
if ! tar -cf ${prev_files_tar} -C ${dest_dir} .
then
ret=$?
# Make sure there is no half-backup lying around.
rm -f ${prev_files_tar}
exit $ret
fi
rm -rf ${dest_dir}
mkdir -p ${dest_dir}
tar -xf ${update_files_tar} -C ${dest_dir}
;;

ArtifactRollback)
test -f $prev_files_tar || exit 0
dest_dir=$(cat $dest_dir_file)
test -z "$dest_dir" && \
echo "Fatal error: dest_dir is undefined." && exit 1
test "$dest_dir" = "/" && \
echo "Info: destination dir is '/', not performing rollback." && exit 0
rm -rf ${dest_dir}
mkdir -p ${dest_dir}
test -f $prev_files_tar || exit 0
tar -xf ${prev_files_tar} -C ${dest_dir}
;;
esac
Expand Down
13 changes: 11 additions & 2 deletions support/modules/single-file-install
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,26 @@ case "$STATE" in
echo "Fatal error: dest_dir or filename are undefined." && exit 1
mkdir -p $dest_dir
mkdir -p $tmp_dest_dir
test -f ${dest_dir}/${filename} && cp ${dest_dir}/${filename} ${tmp_dest_dir}
if test -f ${dest_dir}/${filename}
then
if ! cp ${dest_dir}/${filename} ${tmp_dest_dir}
then
ret=$?
# Make sure there is no half-backup lying around.
rm -rf ${tmp_dest_dir}
exit $ret
fi
fi
cp "$FILES"/files/$filename ${dest_dir}/${filename}
;;

ArtifactRollback)
test -f $tmp_dest_dir/$filename || exit 0
dest_dir=$(cat $dest_dir_file)
filename=$(cat $filename_file)
test -z "$dest_dir" -o -z "$filename" && \
echo "Fatal error: dest_dir or filename are undefined." && exit 1
rm ${dest_dir}/${filename}
test -f $tmp_dest_dir/$filename || exit 0
cp $tmp_dest_dir/$filename ${dest_dir}/${filename}
;;
esac
Expand Down

0 comments on commit 44b1f48

Please sign in to comment.