From patchwork Fri Apr 2 03:46:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 1893 Return-Path: Delivered-To: patchwork@archlinux.org Received: from mail.archlinux.org [95.216.189.61] by patchwork.archlinux.org with IMAP (fetchmail-6.4.17) for (single-drop); Fri, 02 Apr 2021 03:46:42 +0000 (UTC) Received: from mail.archlinux.org by mail.archlinux.org with LMTP id VSg9HKGTZmAT4gIAK+/4rw (envelope-from ) for ; Fri, 02 Apr 2021 03:46:41 +0000 Received: from luna.archlinux.org (luna.archlinux.org [IPv6:2a01:4f8:160:3033::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits)) (No client certificate requested) by mail.archlinux.org (Postfix) with ESMTPS id D36244C6417; Fri, 2 Apr 2021 03:46:40 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 74D552B63E; Fri, 2 Apr 2021 03:46:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lists.archlinux.org; s=luna; t=1617335200; bh=mJIFrq6u/QrOr2CklzEYzP/pjpOI0BHzTXUdQqEh6UY=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc; b=Sj4pxgk0H7g/rSJ1HH51tP542t5Ya/fMVhXKgzzdGqop6H4yOtdLz507KwvRsdRvA XzO+lSVVC3/Hr7DUgnhMpaKwzF2RgAxu8NvzeVjJyLOc9vIqg/zhGbauQ7fT/Lbz1J 8N/i2cXeidtJkUIIL1Q4UVK+Mw//8aMUXNVXPAlPL6SRlwtHfufTDo+zA5CBIjxEuC R5bHwyLUq+74ZRDe1WL+dFM7jYzCUdGTMtnhdss/1kS0WkxOBvqIg8PFmF8ex2BqHX EojVvAlSNTP7/bVjPjZU3ZX+NRFfQ+orS6b0CMxCDiC0F2MvxqH4bxgaf4uFWtNjXU cit+Yl6KiyGYGMwK4WRFfc45NLPEyNujE+06RQZe5W/x/O24xtO1bN9xMGhJaDIKLg DTLeFqsispderHu8xiefdHM99VDZb9Vep10mq0ZJHcVa1fM16tFf0YcbmSX8CocUmx mFl8KOIa2GFtTxIrElBAG3Hb9EJygY17iOya3Rh0ts4GQO5ckHaNumw1/dQj4oFpyL QgT1vIs55L+LF1fUHjK/DOmqIh8eUm/Ew8EXttf/tCnVRnr+fDOz04BJEeM51yj3P4 d3JaAe4/bsqYwvyNU1+hiCv65xfyoxu/ZBbQzQjiFUxNBDXO6KOF6pB/vv9nFPaNm2 ECEtCP62KejyzmVZE+9ERaVg= Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id BC05D2B63D for ; Fri, 2 Apr 2021 03:46:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on luna.archlinux.org X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=DKIM_SIGNED=0.1, DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,FREEMAIL_FROM=0.5, RCVD_IN_DNSWL_NONE=-0.0001,SPF_HELO_NONE=0.001, T_DMARC_POLICY_NONE=0.01,T_DMARC_SIMPLE_DKIM=0.01 autolearn=no autolearn_force=no version=3.4.4 X-Spam-BL-Results: [127.0.5.0] Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by luna.archlinux.org (Postfix) with ESMTPS for ; Fri, 2 Apr 2021 03:46:35 +0000 (UTC) Received: by mail-pj1-x102c.google.com with SMTP id k23-20020a17090a5917b02901043e35ad4aso4058058pji.3 for ; Thu, 01 Apr 2021 20:46:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qRG2zWvpy8S/k/1J2WMqdIuwDE/ddBuzWAW1dEfYoLg=; b=k4u5ai8A+QPEF4PSAKvYFM4xbJrJeAv4YB2PJe8yZTfehOBtZY4bawoxop4jFWAupZ jOgIAXlpJtDzgDTrnlmvaZbAwrA1WIQat/kqUSZuw0Pd0V42lY1yfiTc6r4NIsFSEcG9 mLzBPVknM0tmhoSRhhY21m7fshrtfitcncuCrxgpaCMCNv9O16Qzy83efOKq2IaV/AFG S1qxkQXGzr8j9e0gerBavLSB/z/ylxHTpVQavtQv/IdMhHHbsq7iUeXhYAzejutQvMT1 GoUJvtH9A9cfpYsqdLnfYd1zKwzJP7YAi1fqq0nXSThnr1jsxq4HLLZ3IG4vtLgUEuyz cGCw== X-Gm-Message-State: AOAM530pVKD2XhKSyORiK9YFKFUE7o0PQrUHzWsy+AnNcoVwfCxtgbtw ojYIe/ta8+NiJ6p4X/RwKb7YxCsYDkQ= X-Google-Smtp-Source: ABdhPJyTzQdnTgrvU4e0cENJRqChgWVYq2AaR4wRw/6MjOIeGOLnYQy5NpuX0LoleZWJOpbA3DffPw== X-Received: by 2002:a17:903:2284:b029:e7:1490:9c60 with SMTP id b4-20020a1709032284b02900e714909c60mr10950843plh.62.1617335192412; Thu, 01 Apr 2021 20:46:32 -0700 (PDT) Received: from archbookpro.localdomain ([172.92.165.181]) by smtp.gmail.com with ESMTPSA id 202sm6660891pfu.46.2021.04.01.20.46.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Apr 2021 20:46:31 -0700 (PDT) To: pacman-contrib@lists.archlinux.org Subject: [PATCH v2] pacdiff: Don't use $SUDO on temporary files Date: Thu, 1 Apr 2021 20:46:21 -0700 Message-Id: X-Mailer: git-send-email 2.31.0.208.g409f899ff0 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: pacman-contrib@lists.archlinux.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Discussion list for pacman-contrib development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Denton Liu via pacman-contrib From: Denton Liu Reply-To: Discussion list for pacman-contrib development Cc: Denton Liu Errors-To: pacman-contrib-bounces@lists.archlinux.org Sender: "pacman-contrib" Authentication-Results: mail.archlinux.org; dkim=pass header.d=lists.archlinux.org header.s=luna header.b=Sj4pxgk0; dmarc=pass (policy=none) header.from=archlinux.org; spf=pass (mail.archlinux.org: domain of pacman-contrib-bounces@lists.archlinux.org designates 2a01:4f8:160:3033::2 as permitted sender) smtp.mailfrom=pacman-contrib-bounces@lists.archlinux.org X-Rspamd-Queue-Id: D36244C6417 X-Spamd-Result: default: False [3.79 / 15.00]; HAS_REPLYTO(0.00)[pacman-contrib@lists.archlinux.org]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; R_SPF_ALLOW(-0.20)[+ip6:2a01:4f8:160:3033::2]; REPLYTO_ADDR_EQ_FROM(0.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; SUBJECT_HAS_CURRENCY(1.00)[]; DKIM_TRACE(0.00)[lists.archlinux.org:+]; RCPT_COUNT_TWO(0.00)[2]; DMARC_POLICY_ALLOW(-0.50)[archlinux.org,none]; MAILLIST(-0.20)[mailman]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:24940, ipnet:2a01:4f8::/29, country:DE]; FROM_NEQ_ENVFROM(0.00)[pacman-contrib@lists.archlinux.org,pacman-contrib-bounces@lists.archlinux.org]; ARC_NA(0.00)[]; RCVD_COUNT_FIVE(0.00)[6]; R_DKIM_ALLOW(-0.20)[lists.archlinux.org:s=luna]; FROM_HAS_DN(0.00)[]; TAGGED_RCPT(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[pacman-contrib@lists.archlinux.org]; MIME_GOOD(-0.10)[text/plain]; HAS_LIST_UNSUB(-0.01)[]; NEURAL_HAM(-0.00)[-1.000]; FREEMAIL_CC(0.00)[gmail.com]; FORGED_SENDER_MAILLIST(0.00)[] X-Rspamd-Server: mail.archlinux.org In 19ab4fa (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: Denton Liu --- Range-diff against v1: 1: ab12657 < -: ------- .mailmap: Map Daniel Parks 2: 9287d4e < -: ------- .mailmap: Map Denton Liu 3: 636e0fb < -: ------- pacdiff: update --sudo usages 4: 32bb4a1 ! 1: ad45bdd pacdiff: Don't use $SUDO on temporary files @@ Commit message 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. + as /tmp should be writable by all[0][1]. - Also, remove the usage of sudoedit when comparing the original file with - the merge result. This is because the merged file is placed in a - writable directory. Attempting to run sudoedit on this file results in - the following error: - - sudoedit: : editing files in a writable directory is not permitted - - but 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. + 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 + ## src/pacdiff.sh.in ## @@ src/pacdiff.sh.in: merge_file() { fi @@ src/pacdiff.sh.in: merge_file() { + merged="$(mktemp "$tempdir"/"$basename.merged.XXX")" - tar -xOf "$base_tar" "${file#/}" | $SUDO tee "$base" > /dev/null -- if $SUDO $mergeprog "$file" "$base" "$pacfile" | $SUDO tee "$merged" > /dev/null; then +- $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." src/pacdiff.sh.in | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/pacdiff.sh.in b/src/pacdiff.sh.in index 5af7e1c..3c34fdb 100644 --- a/src/pacdiff.sh.in +++ b/src/pacdiff.sh.in @@ -117,21 +117,16 @@ merge_file() { fi 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." fi - if [[ -n "$SUDO" ]]; then - SUDO_EDITOR="$diffprog" sudoedit "$file" "$merged" - else - $diffprog "$file" "$merged" - fi + $diffprog "$file" "$merged" while :; do ask "Would you like to use the results of the merge? [y/n] "