Verified Commit c066a07a authored by Denton Liu's avatar Denton Liu Committed by Daniel M. Capella
Browse files

pacdiff: Don't use $SUDO on temporary files

In 19ab4fac (pacdiff: Add option to use sudo/sudoedit to manage files,
2021-03-27), pacdiff was taught to accept -s to run various commands
with $SUDO. This introduced many instances of $SUDO in merge_file()
where most of them are unnecessary.

In particular, it is not necessary to $SUDO to write the temporary files
as /tmp should be writable by all[0][1].

Also, the usage of sudoedit when comparing the original file with the
merge result is unnecessary. This is because root permissions are not
really required since users should not write to the original file
anyway. The merged file will be used to overwrite the original file at
the end of the function anyway.

Remove these unnecessary usages of $SUDO.

[0]: https://unix.stackexchange.com/a/71625
[1]: https://serverfault.com/a/427290

Signed-off-by: default avatarDenton Liu <liu.denton@gmail.com>
Signed-off-by: Daniel M. Capella's avatarDaniel M. Capella <polyzen@archlinux.org>
parent ea3b36f1
...@@ -117,21 +117,16 @@ merge_file() { ...@@ -117,21 +117,16 @@ merge_file() {
fi fi
basename="$(basename "$file")" basename="$(basename "$file")"
tempdir="$($SUDO mktemp -d --tmpdir "pacdiff-merge-$basename.XXX")" tempdir="$(mktemp -d --tmpdir "pacdiff-merge-$basename.XXX")"
base="$($SUDO mktemp "$tempdir"/"$basename.base.XXX")" base="$(mktemp "$tempdir"/"$basename.base.XXX")"
merged="$($SUDO mktemp "$tempdir"/"$basename.merged.XXX")" merged="$(mktemp "$tempdir"/"$basename.merged.XXX")"
tar -xOf "$base_tar" "${file#/}" | $SUDO tee "$base" > /dev/null tar -xOf "$base_tar" "${file#/}" >"$base"
$SUDO $mergeprog "$file" "$base" "$pacfile" | $SUDO tee "$merged" > /dev/null if $mergeprog "$file" "$base" "$pacfile" >"$merged"; then
if [ "${PIPESTATUS[0]}" -ne "1" ]; then
msg2 "Merged without conflicts." msg2 "Merged without conflicts."
fi fi
if [[ -n "$SUDO" ]]; then $diffprog "$file" "$merged"
SUDO_EDITOR="$diffprog" sudoedit "$file" "$merged"
else
$diffprog "$file" "$merged"
fi
while :; do while :; do
ask "Would you like to use the results of the merge? [y/n] " ask "Would you like to use the results of the merge? [y/n] "
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment