unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#25220: tar-untar-buffer doesn't support symlinks
@ 2016-12-18  0:25 npostavs
  2019-07-27 11:11 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 2+ messages in thread
From: npostavs @ 2016-12-18  0:25 UTC (permalink / raw)
  To: 25220

[-- 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* bug#25220: tar-untar-buffer doesn't support symlinks
  2016-12-18  0:25 bug#25220: tar-untar-buffer doesn't support symlinks npostavs
@ 2019-07-27 11:11 ` Lars Ingebrigtsen
  0 siblings, 0 replies; 2+ messages in thread
From: Lars Ingebrigtsen @ 2019-07-27 11:11 UTC (permalink / raw)
  To: npostavs; +Cc: 25220

npostavs@users.sourceforge.net writes:

> 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).

It looks like this patch was applied at the time, but the bug report
wasn't closed, so I'm doing that now.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-07-27 11:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-18  0:25 bug#25220: tar-untar-buffer doesn't support symlinks npostavs
2019-07-27 11:11 ` Lars Ingebrigtsen

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).