Function: dirvish--dir-data-async

dirvish--dir-data-async is a natively compiled function defined in dirvish.el.

Signature

(dirvish--dir-data-async DIR BUFFER &optional INHIBIT-SETUP)

Documentation

Asynchronously fetch metadata for DIR, stored locally in BUFFER.

INHIBIT-SETUP is passed to dirvish-data-for-dir.

Source Code

;; Defined in /nix/store/1gijwny2yx4fggrsb9l110h1ybs1gdk5-emacs-packages-deps/share/emacs/site-lisp/elpa/dirvish-20260725.1520/dirvish.el
(defun dirvish--dir-data-async (dir buffer &optional inhibit-setup)
  "Asynchronously fetch metadata for DIR, stored locally in BUFFER.
INHIBIT-SETUP is passed to `dirvish-data-for-dir'."
  (dirvish--make-proc
   `(prin1
     (let ((hs (make-hash-table)) (bk ',(dirvish-prop :vc-backend)))
       (if ,(and (not (dirvish-prop :sudo)) (dirvish-prop :remote)) (setq bk 0)
         (dolist (f (ignore-errors ; `dir' can be problematic due to its encoding
                      (directory-files ,(file-local-name dir) t nil t 20000)))
           (let* ((attrs (ignore-errors (file-attributes f))) (tp (nth 0 attrs)))
             (cond ((eq t tp) (setq tp '(dir . nil)))
                   (tp (setq tp `(,(if (file-directory-p tp) 'dir 'file) . ,tp)))
                   (t (setq tp '(file . nil))))
             (puthash (secure-hash 'md5 f) `(:builtin ,attrs :type ,tp) hs)))
         (setq bk (or bk (vc-responsible-backend ,(file-local-name dir) t))))
       (cons bk hs)))
   (lambda (p _)
     (pcase-let ((`(,buf . ,inhibit-setup) (process-get p 'meta))
                 (`(,pb . ,data) (cons (process-buffer p) nil)))
       (condition-case err
           (setq data (with-current-buffer pb (read (buffer-string))))
         (error (message "Fetch dir data failed with error: %s" err)))
       (when (and (buffer-live-p buf)
                  (listp data))
         (with-current-buffer buf
           (when-let* ((attrs (cdr data)) ((hash-table-p attrs)))
             (maphash (lambda (k v) (puthash k v dirvish--dir-data)) attrs))
           (dirvish-prop :vc-backend (or (car data) 0)) ; for &context compat
           (dirvish-data-for-dir dir buf inhibit-setup))))
     (delete-process p)
     (dirvish--kill-buffer (process-buffer p)))
   nil 'meta (cons buffer inhibit-setup)))