comparison lisp/tar-mode.el @ 95370:fafc513e04bc

(tar-summarize-buffer): Fix reporter initialization. (tar-mode): Use write-region-annotate-functions rather than write-contents-functions. (tar-extract): Remove unused var `pos'. (tar-subfile-save-buffer): Remove unused var `following-descs'. (tar-mode-write-file): Remove. (tar-write-region-annotate): New function.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Wed, 28 May 2008 17:43:58 +0000
parents 8a8bad853798
children 4eddf6f13d89
comparison
equal deleted inserted replaced
95369:d147ddeb05f9 95370:fafc513e04bc
440 (assert (tar-data-swapped-p)) 440 (assert (tar-data-swapped-p))
441 (let* ((modified (buffer-modified-p)) 441 (let* ((modified (buffer-modified-p))
442 (result '()) 442 (result '())
443 (pos (point-min)) 443 (pos (point-min))
444 (progress-reporter 444 (progress-reporter
445 (make-progress-reporter "Parsing tar file..." 445 (with-current-buffer tar-data-buffer
446 (point-min) (max 1 (- (buffer-size) 1024)))) 446 (make-progress-reporter "Parsing tar file..."
447 (point-min) (point-max))))
447 descriptor) 448 descriptor)
448 (with-current-buffer tar-data-buffer 449 (with-current-buffer tar-data-buffer
449 (while (and (<= (+ pos 512) (point-max)) 450 (while (and (<= (+ pos 512) (point-max))
450 (setq descriptor (tar-header-block-tokenize pos))) 451 (setq descriptor (tar-header-block-tokenize pos)))
451 (setq pos (marker-position (tar-header-data-start descriptor))) 452 (setq pos (marker-position (tar-header-data-start descriptor)))
465 466
466 (push descriptor result) 467 (push descriptor result)
467 468
468 (and (null (tar-header-link-type descriptor)) 469 (and (null (tar-header-link-type descriptor))
469 (> size 0) 470 (> size 0)
470 ;; Round up to a multiple of 512.
471 (setq pos (+ pos (tar-roundup-512 size))))))) 471 (setq pos (+ pos (tar-roundup-512 size)))))))
472 472
473 (set (make-local-variable 'tar-parse-info) (nreverse result)) 473 (set (make-local-variable 'tar-parse-info) (nreverse result))
474 ;; A tar file should end with a block or two of nulls, 474 ;; A tar file should end with a block or two of nulls,
475 ;; but let's not get a fatal error if it doesn't. 475 ;; but let's not get a fatal error if it doesn't.
605 (or file-name-coding-system 605 (or file-name-coding-system
606 default-file-name-coding-system 606 default-file-name-coding-system
607 locale-coding-system)) 607 locale-coding-system))
608 ;; Prevent loss of data when saving the file. 608 ;; Prevent loss of data when saving the file.
609 (set (make-local-variable 'file-precious-flag) t) 609 (set (make-local-variable 'file-precious-flag) t)
610 (auto-save-mode 0)
611 (buffer-disable-undo) 610 (buffer-disable-undo)
612 (widen) 611 (widen)
613 ;; Now move the Tar data into an auxiliary buffer, so we can use the main 612 ;; Now move the Tar data into an auxiliary buffer, so we can use the main
614 ;; buffer for the summary. 613 ;; buffer for the summary.
615 (assert (not (tar-data-swapped-p))) 614 (assert (not (tar-data-swapped-p)))
616 (set (make-local-variable 'revert-buffer-function) 'tar-mode-revert) 615 (set (make-local-variable 'revert-buffer-function) 'tar-mode-revert)
617 (set (make-local-variable 'write-contents-functions) '(tar-mode-write-file)) 616 (add-hook 'write-region-annotate-functions 'tar-write-region-annotate nil t)
618 (add-hook 'kill-buffer-hook 'tar-mode-kill-buffer-hook nil t) 617 (add-hook 'kill-buffer-hook 'tar-mode-kill-buffer-hook nil t)
619 (add-hook 'change-major-mode-hook 'tar-change-major-mode-hook nil t) 618 (add-hook 'change-major-mode-hook 'tar-change-major-mode-hook nil t)
620 ;; Tar data is made of bytes, not chars. 619 ;; Tar data is made of bytes, not chars.
621 (set-buffer-multibyte nil) 620 (set-buffer-multibyte nil)
622 (set (make-local-variable 'tar-data-buffer) 621 (set (make-local-variable 'tar-data-buffer)
745 (new-buffer-file-name (expand-file-name 744 (new-buffer-file-name (expand-file-name
746 ;; `:' is not allowed on Windows 745 ;; `:' is not allowed on Windows
747 (concat tarname "!" name))) 746 (concat tarname "!" name)))
748 (buffer (get-file-buffer new-buffer-file-name)) 747 (buffer (get-file-buffer new-buffer-file-name))
749 (just-created nil) 748 (just-created nil)
750 (pos (point))
751 undo-list) 749 undo-list)
752 (unless buffer 750 (unless buffer
753 (setq buffer (generate-new-buffer bufname)) 751 (setq buffer (generate-new-buffer bufname))
754 (with-current-buffer buffer 752 (with-current-buffer buffer
755 (setq undo-list buffer-undo-list 753 (setq undo-list buffer-undo-list
1022 (if (string= "" new-name) (error "zero length name")) 1020 (if (string= "" new-name) (error "zero length name"))
1023 (let ((encoded-new-name (encode-coding-string new-name 1021 (let ((encoded-new-name (encode-coding-string new-name
1024 tar-file-name-coding-system))) 1022 tar-file-name-coding-system)))
1025 (if (> (length encoded-new-name) 98) (error "name too long")) 1023 (if (> (length encoded-new-name) 98) (error "name too long"))
1026 (setf (tar-header-name (tar-current-descriptor)) new-name) 1024 (setf (tar-header-name (tar-current-descriptor)) new-name)
1025 ;; FIXME: Make it work for ././@LongLink.
1027 (tar-alter-one-field 0 1026 (tar-alter-one-field 0
1028 (substring (concat encoded-new-name (make-string 99 0)) 0 99)))) 1027 (substring (concat encoded-new-name (make-string 99 0)) 0 99))))
1029 1028
1030 1029
1031 (defun tar-chmod-entry (new-mode) 1030 (defun tar-chmod-entry (new-mode)
1101 subfile-size) 1100 subfile-size)
1102 (with-current-buffer tar-superior-buffer 1101 (with-current-buffer tar-superior-buffer
1103 (let* ((start (tar-header-data-start descriptor)) 1102 (let* ((start (tar-header-data-start descriptor))
1104 (name (tar-header-name descriptor)) 1103 (name (tar-header-name descriptor))
1105 (size (tar-header-size descriptor)) 1104 (size (tar-header-size descriptor))
1106 (head (memq descriptor tar-parse-info)) 1105 (head (memq descriptor tar-parse-info)))
1107 (following-descs (cdr head)))
1108 (if (not head) 1106 (if (not head)
1109 (error "Can't find this tar file entry in its parent tar file!")) 1107 (error "Can't find this tar file entry in its parent tar file!"))
1110 (with-current-buffer tar-data-buffer 1108 (with-current-buffer tar-data-buffer
1111 ;; delete the old data... 1109 ;; delete the old data...
1112 (let* ((data-start start) 1110 (let* ((data-start start)
1201 (delete-region goal-end (point-max)) 1199 (delete-region goal-end (point-max))
1202 (goto-char (point-max)) 1200 (goto-char (point-max))
1203 (insert (make-string (- goal-end (point-max)) ?\0)))))))) 1201 (insert (make-string (- goal-end (point-max)) ?\0))))))))
1204 1202
1205 1203
1206 ;; Used in write-file-hook to write tar-files out correctly. 1204 ;; Used in write-region-annotate-functions to write tar-files out correctly.
1207 (defun tar-mode-write-file () 1205 (defun tar-write-region-annotate (start end)
1208 (unwind-protect 1206 ;; When called from write-file (and auto-save), `start' is nil.
1209 (progn 1207 ;; When called from M-x write-region, we assume the user wants to save
1210 (if (tar-data-swapped-p) (buffer-swap-text tar-data-buffer)) 1208 ;; (part of) the summary, not the tar data.
1211 ;; Yuck: This is an internal function. We should improve the 1209 (unless (or start (not (tar-data-swapped-p)))
1212 ;; write-content-functions hook to make it easier to DTRT. 1210 (tar-clear-modification-flags)
1213 (prog1 (basic-save-buffer-1) 1211 (set-buffer tar-data-buffer)
1214 (unless (tar-data-swapped-p) (buffer-swap-text tar-data-buffer)) 1212 nil))
1215 (tar-clear-modification-flags)
1216 (set-buffer-modified-p nil)))
1217 (unless (tar-data-swapped-p) (buffer-swap-text tar-data-buffer)))
1218 ;; Return t because we've written the file.
1219 t)
1220 1213
1221 (provide 'tar-mode) 1214 (provide 'tar-mode)
1222 1215
1223 ;; arch-tag: 8a585a4a-340e-42c2-89e7-d3b1013a4b78 1216 ;; arch-tag: 8a585a4a-340e-42c2-89e7-d3b1013a4b78
1224 ;;; tar-mode.el ends here 1217 ;;; tar-mode.el ends here