From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.bugs Subject: bug#50581: 27.2.50; Tramp fails to (un)compress directories Date: Sun, 19 Sep 2021 18:50:38 +0200 Message-ID: <87wnnc7bmp.fsf@calancha-pc.dy.bbexcite.jp> References: <87o88vco8a.fsf@gmail.com> <87sfy7ov5m.fsf@gmx.de> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3803"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: uyennhi.qm@gmail.com, 50581@debbugs.gnu.org To: Michael Albinus Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Sep 19 18:51:23 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mS02F-0000nZ-Dq for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 19 Sep 2021 18:51:23 +0200 Original-Received: from localhost ([::1]:46896 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mS02E-00045h-EG for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 19 Sep 2021 12:51:22 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44856) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mS01w-00045X-0l for bug-gnu-emacs@gnu.org; Sun, 19 Sep 2021 12:51:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:56429) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mS01t-0006TO-U3 for bug-gnu-emacs@gnu.org; Sun, 19 Sep 2021 12:51:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mS01t-0007Rv-LG for bug-gnu-emacs@gnu.org; Sun, 19 Sep 2021 12:51:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 19 Sep 2021 16:51:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50581 X-GNU-PR-Package: emacs Original-Received: via spool by 50581-submit@debbugs.gnu.org id=B50581.163207025328620 (code B ref 50581); Sun, 19 Sep 2021 16:51:01 +0000 Original-Received: (at 50581) by debbugs.gnu.org; 19 Sep 2021 16:50:53 +0000 Original-Received: from localhost ([127.0.0.1]:39742 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mS01l-0007RY-Et for submit@debbugs.gnu.org; Sun, 19 Sep 2021 12:50:53 -0400 Original-Received: from mail-ed1-f49.google.com ([209.85.208.49]:37465) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mS01j-0007RJ-3j for 50581@debbugs.gnu.org; Sun, 19 Sep 2021 12:50:52 -0400 Original-Received: by mail-ed1-f49.google.com with SMTP id bx4so6314093edb.4 for <50581@debbugs.gnu.org>; Sun, 19 Sep 2021 09:50:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=1Pn4KBSdZI22xWerEarGIJ0VlFRA794JLMcyItEBXBA=; b=ow0Eu3fA0Zxv1sDnMRg2tCPVp1TlTMNAp9e4duE4kMq7d6PPc/VLtDJuwca0NjzmKK vpGpTRLetcF9qlWrn47OEwmTCKayZE0N2cdqdKRYXnFjBbs7dvWaTVJKe+af1cI/CMfw JXFH5/KPnkC8QrHEe6AUScMlI/ssPSp0/JdvAXqDfippjWduld77Jh1S8gdb2mZ/M5gD TAXTT6FNVXEBrtserkx7lvAWA1+CRl5VJ576Y4IG9Zlxf3WF9QQ7U12As1A4C3v8YRwX D84ioNOkBFyFWcWVBUI0Xie6Lx4uUyDaBCdxGosvecJfUC+woDPRa26c6frQ08ynE0Iu uDCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=1Pn4KBSdZI22xWerEarGIJ0VlFRA794JLMcyItEBXBA=; b=Lhi61pn7Og+dJTOUr7ABayxuVAw/M8lbiN0VjaRNbf/5Jqp05mmRBnytudGr9Ure5P QX5To4iG5eMK6uij/Bspg27ydq/kU0jidbvqj+nfXnzrRbgs5/DG0e4d6IOccfW2l6TJ V3EldtzM5qhmrvFi1ydD5Em1i0yqUdVmKcNqZlGjpCnr6MJ/Jmf5mZYsT2dwCswQCpzp NP4MZ4yrMp5kJYMLeN7YrLU731YFflmYOPPBK5d+7YurxiZ6LKVD1uOruyW3V6bUYgSc MRQfDvjgtUvZydO6tK0APz+CSVyrW4eJqH2PUVbURuwqg2I9qBMAw/zG0ttCL+XS6aDh jUhQ== X-Gm-Message-State: AOAM531Ymkw6MOh+DbAQ+g+lOdRwUu4iSwL0AZKVE/JyTnbPWWop0M8k vs6HpFUP/adPc9JBVau9SE8/SrEFPfwBHuox X-Google-Smtp-Source: ABdhPJzBvz9+JzcmiuHqCrKlq2nO2SemIsgd25IzpL2XKEyMvjUZVBBNdxws/6o0MiouG7nZs7o27w== X-Received: by 2002:a50:9b52:: with SMTP id a18mr24599238edj.165.1632070245244; Sun, 19 Sep 2021 09:50:45 -0700 (PDT) Original-Received: from calancha-pc.dy.bbexcite.jp ([193.118.249.171]) by smtp.gmail.com with ESMTPSA id s6sm304434edx.96.2021.09.19.09.50.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Sep 2021 09:50:43 -0700 (PDT) In-Reply-To: <87sfy7ov5m.fsf@gmx.de> (Michael Albinus's message of "Tue, 14 Sep 2021 20:43:17 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:214757 Archived-At: Michael Albinus writes: > Indeed, the directory case is not implemented in tramp-sh-handle-dired-compress-file. > I will see how to implement it next time. I have mimic what `dired-compress-file' does: it checks if the file is a directory. --8<-----------------------------cut here---------------start------------->8--- diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index fbb122e721..54256253b1 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el @@ -2498,9 +2498,13 @@ tramp-sh-handle-dired-compress-file (with-tramp-progress-reporter v 0 (format "Uncompressing %s" file) (when (tramp-send-command-and-check - v (concat (nth 2 suffix) " " - (tramp-shell-quote-argument localname))) - (dired-remove-file file) + v (if (string-match-p "%[io]" (nth 2 suffix)) + (replace-regexp-in-string + "%i" (tramp-shell-quote-argument localname) + (nth 2 suffix)) + (concat (nth 2 suffix) " " (tramp-shell-quote-argument localname)))) + (unless (string-match-p "\\.tar\\.gz" file) + (dired-remove-file file)) (string-match (car suffix) file) (concat (substring file 0 (match-beginning 0)))))) (t @@ -2508,14 +2512,19 @@ tramp-sh-handle-dired-compress-file ;; Try gzip. (with-tramp-progress-reporter v 0 (format "Compressing %s" file) (when (tramp-send-command-and-check - v (concat "gzip -f " - (tramp-shell-quote-argument localname))) - (dired-remove-file file) - (cond ((file-exists-p (concat file ".gz")) - (concat file ".gz")) - ((file-exists-p (concat file ".z")) - (concat file ".z")) - (t nil))))))))) + v (if (file-directory-p file) + (format "tar -cf - %s | gzip -c9 > %s.tar.gz" + (tramp-shell-quote-argument (file-name-nondirectory localname)) + (tramp-shell-quote-argument localname)) + (concat "gzip -f " + (tramp-shell-quote-argument localname)))) + (unless (file-directory-p file) + (dired-remove-file file)) + (catch 'found nil + (dolist (target (mapcar (lambda (suffix) (concat file suffix)) + '(".tar.gz" ".gz" ".z"))) + (when (file-exists-p target) + (throw 'found target))))))))))) (defun tramp-sh-handle-insert-directory (filename switches &optional wildcard full-directory-p) diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index 9f0264abc1..b0b61ad8f0 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -61,6 +61,7 @@ (declare-function tramp-list-tramp-buffers "tramp-cmds") (declare-function tramp-method-out-of-band-p "tramp-sh") (declare-function tramp-smb-get-localname "tramp-smb") +(declare-function dired-compress "dired-aux") (defvar ange-ftp-make-backup-files) (defvar auto-save-file-name-transforms) (defvar lock-file-name-transforms) @@ -7079,6 +7080,36 @@ tramp--test-with-proper-process-name-and-buffer (ignore-errors (all-completions "tramp" (symbol-value x))) (ert-fail (format "Hook `%s' still contains Tramp function" x)))))) +(ert-deftest tramp-test47-dired-compress-file () + "Check that Tramp (un)compress normal files." + (skip-unless (tramp--test-enabled)) + (let ((default-directory tramp-test-temporary-file-directory) + (tmp-name (tramp--test-make-temp-name))) + (write-region "foo" nil tmp-name) + (dired default-directory) + (dired-revert) + (dired-goto-file tmp-name) + (should-not (dired-compress)) + (should (string= (concat tmp-name ".gz") (dired-get-filename))) + (should-not (dired-compress)) + (should (string= tmp-name (dired-get-filename))) + (delete-file tmp-name))) + +(ert-deftest tramp-test47-dired-compress-dir () + "Check that Tramp (un)compress directories." + (skip-unless (tramp--test-enabled)) + (let ((default-directory tramp-test-temporary-file-directory) + (tmp-name (tramp--test-make-temp-name))) + (make-directory tmp-name) + (dired default-directory) + (dired-revert) + (dired-goto-file tmp-name) + (should-not (dired-compress)) + (should (string= (concat tmp-name ".tar.gz") (dired-get-filename))) + (should-not (dired-compress)) + (should (string= tmp-name (dired-get-filename))) + (delete-directory tmp-name))) + (defun tramp-test-all (&optional interactive) "Run all tests for \\[tramp]. If INTERACTIVE is non-nil, the tests are run interactively." --8<-----------------------------cut here---------------end--------------->8--- In GNU Emacs 28.0.50 (build 6, x86_64-pc-linux-gnu, GTK+ Version 3.24.5, cairo version 1.16.0) Repository revision: 7abbf3779cf88c59a9c20526464974213db63fdb Repository branch: master Windowing system distributor 'The X.Org Foundation', version 11.0.12004000 System Description: Debian GNU/Linux 10 (buster)