unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: npostavs@users.sourceforge.net
To: 25220@debbugs.gnu.org
Subject: bug#25220: tar-untar-buffer doesn't support symlinks
Date: Sat, 17 Dec 2016 19:25:47 -0500	[thread overview]
Message-ID: <877f6yccc4.fsf@users.sourceforge.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 432 bytes --]

Severity: wishlist

tar-untar-buffer silently converts symlinks into regular files.  There
might be some portability trouble with supporting them, but at least we
should warn about low fidelity unpacking, as in the patch below.

This initially turned up as a yasnippet bug, because the package's
tarball was using symlinks.  Of course that has to be fixed by avoiding
symlinks (https://github.com/joaotavora/yasnippet/issues/748).


[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 3082 bytes --]

From 43d59f8d90604cb8d65a28d99f90156da70d4718 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Sat, 17 Dec 2016 18:01:52 -0500
Subject: [PATCH] Warn about incomplete untarring of link files

The current tar-mode is doesn't really support unpacking symlinks, it
simply creates an empty file of the same name.

* lisp/tar-mode.el (tar--describe-as-link): New function extracted from
`tar--check-descriptor'.
(tar-untar-buffer): Use it to warn about imperfectly untarred link
files.
---
 lisp/tar-mode.el | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/lisp/tar-mode.el b/lisp/tar-mode.el
index 0520369..cafd0ad 100644
--- a/lisp/tar-mode.el
+++ b/lisp/tar-mode.el
@@ -544,6 +544,7 @@ tar-untar-buffer
                (dir (if (eq (tar-header-link-type descriptor) 5)
                         name
                       (file-name-directory name)))
+               (link-desc (tar--describe-as-link descriptor))
                (start (tar-header-data-start descriptor))
                (end (+ start (tar-header-size descriptor))))
           (unless (file-directory-p name)
@@ -552,6 +553,10 @@ tar-untar-buffer
                 (make-directory dir t))
             (unless (file-directory-p name)
 	      (let ((coding-system-for-write 'no-conversion))
+                (when link-desc
+                  (lwarn '(tar link) :warning
+                         "Extracted `%s', %s, as a normal file"
+                         name link-desc))
 		(write-region start end name)))
             (set-file-modes name (tar-header-mode descriptor))))))))
 
@@ -816,19 +821,23 @@ tar-current-descriptor
 	  nil
 	  (error "This line does not describe a tar-file entry"))))
 
-(defun tar--check-descriptor (descriptor)
+(defun tar--describe-as-link (descriptor)
   (let ((link-p (tar-header-link-type descriptor)))
     (if link-p
-	(error "This is %s, not a real file"
-	       (cond ((eq link-p 5) "a directory")
-		     ((eq link-p 20) "a tar directory header")
-		     ((eq link-p 28) "a next has longname")
-		     ((eq link-p 29) "a multivolume-continuation")
-		     ((eq link-p 35) "a sparse entry")
-		     ((eq link-p 38) "a volume header")
-		     ((eq link-p 55) "a pax global extended header")
-		     ((eq link-p 72) "a pax extended header")
-		     (t "a link"))))))
+	(cond ((eq link-p 5) "a directory")
+              ((eq link-p 20) "a tar directory header")
+              ((eq link-p 28) "a next has longname")
+              ((eq link-p 29) "a multivolume-continuation")
+              ((eq link-p 35) "a sparse entry")
+              ((eq link-p 38) "a volume header")
+              ((eq link-p 55) "a pax global extended header")
+              ((eq link-p 72) "a pax extended header")
+              (t "a link")))))
+
+(defun tar--check-descriptor (descriptor)
+  (let ((link-desc (tar--describe-as-link descriptor)))
+    (when link-desc
+      (error "This is %s, not a real file" link-desc))))
 
 (defun tar-get-descriptor ()
   (let* ((descriptor (tar-current-descriptor))
-- 
2.9.3


             reply	other threads:[~2016-12-18  0:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-18  0:25 npostavs [this message]
2019-07-27 11:11 ` bug#25220: tar-untar-buffer doesn't support symlinks Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877f6yccc4.fsf@users.sourceforge.net \
    --to=npostavs@users.sourceforge.net \
    --cc=25220@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).