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.


Signed-off-by: default avatarDenton Liu <>
Signed-off-by: Daniel M. Capella's avatarDaniel M. Capella <>
parent ea3b36f1
......@@ -117,21 +117,16 @@ merge_file() {
basename="$(basename "$file")"
tempdir="$($SUDO mktemp -d --tmpdir "pacdiff-merge-$basename.XXX")"
base="$($SUDO mktemp "$tempdir"/"$basename.base.XXX")"
merged="$($SUDO mktemp "$tempdir"/"$basename.merged.XXX")"
tempdir="$(mktemp -d --tmpdir "pacdiff-merge-$basename.XXX")"
base="$(mktemp "$tempdir"/"$basename.base.XXX")"
merged="$(mktemp "$tempdir"/"$basename.merged.XXX")"
tar -xOf "$base_tar" "${file#/}" | $SUDO tee "$base" > /dev/null
$SUDO $mergeprog "$file" "$base" "$pacfile" | $SUDO tee "$merged" > /dev/null
if [ "${PIPESTATUS[0]}" -ne "1" ]; then
tar -xOf "$base_tar" "${file#/}" >"$base"
if $mergeprog "$file" "$base" "$pacfile" >"$merged"; then
msg2 "Merged without conflicts."
if [[ -n "$SUDO" ]]; then
SUDO_EDITOR="$diffprog" sudoedit "$file" "$merged"
$diffprog "$file" "$merged"
$diffprog "$file" "$merged"
while :; do
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