Function: trashed-read-trashinfo
trashed-read-trashinfo is a natively compiled function defined in
trashed.el.
Signature
(trashed-read-trashinfo TRASHINFO-FILE)
Documentation
Return a list of original file information from TRASHINFO-FILE.
The information is original file's size, deletion date and path. Currently, MS Windows Vista/7/8/8.1/10 Recycle Bin and freedesktop trash can are supported.
Source Code
;; Defined in /nix/store/7ppdacjhnynz276lxxnfw8sdz6r2k6h2-emacs-packages-deps/share/emacs/site-lisp/elpa/trashed-20230811.157/trashed.el
(defun trashed-read-trashinfo (trashinfo-file)
"Return a list of original file information from TRASHINFO-FILE.
The information is original file's size, deletion date and path.
Currently, MS Windows Vista/7/8/8.1/10 Recycle Bin and freedesktop trash can
are supported."
(ignore-errors
(with-temp-buffer
(set-buffer-multibyte nil)
(insert-file-contents-literally trashinfo-file)
(let (sizenum datenum pathstr)
(if (eq system-type 'windows-nt) ;; Windows Recycle Bin
(let ((header (trashed-buffer-get-integer 0 8))
(datewin (trashed-buffer-get-integer 16 8))
pathpos pathlen)
(pcase header
(1 ;; Windows Vista/7/8/8.1
(setq pathpos 24
pathlen (let ((i pathpos) found) ;; search NUL char
(while (and (< i (point-max)) (not found))
(setq found (and
(= (char-after i) 0)
(= (char-after (1+ i)) 0))
i (+ i 2)))
(/ (- i pathpos 2) 2))))
(2 ;; Windows 10
(setq pathpos 28
pathlen (1- (trashed-buffer-get-integer 24 4)))))
(setq sizenum (trashed-buffer-get-integer 8 8)
;; Win to Unix time format conversion
;; (100nsecs from 1/1/1601 to secs from 1/1/1970)
datenum (floor (/ (- datewin 116444736000000000)
10000000))
;; Conversion to (HIGH . LOW) format
datenum (list (lsh datenum -16)
(logand datenum (1- (lsh 1 16))))
pathstr (replace-regexp-in-string
"\\\\" "/" (decode-coding-string
(buffer-substring (+ 1 pathpos)
(+ 1 pathpos
(* pathlen 2)))
'utf-16-le))))
;; freedesktop trash can
(setq pathstr (decode-coding-string
(url-unhex-string
(when (re-search-forward
(rx bol "Path" (0+ blank) "="
(0+ blank) (group (1+ nonl)))
nil t)
(match-string 1)))
'utf-8)
datenum (progn
(goto-char (point-min))
(when (re-search-forward
(rx bol "DeletionDate" (0+ blank) "="
(0+ blank) (group (1+ nonl)))
nil t)
(parse-iso8601-time-string (match-string 1))))))
(list sizenum datenum pathstr)))))