Skip to content

Commit fc39fd0

Browse files
committed
Add support for GNU long names to minitar.
1 parent 70b94d7 commit fc39fd0

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

quicklisp/minitar.lisp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,15 @@ value it specifies as multiple values."
125125
(read-sequence block stream)
126126
(write-sequence block outstream :end partial))))))
127127

128+
(defun gnu-long-name (size stream)
129+
;; GNU long names are simply the filename (null terminated) packed into the
130+
;; payload.
131+
(let ((payload (read-octet-vector size stream)))
132+
(ascii-subseq payload 0 (1- size))))
133+
128134
(defun unpack-tarball (tarfile &key (directory *default-pathname-defaults*))
129135
(let ((block (make-block-buffer))
130-
(pax-extended-path nil))
136+
(extended-path nil))
131137
(with-open-file (stream tarfile :element-type '(unsigned-byte 8))
132138
(loop
133139
(let ((size (read-sequence block stream)))
@@ -139,7 +145,7 @@ value it specifies as multiple values."
139145
(return))
140146
(let* ((payload-code (aref block 156))
141147
(payload-type (payload-type payload-code))
142-
(tar-path (or (shiftf pax-extended-path nil)
148+
(tar-path (or (shiftf extended-path nil)
143149
(full-path block)))
144150
(full-path (merge-pathnames tar-path directory))
145151
(payload-size (payload-size block))
@@ -149,14 +155,16 @@ value it specifies as multiple values."
149155
(save-file full-path payload-size stream))
150156
(:directory
151157
(ensure-directories-exist full-path))
152-
((:symlink :long-name :global-header)
158+
((:symlink :global-header)
153159
;; These block types aren't required for Quicklisp archives
154160
(skip-n-blocks block-count stream))
161+
(:long-name
162+
(setf extended-path (gnu-long-name payload-size stream)))
155163
(:pax-extended-header
156164
(let* ((pax-header-data (read-octet-vector payload-size stream))
157165
(path (pax-header-path pax-header-data)))
158166
(when path
159-
(setf pax-extended-path path))))
167+
(setf extended-path path))))
160168
(t
161169
(warn "Unknown tar block payload code -- ~D" payload-code)
162170
(skip-n-blocks block-count stream)))))))))

0 commit comments

Comments
 (0)