From patchwork Mon Mar 29 09:02:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 1892 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); Mon, 29 Mar 2021 09:28:47 +0000 (UTC) Received: from mail.archlinux.org by mail.archlinux.org with LMTP id SF3lC86dYWAgHgEAK+/4rw (envelope-from ) for ; Mon, 29 Mar 2021 09:28:46 +0000 Received: from luna.archlinux.org (luna.archlinux.org [5.9.250.164]) (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 EBF484B8C31; Mon, 29 Mar 2021 09:28:45 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 88E4C2C7B5; Mon, 29 Mar 2021 09:28:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lists.archlinux.org; s=luna; t=1617010123; bh=r5MRa5folgXi1sBuhwb6xAvu3buS6PRqBGrwPezuWT8=; 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=LL50XJExWgfhZLe/Qc6NxNRWue8Iecfi5aa8aKgLzVnMBpRWKb/ItR3MGl8JN8Egr Gff+999/3nb1z1Gufc3MN4sDTZycHg/XwRBHHZVrX6yf1w+aZYlQmxG3rCLJju0UBG bbkZtHmHGn+aAxQFg6nqZn/IxRyisbbE3eHoGB3xHFeHJWJaSv6LbZ1o/QWkJ7C4Mf MSEeCtMs17j2dv8TVHaLMR6ED8y/za56FAhD3qqcpPdjdtKtH7qf52dzBHOE2F9D73 20s94h2Zr98Rji9BcIN8Zk6QlaNBEOkn3y+J8JSpmpZScCXl5I9jKQkamd387pxGgH 3HQeD1th58WNWYnUFeLs7dbdzEO1EPj19S+wmMDtf7ucLpCUFZ+zI0Fw/02hZzFCbu nAB8GprchC/3sbFexpuXZzEKVFvENODpJjzN6/7BP3o0spdRAk/uDREK6BiUwoYwKw 2wAPFLK5tgiiqdhR08sXFz9YKsmzfzpzZA2Jnmjs3wgKF24HiyBcwhVNTzUSUmlxA9 /s/D4XuhWuLdGDDLVomNSROen89fsPuFp34N69dNNf5oQCB+/G8ofuY/Ey5gSC8GYA xFQI6mvnqe4HQ7yvo/RM2VffLs2mWyc4TE1BPo++wRwVU8ulOE9v6HwYnWjK37KCl2 5ZGZIIlNV5+2rl+7rICgr+pc= Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id CF4572C61B for ; Mon, 29 Mar 2021 09:03:08 +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-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by luna.archlinux.org (Postfix) with ESMTPS for ; Mon, 29 Mar 2021 09:03:08 +0000 (UTC) Received: by mail-pl1-x633.google.com with SMTP id t20so4083001plr.13 for ; Mon, 29 Mar 2021 02:03:08 -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:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ykJ20mV45avKOI6cBtutBcJtmsM8oH1SKKsug6Or0AM=; b=QXcO5QnnAgn2+G1CG0QwyMPVSv1kGK2l8S3/8tu3EvSHkHlSnn6zyfpGnqg1LYClzJ yA4Beu707uksZA6NzJM7iJvzxHB145ZD8hKClcnMsvzc+yNNjUPUak4KAwVHPEyP2Nn3 gadHWhs5UMcCncjyGK9BT9WdoA4fm1+lWi2HMOfCm8UFwMXWKvBx+jfxxQGrzcUx0n2f w3nqXrfNIrk5O8G9qZ0377x4SljzYbXEVxCdrkSWcI3Ri4As7FLAjnUyZwbXwP3GXnPQ FdcggO9SDVBGi+7XnQJqp4yEzKfDqBn3ucj7Bss3YJ/IwVwJfPfyNG17yFwXrWjslRo3 e2ow== X-Gm-Message-State: AOAM530uu+ePNKSbOK2f20GjtzXukh8pa2EtacfQUGhJ33LUGiOHs5fu kxCwPCew9bdQdfD/+JYbx1CIiic135k= X-Google-Smtp-Source: ABdhPJxplikpK1JwnCePNwWmOnJjXney8oiYD9qgIE6SLS/7CW2GMsfoPXwX0VpZxkCg7/TiNr/gGA== X-Received: by 2002:a17:90b:4c0a:: with SMTP id na10mr26731247pjb.227.1617008586773; Mon, 29 Mar 2021 02:03:06 -0700 (PDT) Received: from archbookpro.localdomain ([172.92.165.181]) by smtp.gmail.com with ESMTPSA id h68sm16122545pfe.111.2021.03.29.02.03.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Mar 2021 02:03:06 -0700 (PDT) To: pacman-contrib@lists.archlinux.org Subject: [PATCH 4/4] pacdiff: Don't use $SUDO on temporary files Date: Mon, 29 Mar 2021 02:02:43 -0700 Message-Id: <32bb4a1978c52eb0bbc1a984f8ea9f9e9eccd1a4.1617008556.git.liu.denton@gmail.com> 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=LL50XJEx; dmarc=pass (policy=none) header.from=archlinux.org; spf=pass (mail.archlinux.org: domain of pacman-contrib-bounces@lists.archlinux.org designates 5.9.250.164 as permitted sender) smtp.mailfrom=pacman-contrib-bounces@lists.archlinux.org X-Rspamd-Queue-Id: EBF484B8C31 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_SPF_ALLOW(-0.20)[+ip4:5.9.250.164:c]; R_MISSING_CHARSET(2.50)[]; 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:5.9.0.0/16, country:DE]; FROM_NEQ_ENVFROM(0.00)[pacman-contrib@lists.archlinux.org,pacman-contrib-bounces@lists.archlinux.org]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[lists.archlinux.org:s=luna]; RCVD_COUNT_FIVE(0.00)[6]; 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 From: Denton Liu via pacman-contrib 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. 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. Remove these unnecessary usages of $SUDO. Signed-off-by: Denton Liu --- src/pacdiff.sh.in | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/pacdiff.sh.in b/src/pacdiff.sh.in index fe66a6e..3c34fdb 100644 --- a/src/pacdiff.sh.in +++ b/src/pacdiff.sh.in @@ -117,20 +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 - if $SUDO $mergeprog "$file" "$base" "$pacfile" | $SUDO tee "$merged" > /dev/null; 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] "