match (car x)))
x))
result)))
- (when (natnump count)
- (setq result (last result count)))
+ (when (and (natnump count) (> count 0))
+ (setq result (nbutlast result (- (length result) count))))
result)))))))
(defun tramp-adb-get-ls-command (vec)
(let (tramp-crypt-enabled)
(delete-file (tramp-crypt-encrypt-file-name filename)))))
-(defun tramp-crypt-handle-directory-files (directory &optional full match nosort)
+(defun tramp-crypt-handle-directory-files
+ (directory &optional full match nosort count)
"Like `directory-files' for Tramp files."
(unless (file-exists-p directory)
(tramp-error
(replace-regexp-in-string
(concat "^" (regexp-quote directory)) "" x))
result)))
- (if nosort result (sort result #'string<)))))
+ (unless nosort
+ (setq result (sort result #'string<)))
+ (when (and (natnump count) (> count 0))
+ (setq result (nbutlast result (- (length result) count))))
+ result)))
(defun tramp-crypt-handle-file-attributes (filename &optional id-format)
"Like `file-attributes' for Tramp files."
byte-array (car byte-array))))
(dbus-byte-array-to-string
(if (and (consp byte-array) (zerop (car (last byte-array))))
- (butlast byte-array) byte-array))))
+ (nbutlast byte-array) byte-array))))
(defun tramp-gvfs-stringify-dbus-message (message)
"Convert a D-Bus MESSAGE into readable UTF8 strings, used for traces."
;; Use `path-separator' as it does eshell.
(setq eshell-path-env
(mapconcat
- #'identity (butlast (tramp-compat-exec-path)) path-separator)))
+ #'identity (nbutlast (tramp-compat-exec-path)) path-separator)))
(with-eval-after-load 'esh-util
(add-hook 'eshell-mode-hook
(directory &optional recursive trash)
"Like `delete-directory' for Tramp files."
(with-parsed-tramp-file-name (expand-file-name directory) nil
- (delete-directory (tramp-rclone-local-file-name directory) recursive trash)
(tramp-flush-directory-properties v localname)
- (tramp-rclone-flush-directory-cache v)))
+ (tramp-rclone-flush-directory-cache v)
+ (delete-directory (tramp-rclone-local-file-name directory) recursive trash)))
(defun tramp-rclone-handle-delete-file (filename &optional trash)
"Like `delete-file' for Tramp files."
(with-parsed-tramp-file-name (expand-file-name filename) nil
+ (tramp-rclone-flush-directory-cache v)
(delete-file (tramp-rclone-local-file-name filename) trash)
- (tramp-flush-file-properties v localname)
- (tramp-rclone-flush-directory-cache v)))
+ (tramp-flush-file-properties v localname)))
(defun tramp-rclone-handle-directory-files
(directory &optional full match nosort count)
(setq directory (file-name-as-directory (expand-file-name directory)))
(with-parsed-tramp-file-name directory nil
(let ((result
- (directory-files
- (tramp-rclone-local-file-name directory) full match count)))
+ (tramp-compat-directory-files
+ (tramp-rclone-local-file-name directory) full match nosort count)))
;; Massage the result.
(when full
(let ((local (concat "^" (regexp-quote (tramp-rclone-mount-point v))))
(setcar item (expand-file-name (car item) directory)))
(push item result)))
- (when (natnump count)
- (setq result (last result count)))
+ (unless nosort
+ (setq result (sort result (lambda (x y) (string< (car x) (car y))))))
- (or (if nosort
- result
- (sort result (lambda (x y) (string< (car x) (car y)))))
+ (when (and (natnump count) (> count 0))
+ (setq result (nbutlast result (- (length result) count))))
+
+ (or result
;; The scripts could fail, for example with huge file size.
(tramp-handle-directory-files-and-attributes
directory full match nosort id-format count)))))
(mapcar (lambda (x) (when (string-match-p match x) x))
result))))
+ ;; Sort them if necessary.
+ (unless nosort
+ (setq result (sort result #'string-lessp)))
+
;; Return count number of results.
(when (and (natnump count) (> count 0))
(setq result (nbutlast result (- (length result) count))))
(mapcar
(lambda (x) (format "%s/%s" (directory-file-name directory) x))
result)))
- ;; Sort them if necessary.
- (unless nosort (setq result (sort result #'string-lessp)))
+
result))
(defun tramp-smb-handle-expand-file-name (name &optional dir)
result)))
(unless nosort
(setq result (sort result #'string<)))
- (when (natnump count)
- (setq result (last result count)))
+ (when (and (natnump count) (> count 0))
+ (setq result (nbutlast result (- (length result) count))))
result)))
(defun tramp-handle-directory-files-and-attributes
(skip-unless (tramp--test-enabled))
;; The bugs are fixed in Emacs 28.1.
(skip-unless (tramp--test-emacs28-p))
+ ;; Methods with a share do not expand "/path/..".
+ (skip-unless (not (tramp--test-share-p)))
(should
(string-equal
(when (tramp--test-emacs28-p)
(with-no-warnings
(should
- (= 1 (length
- (directory-files
- tmp-name1 nil directory-files-no-dot-files-regexp
- nil 1)))))))
+ (equal
+ (directory-files
+ tmp-name1 nil directory-files-no-dot-files-regexp nil 1)
+ '("bla"))))))
;; Cleanup.
(ignore-errors (delete-directory tmp-name1 'recursive))))))
;; Check the COUNT arg. It exists since Emacs 28.
(when (tramp--test-emacs28-p)
(with-no-warnings
- (should (= 1 (length (directory-files-and-attributes
- tmp-name2 nil "\\`b" nil nil 1)))))))
+ (setq attr (directory-files-and-attributes
+ tmp-name2 nil "\\`b" nil nil 1))
+ (should (equal (mapcar #'car attr) '("bar"))))))
;; Cleanup.
(ignore-errors (delete-directory tmp-name1 'recursive))))))
(skip-unless
(or (tramp--test-sh-p) (tramp--test-sudoedit-p)
;; Not all tramp-gvfs.el methods support changing the file mode.
- (and
- (tramp--test-gvfs-p)
- (string-match-p
- "ftp" (file-remote-p tramp-test-temporary-file-directory 'method)))))
+ (tramp--test-gvfs-p "afp") (tramp--test-gvfs-p "ftp")))
(dolist (quoted (if (tramp--test-expensive-test) '(nil t) '(nil)))
(let ((tmp-name1 (tramp--test-make-temp-name nil quoted))
(tramp-sh-file-name-handler-p
(tramp-dissect-file-name tramp-test-temporary-file-directory)))
+(defun tramp--test-share-p ()
+ "Check, whether the method needs a share."
+ (and (tramp--test-gvfs-p)
+ (string-match-p
+ "^\\(afp\\|davs?\\|smb\\)$"
+ (file-remote-p tramp-test-temporary-file-directory 'method))))
+
(defun tramp--test-sudoedit-p ()
"Check, whether the sudoedit method is used."
(tramp-sudoedit-file-name-p tramp-test-temporary-file-directory))