Commit 66b49fc1 authored by Michael Albinus's avatar Michael Albinus

Rework Tramp wrt string-match-p, looking-at-p, save-match-data

* lisp/net/tramp.el (tramp-find-method, tramp-find-user)
(tramp-find-host, tramp-dissect-file-name, tramp-make-tramp-file-name)
(tramp-completion-make-tramp-file-name, tramp-debug-message)
(tramp-message, tramp-progress-reporter-update)
(tramp-set-completion-function)
(tramp-rfn-eshadow-update-overlay)
(tramp-find-file-name-coding-system-alist)
(tramp-file-name-for-operation)
(tramp-use-absolute-autoload-file-names)
(tramp-get-completion-methods, tramp-get-completion-user-host)
(tramp-handle-directory-files)
(tramp-handle-file-name-case-insensitive-p)
(tramp-handle-file-name-completion, tramp-handle-file-truename)
(tramp-handle-insert-directory, tramp-handle-load)
(tramp-handle-shell-command, tramp-action-yesno)
(tramp-action-yn, tramp-process-actions)
(tramp-mode-string-to-int, tramp-get-local-locale)
(tramp-local-host-p):
* lisp/net/tramp-adb.el (tramp-adb-handle-file-system-info)
(tramp-adb-handle-directory-files-and-attributes)
(tramp-adb--gnu-switches-to-ash, tramp-adb-sh-fix-ls-output)
(tramp-adb-handle-file-name-all-completions)
(tramp-adb-handle-shell-command)
(tramp-adb-handle-start-file-process):
* lisp/net/tramp-archive.el (tramp-archive-dissect-file-name):
* lisp/net/tramp-cache.el (tramp-get-hash-table)
(tramp-flush-directory-properties, tramp-flush-file-function):
* lisp/net/tramp-cmds.el (tramp-reporter-dump-variable)
(tramp-append-tramp-buffers):
* lisp/net/tramp-compat.el (tramp-compat-process-running-p):
* lisp/net/tramp-gvfs.el (tramp-gvfs-handle-expand-file-name)
(tramp-gvfs-get-file-attributes)
(tramp-gvfs-handle-file-attributes)
(tramp-gvfs-monitor-process-filter)
(tramp-gvfs-handler-mounted-unmounted)
(tramp-gvfs-connection-mounted-p, tramp-gvfs-mount-spec-entry)
(tramp-gvfs-mount-spec, tramp-gvfs-maybe-open-connection):
* lisp/net/tramp-sh.el (tramp-do-file-attributes-with-ls)
(tramp-do-file-attributes-with-stat)
(tramp-sh-handle-file-selinux-context)
(tramp-sh-handle-directory-files-and-attributes)
(tramp-do-directory-files-and-attributes-with-stat)
(tramp-sh-handle-file-name-all-completions)
(tramp-sh-handle-dired-compress-file)
(tramp-sh-handle-insert-directory)
(tramp-sh-handle-expand-file-name)
(tramp-sh-handle-start-file-process)
(tramp-sh-handle-process-file, tramp-sh-handle-write-region)
(tramp-sh-handle-file-notify-add-watch)
(tramp-sh-gio-monitor-process-filter)
(tramp-sh-gvfs-monitor-dir-process-filter)
(tramp-sh-inotifywait-process-filter)
(tramp-sh-handle-file-system-info, tramp-maybe-send-script)
(tramp-find-executable, tramp-open-shell, tramp-find-shell)
(tramp-open-connection-setup-interactive-shell)
(tramp-find-inline-encoding, tramp-call-local-coding-command)
(tramp-compute-multi-hops, tramp-maybe-open-connection)
(tramp-convert-file-attributes)
(tramp-make-copy-program-file-name, tramp-get-remote-locale)
(tramp-get-test-nt-command, tramp-get-remote-stat)
(tramp-get-inline-coding):
* lisp/net/tramp-smb.el (tramp-smb-handle-directory-files)
(tramp-smb-action-get-acl, tramp-smb-handle-file-attributes)
(tramp-smb-handle-file-name-all-completions)
(tramp-smb-handle-file-system-info)
(tramp-smb-handle-file-writable-p)
(tramp-smb-handle-insert-directory)
(tramp-smb-handle-make-directory)
(tramp-smb-handle-make-directory-internal)
(tramp-smb-handle-start-file-process, tramp-smb-get-localname)
(tramp-smb-read-file-entry): Use `string-match-p' and
`looking-at-p'.  Remove superfluous `save-match-data'.  Apply
`eval-when-compile' on constant concat data.

* lisp/net/tramp-compat.el (tramp-compat-file-name-quoted-p-p):
Use `string-prefix-p'.
(tramp-compat-file-name-unquote): Do not use match data.
parent 8f3fde38
......@@ -259,10 +259,11 @@ pass to the OPERATION."
(goto-char (point-min))
(forward-line)
(when (looking-at
(concat "[[:space:]]*[^[:space:]]+"
"[[:space:]]+\\([[:digit:]]+\\)"
"[[:space:]]+\\([[:digit:]]+\\)"
"[[:space:]]+\\([[:digit:]]+\\)"))
(eval-when-compile
(concat "[[:space:]]*[^[:space:]]+"
"[[:space:]]+\\([[:digit:]]+\\)"
"[[:space:]]+\\([[:digit:]]+\\)"
"[[:space:]]+\\([[:digit:]]+\\)")))
;; The values are given as 1k numbers, so we must change
;; them to number of bytes.
(list (* 1024 (string-to-number (match-string 1)))
......@@ -462,7 +463,7 @@ pass to the OPERATION."
(sort result (lambda (x y) (string< (car x) (car y))))))
(delq nil
(mapcar (lambda (x)
(if (or (not match) (string-match match (car x)))
(if (or (not match) (string-match-p match (car x)))
x))
result)))))))))
......@@ -499,7 +500,7 @@ Convert (\"-al\") to (\"-a\" \"-l\"). Remove arguments like \"--dired\"."
(delq nil
(mapcar
(lambda (s)
(and (not (string-match "\\(^--\\|^[^-]\\)" s)) s))
(and (not (string-match-p "\\(^--\\|^[^-]\\)" s)) s))
switches))))))
(defun tramp-adb-sh-fix-ls-output (&optional sort-by-time)
......@@ -514,7 +515,7 @@ Emacs dired can't find files."
"[[:space:]]\\([[:space:]][0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9][[:space:]]\\)" nil t)
(replace-match "0\\1" "\\1" nil)
;; Insert missing "/".
(when (looking-at "[0-9][0-9]:[0-9][0-9][[:space:]]+$")
(when (looking-at-p "[0-9][0-9]:[0-9][0-9][[:space:]]+$")
(end-of-line)
(insert "/")))
;; Sort entries.
......@@ -594,28 +595,27 @@ Emacs dired can't find files."
filename
(with-parsed-tramp-file-name (expand-file-name directory) nil
(with-tramp-file-property v localname "file-name-all-completions"
(save-match-data
(tramp-adb-send-command
v (format "%s -a %s"
(tramp-adb-get-ls-command v)
(tramp-shell-quote-argument localname)))
(mapcar
(lambda (f)
(if (file-directory-p (expand-file-name f directory))
(file-name-as-directory f)
f))
(with-current-buffer (tramp-get-buffer v)
(delete-dups
(append
;; In older Android versions, "." and ".." are not
;; included. In newer versions (toybox, since Android
;; 6) they are. We fix this by `delete-dups'.
'("." "..")
(delq
nil
(mapcar
(lambda (l) (and (not (string-match "^[[:space:]]*$" l)) l))
(split-string (buffer-string) "\n"))))))))))))
(tramp-adb-send-command
v (format "%s -a %s"
(tramp-adb-get-ls-command v)
(tramp-shell-quote-argument localname)))
(mapcar
(lambda (f)
(if (file-directory-p (expand-file-name f directory))
(file-name-as-directory f)
f))
(with-current-buffer (tramp-get-buffer v)
(delete-dups
(append
;; In older Android versions, "." and ".." are not
;; included. In newer versions (toybox, since Android 6)
;; they are. We fix this by `delete-dups'.
'("." "..")
(delq
nil
(mapcar
(lambda (l) (and (not (string-match-p "^[[:space:]]*$" l)) l))
(split-string (buffer-string) "\n")))))))))))
(defun tramp-adb-handle-file-local-copy (filename)
"Like `file-local-copy' for Tramp files."
......@@ -967,7 +967,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
(defun tramp-adb-handle-shell-command
(command &optional output-buffer error-buffer)
"Like `shell-command' for Tramp files."
(let* ((asynchronous (string-match "[ \t]*&[ \t]*\\'" command))
(let* ((asynchronous (string-match-p "[ \t]*&[ \t]*\\'" command))
;; We cannot use `shell-file-name' and `shell-command-switch',
;; they are variables of the local host.
(args (list "sh" "-c" (substring command 0 asynchronous)))
......@@ -1111,7 +1111,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
p))))
;; Save exit.
(if (string-match tramp-temp-buffer-name (buffer-name))
(if (string-match-p tramp-temp-buffer-name (buffer-name))
(ignore-errors
(set-process-buffer (tramp-get-connection-process v) nil)
(kill-buffer (current-buffer)))
......
......@@ -378,6 +378,7 @@ pass to the OPERATION."
(defun tramp-archive-file-name-p (name)
"Return t if NAME is a string with archive file name syntax."
(and (stringp name)
;; We cannot use `string-match-p', the matches are used.
(string-match tramp-archive-file-name-regexp name)
t))
......@@ -430,8 +431,9 @@ name is kept in slot `hop'"
;; http://...
((and url-handler-mode
tramp-compat-use-url-tramp-p
(string-match url-handler-regexp archive)
(string-match "https?" (url-type (url-generic-parse-url archive))))
(string-match-p url-handler-regexp archive)
(string-match-p
"https?" (url-type (url-generic-parse-url archive))))
(let* ((url-tramp-protocols
(cons
(url-type (url-generic-parse-url archive))
......
......@@ -104,7 +104,7 @@ matching entries of `tramp-connection-properties'."
(puthash key (make-hash-table :test 'equal) tramp-cache-data)))
(when (tramp-file-name-p key)
(dolist (elt tramp-connection-properties)
(when (string-match
(when (string-match-p
(or (nth 0 elt) "")
(tramp-make-tramp-file-name key 'noloc 'nohop))
(tramp-set-connection-property key (nth 1 elt) (nth 2 elt)))))
......@@ -217,8 +217,8 @@ Remove also properties of all files in subdirectories."
(lambda (key _value)
(when (and (tramp-file-name-p key)
(stringp (tramp-file-name-localname key))
(string-match (regexp-quote directory)
(tramp-file-name-localname key)))
(string-match-p (regexp-quote directory)
(tramp-file-name-localname key)))
(remhash key tramp-cache-data)))
tramp-cache-data)
;; Remove file properties of symlinks.
......@@ -236,7 +236,7 @@ Remove also properties of all files in subdirectories."
This is suppressed for temporary buffers."
(save-match-data
(unless (or (null (buffer-name))
(string-match "^\\( \\|\\*\\)" (buffer-name)))
(string-match-p "^\\( \\|\\*\\)" (buffer-name)))
(let ((bfn (if (stringp (buffer-file-name))
(buffer-file-name)
default-directory))
......
......@@ -261,7 +261,7 @@ buffer in your bug report.
(set varsym (read (format "(%s)" (tramp-cache-print val))))
;; There are non-7bit characters to be masked.
(when (and (stringp val)
(string-match
(string-match-p
(concat "[^" (bound-and-true-p mm-7bit-chars) "]") val))
(with-current-buffer reporter-eval-buffer
(set
......@@ -277,10 +277,11 @@ buffer in your bug report.
;; Remove string quotation.
(forward-line -1)
(when (looking-at
(concat "\\(^.*\\)" "\"" ;; \1 "
"\\((base64-decode-string \\)" "\\\\" ;; \2 \
"\\(\".*\\)" "\\\\" ;; \3 \
"\\(\")\\)" "\"$")) ;; \4 "
(eval-when-compile
(concat "\\(^.*\\)" "\"" ;; \1 "
"\\((base64-decode-string \\)" "\\\\" ;; \2 \
"\\(\".*\\)" "\\\\" ;; \3 \
"\\(\")\\)" "\"$"))) ;; \4 "
(replace-match "\\1\\2\\3\\4")
(beginning-of-line)
(insert " ;; Variable encoded due to non-printable characters.\n"))
......@@ -305,7 +306,7 @@ buffer in your bug report.
(delq nil
(mapcar
(lambda (b)
(when (string-match "\\*tramp/" (buffer-name b)) b))
(when (string-match-p "\\*tramp/" (buffer-name b)) b))
(buffer-list))))
(let ((reporter-eval-buffer buffer)
(elbuf (get-buffer-create " *tmp-reporter-buffer*")))
......@@ -333,7 +334,7 @@ buffer in your bug report.
(insert "\nload-path shadows:\n==================\n")
(ignore-errors
(mapc
(lambda (x) (when (string-match "tramp" x) (insert x "\n")))
(lambda (x) (when (string-match-p "tramp" x) (insert x "\n")))
(split-string (list-load-path-shadows t) "\n")))
;; Append buffers only when we are in message mode.
......
......@@ -97,7 +97,7 @@ Add the extension of F, if existing."
;; The returned command name could be truncated
;; to 15 characters. Therefore, we cannot check
;; for `string-equal'.
(and comm (string-match
(and comm (string-match-p
(concat "^" (regexp-quote comm))
process-name))))
(setq result t)))))))))
......@@ -195,7 +195,7 @@ This is a string of ten letters or dashes as in ls -l."
(defsubst tramp-compat-file-name-quoted-p (name)
"Whether NAME is quoted with prefix \"/:\".
If NAME is a remote file name, check the local part of NAME."
(string-match "^/:" (or (file-remote-p name 'localname) name))))
(string-prefix-p "/:" (or (file-remote-p name 'localname) name))))
(if (fboundp 'file-name-quote)
(defalias 'tramp-compat-file-name-quote 'file-name-quote)
......@@ -212,14 +212,11 @@ If NAME is a remote file name, the local part of NAME is quoted."
(defsubst tramp-compat-file-name-unquote (name)
"Remove quotation prefix \"/:\" from file NAME.
If NAME is a remote file name, the local part of NAME is unquoted."
(save-match-data
(let ((localname (or (file-remote-p name 'localname) name)))
(when (tramp-compat-file-name-quoted-p localname)
(setq
localname
(replace-match
(if (= (length localname) 2) "/" "") nil t localname)))
(concat (file-remote-p name) localname))))))
(let ((localname (or (file-remote-p name 'localname) name)))
(when (tramp-compat-file-name-quoted-p localname)
(setq
localname (if (= (length localname) 2) "/" (substring localname 2))))
(concat (file-remote-p name) localname)))))
;; `tramp-syntax' has changed its meaning in Emacs 26. We still
;; support old settings.
......
......@@ -899,14 +899,14 @@ file names."
(tramp-get-connection-property v "default-location" "~")
nil t localname 1)))
;; Tilde expansion is not possible.
(when (string-match "\\`\\(~[^/]*\\)\\(.*\\)\\'" localname)
(when (string-match-p "\\`\\(~[^/]*\\)\\(.*\\)\\'" localname)
(tramp-error
v 'file-error
"Cannot expand tilde in file `%s'" name))
(unless (tramp-run-real-handler 'file-name-absolute-p (list localname))
(setq localname (concat "/" localname)))
;; We do not pass "/..".
(if (string-match "^\\(afp\\|davs?\\|smb\\)$" method)
(if (string-match-p "^\\(afp\\|davs?\\|smb\\)$" method)
(when (string-match "^/[^/]+\\(/\\.\\./?\\)" localname)
(setq localname (replace-match "/" t t localname 1)))
(when (string-match "^/\\.\\./?" localname)
......@@ -997,8 +997,8 @@ If FILE-SYSTEM is non-nil, return file system attributes."
(setq filename (directory-file-name (expand-file-name filename)))
(with-parsed-tramp-file-name filename nil
(setq localname (tramp-compat-file-name-unquote localname))
(if (or (and (string-match "^\\(afp\\|davs?\\|smb\\)$" method)
(string-match "^/?\\([^/]+\\)$" localname))
(if (or (and (string-match-p "^\\(afp\\|davs?\\|smb\\)$" method)
(string-match-p "^/?\\([^/]+\\)$" localname))
(string-equal localname "/"))
(tramp-gvfs-get-root-attributes filename)
(assoc
......@@ -1038,7 +1038,8 @@ If FILE-SYSTEM is non-nil, return file system attributes."
(if (eq id-format 'integer)
(string-to-number
(or (cdr (assoc "unix::uid" attributes))
(format "%s" tramp-unknown-id-integer)))
(eval-when-compile
(format "%s" tramp-unknown-id-integer))))
(or (cdr (assoc "owner::user" attributes))
(cdr (assoc "unix::uid" attributes))
tramp-unknown-id-string)))
......@@ -1046,7 +1047,8 @@ If FILE-SYSTEM is non-nil, return file system attributes."
(if (eq id-format 'integer)
(string-to-number
(or (cdr (assoc "unix::gid" attributes))
(format "%s" tramp-unknown-id-integer)))
(eval-when-compile
(format "%s" tramp-unknown-id-integer))))
(or (cdr (assoc "owner::group" attributes))
(cdr (assoc "unix::gid" attributes))
tramp-unknown-id-string)))
......@@ -1216,14 +1218,16 @@ file-notify events."
string (replace-regexp-in-string
"renamed to" "moved" string))
;; https://bugs.launchpad.net/bugs/1742946
(when (string-match "Monitoring not supported\\|No locations given" string)
(when
(string-match-p "Monitoring not supported\\|No locations given" string)
(delete-process proc))
(while (string-match
(concat "^.+:"
"[[:space:]]\\(.+\\):"
"[[:space:]]" (regexp-opt tramp-gio-events t)
"\\([[:space:]]\\(.+\\)\\)?$")
(eval-when-compile
(concat "^.+:"
"[[:space:]]\\(.+\\):"
"[[:space:]]" (regexp-opt tramp-gio-events t)
"\\([[:space:]]\\(.+\\)\\)?$"))
string)
(let ((file (match-string 1 string))
......@@ -1233,11 +1237,11 @@ file-notify events."
;; File names are returned as URL paths. We must convert them.
(when (string-match ddu file)
(setq file (replace-match dd nil nil file)))
(while (string-match "%\\([0-9A-F]\\{2\\}\\)" file)
(while (string-match-p "%\\([0-9A-F]\\{2\\}\\)" file)
(setq file (url-unhex-string file)))
(when (string-match ddu (or file1 ""))
(setq file1 (replace-match dd nil nil file1)))
(while (string-match "%\\([0-9A-F]\\{2\\}\\)" (or file1 ""))
(while (string-match-p "%\\([0-9A-F]\\{2\\}\\)" (or file1 ""))
(setq file1 (url-unhex-string file1)))
;; Remove watch when file or directory to be watched is deleted.
(when (and (member action '(moved deleted))
......@@ -1540,7 +1544,7 @@ file-notify events."
(when (and (string-equal "dav" method) (string-equal "true" ssl))
(setq method "davs"))
(when (and (string-equal "davs" method)
(string-match
(string-match-p
tramp-gvfs-nextcloud-default-prefix-regexp prefix))
(setq method "nextcloud"))
(when (string-equal "google-drive" method)
......@@ -1630,7 +1634,7 @@ file-notify events."
(when (and (string-equal "dav" method) (string-equal "true" ssl))
(setq method "davs"))
(when (and (string-equal "davs" method)
(string-match
(string-match-p
tramp-gvfs-nextcloud-default-prefix-regexp prefix))
(setq method "nextcloud"))
(when (string-equal "google-drive" method)
......@@ -1647,8 +1651,8 @@ file-notify events."
(string-equal domain (tramp-file-name-domain vec))
(string-equal host (tramp-file-name-host vec))
(string-equal port (tramp-file-name-port vec))
(string-match (concat "^/" (regexp-quote (or share "")))
(tramp-file-name-unquote-localname vec)))
(string-match-p (concat "^/" (regexp-quote (or share "")))
(tramp-file-name-unquote-localname vec)))
;; Set mountpoint and location.
(tramp-set-file-property vec "/" "fuse-mountpoint" fuse-mountpoint)
(tramp-set-connection-property
......@@ -1671,7 +1675,7 @@ file-notify events."
(defun tramp-gvfs-mount-spec-entry (key value)
"Construct a mount-spec entry to be used in a mount_spec.
It was \"a(say)\", but has changed to \"a{sv})\"."
(if (string-match "^(aya{sv})" tramp-gvfs-mountlocation-signature)
(if (string-match-p "^(aya{sv})" tramp-gvfs-mountlocation-signature)
(list :dict-entry key
(list :variant (tramp-gvfs-dbus-string-to-byte-array value)))
(list :struct key (tramp-gvfs-dbus-string-to-byte-array value))))
......@@ -1686,7 +1690,7 @@ It was \"a(say)\", but has changed to \"a{sv})\"."
(localname (tramp-file-name-unquote-localname vec))
(share (when (string-match "^/?\\([^/]+\\)" localname)
(match-string 1 localname)))
(ssl (if (string-match "^davs\\|^nextcloud" method) "true" "false"))
(ssl (if (string-match-p "^davs\\|^nextcloud" method) "true" "false"))
(mount-spec
`(:array
,@(cond
......@@ -1694,7 +1698,7 @@ It was \"a(say)\", but has changed to \"a{sv})\"."
(list (tramp-gvfs-mount-spec-entry "type" "smb-share")
(tramp-gvfs-mount-spec-entry "server" host)
(tramp-gvfs-mount-spec-entry "share" share)))
((string-match "^dav\\|^nextcloud" method)
((string-match-p "^dav\\|^nextcloud" method)
(list (tramp-gvfs-mount-spec-entry "type" "dav")
(tramp-gvfs-mount-spec-entry "host" host)
(tramp-gvfs-mount-spec-entry "ssl" ssl)))
......@@ -1708,7 +1712,7 @@ It was \"a(say)\", but has changed to \"a{sv})\"."
((string-equal "nextcloud" method)
(list (tramp-gvfs-mount-spec-entry "type" "owncloud")
(tramp-gvfs-mount-spec-entry "host" host)))
((string-match "^http" method)
((string-match-p "^http" method)
(list (tramp-gvfs-mount-spec-entry "type" "http")
(tramp-gvfs-mount-spec-entry
"uri"
......@@ -1725,7 +1729,7 @@ It was \"a(say)\", but has changed to \"a{sv})\"."
,@(when port
(list (tramp-gvfs-mount-spec-entry "port" port)))))
(mount-pref
(if (and (string-match "^dav" method)
(if (and (string-match-p "^dav" method)
(string-match "^/?[^/]+" localname))
(match-string 0 localname)
(tramp-gvfs-get-remote-prefix vec))))
......@@ -1815,7 +1819,7 @@ connection if a previous connection has died for some reason."
(string-equal localname "/"))
(tramp-error vec 'file-error "Filename must contain an AFP volume"))
(when (and (string-match method "davs?")
(when (and (string-match-p "davs?" method)
(string-equal localname "/"))
(tramp-error vec 'file-error "Filename must contain a WebDAV share"))
......@@ -1856,7 +1860,7 @@ connection if a previous connection has died for some reason."
;; The call must be asynchronously, because of the "askPassword"
;; or "askQuestion" callbacks.
(if (string-match "(so)$" tramp-gvfs-mountlocation-signature)
(if (string-match-p "(so)$" tramp-gvfs-mountlocation-signature)
(with-tramp-dbus-call-method vec nil
:session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
tramp-gvfs-interface-mounttracker tramp-gvfs-mountlocation
......
This diff is collapsed.
......@@ -677,7 +677,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
(when match
(setq result
(delete nil
(mapcar (lambda (x) (when (string-match match x) x))
(mapcar (lambda (x) (when (string-match-p match x) x))
result))))
;; Append directory.
(when full
......@@ -728,10 +728,10 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
(widen)
(tramp-message vec 10 "\n%s" (buffer-string))
(goto-char (point-min))
(while (and (not (eobp)) (not (looking-at "^REVISION:")))
(while (and (not (eobp)) (not (looking-at-p "^REVISION:")))
(forward-line)
(delete-region (point-min) (point)))
(while (and (not (eobp)) (looking-at "^.+:.+"))
(while (and (not (eobp)) (looking-at-p "^.+:.+"))
(forward-line))
(delete-region (point) (point-max))
(throw 'tramp-action 'ok))))
......@@ -816,7 +816,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
;; Check result.
(when entry
(list (and (string-match "d" (nth 1 entry))
(list (and (string-match-p "d" (nth 1 entry))
t) ;0 file type
-1 ;1 link count
uid ;2 uid
......@@ -933,15 +933,14 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
filename
(with-parsed-tramp-file-name (expand-file-name directory) nil
(with-tramp-file-property v localname "file-name-all-completions"
(save-match-data
(delete-dups
(mapcar
(lambda (x)
(list
(if (string-match "d" (nth 1 x))
(file-name-as-directory (nth 0 x))
(nth 0 x))))
(tramp-smb-get-file-entries directory))))))))
(delete-dups
(mapcar
(lambda (x)
(list
(if (string-match-p "d" (nth 1 x))
(file-name-as-directory (nth 0 x))
(nth 0 x))))
(tramp-smb-get-file-entries directory)))))))
(defun tramp-smb-handle-file-system-info (filename)
"Like `file-system-info' for Tramp files."
......@@ -956,9 +955,10 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
(goto-char (point-min))
(forward-line)
(when (looking-at
(concat "[[:space:]]*\\([[:digit:]]+\\)"
" blocks of size \\([[:digit:]]+\\)"
"\\. \\([[:digit:]]+\\) blocks available"))
(eval-when-compile
(concat "[[:space:]]*\\([[:digit:]]+\\)"
" blocks of size \\([[:digit:]]+\\)"
"\\. \\([[:digit:]]+\\) blocks available")))
(setq blocksize (string-to-number (match-string 2))
total (* blocksize (string-to-number (match-string 1)))
avail (* blocksize (string-to-number (match-string 3)))))
......@@ -975,7 +975,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
(defun tramp-smb-handle-file-writable-p (filename)
"Like `file-writable-p' for Tramp files."
(if (file-exists-p filename)
(string-match
(string-match-p
"w"
(or (tramp-compat-file-attribute-modes (file-attributes filename)) ""))
(let ((dir (file-name-directory filename)))
......@@ -1027,7 +1027,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
;; Check for matching entries.
(mapcar
(lambda (x)
(when (string-match
(when (string-match-p
(format "^%s" base) (nth 0 x))
x))
entries)
......@@ -1039,14 +1039,14 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
(sort
entries
(lambda (x y)
(if (string-match "t" switches)
(if (string-match-p "t" switches)
;; Sort by date.
(time-less-p (nth 3 y) (nth 3 x))
;; Sort by name.
(string-lessp (nth 0 x) (nth 0 y))))))
;; Handle "-F" switch.
(when (string-match "F" switches)
(when (string-match-p "F" switches)
(mapc
(lambda (x)
(when (not (zerop (length (car x))))
......@@ -1075,7 +1075,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
(expand-file-name
(nth 0 x) (file-name-directory filename))
'string)))))
(when (string-match "l" switches)
(when (string-match-p "l" switches)
(insert
(format
"%10s %3d %-8s %-8s %8s %s "
......@@ -1106,7 +1106,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
(put-text-property start (point) 'dired-filename t))
;; Insert symlink.
(when (and (string-match "l" switches)
(when (and (string-match-p "l" switches)
(stringp (tramp-compat-file-attribute-type attr)))
(insert " -> " (tramp-compat-file-attribute-type attr))))
......@@ -1121,18 +1121,17 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
(unless (file-name-absolute-p dir)
(setq dir (expand-file-name dir default-directory)))
(with-parsed-tramp-file-name dir nil
(save-match-data
(let* ((ldir (file-name-directory dir)))
;; Make missing directory parts.
(when (and parents
(tramp-smb-get-share v)
(not (file-directory-p ldir)))
(make-directory ldir parents))
;; Just do it.
(when (file-directory-p ldir)
(make-directory-internal dir))
(unless (file-directory-p dir)
(tramp-error v 'file-error "Couldn't make directory %s" dir))))))
(let* ((ldir (file-name-directory dir)))
;; Make missing directory parts.
(when (and parents
(tramp-smb-get-share v)
(not (file-directory-p ldir)))
(make-directory ldir parents))
;; Just do it.
(when (file-directory-p ldir)
(make-directory-internal dir))
(unless (file-directory-p dir)
(tramp-error v 'file-error "Couldn't make directory %s" dir)))))
(defun tramp-smb-handle-make-directory-internal (directory)
"Like `make-directory-internal' for Tramp files."
......@@ -1140,21 +1139,19 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
(unless (file-name-absolute-p directory)
(setq directory (expand-file-name directory default-directory)))
(with-parsed-tramp-file-name directory nil
(save-match-data
(let* ((file (tramp-smb-get-localname v)))
(when (file-directory-p (file-name-directory directory))
(tramp-smb-send-command
v
(if (tramp-smb-get-cifs-capabilities v)
(format "posix_mkdir \"%s\" %o" file (default-file-modes))
(format "mkdir \"%s\"" file)))
;; We must also flush the cache of the directory, because
;; `file-attributes' reads the values from there.
(tramp-flush-file-properties v (file-name-directory localname))
(tramp-flush-file-properties v localname))
(unless (file-directory-p directory)
(tramp-error
v 'file-error "Couldn't make directory %s" directory))))))
(let* ((file (tramp-smb-get-localname v)))
(when (file-directory-p (file-name-directory directory))
(tramp-smb-send-command
v
(if (tramp-smb-get-cifs-capabilities v)
(format "posix_mkdir \"%s\" %o" file (default-file-modes))
(format "mkdir \"%s\"" file)))
;; We must also flush the cache of the directory, because
;; `file-attributes' reads the values from there.
(tramp-flush-file-properties v (file-name-directory localname))
(tramp-flush-file-properties v localname))
(unless (file-directory-p directory)
(tramp-error v 'file-error "Couldn't make directory %s" directory)))))
(defun tramp-smb-handle-make-symbolic-link
(target linkname &optional ok-if-already-exists)
......@@ -1510,7 +1507,7 @@ component is used as the target of the symlink."
;; Save exit.
(with-current-buffer (tramp-get-connection-buffer v)
(if (string-match tramp-temp-buffer-name (buffer-name))
(if (string-match-p tramp-temp-buffer-name (buffer-name))
(progn
(set-process-buffer (tramp-get-connection-process v) nil)
(kill-buffer (current-buffer)))
......@@ -1621,7 +1618,7 @@ If VEC has no cifs capabilities, exchange \"/\" by \"\\\\\"."
;; A period followed by a space, or trailing periods and spaces,
;; are not supported.
(when (string-match "\\. \\|\\.$\\| $" localname)
(when (string-match-p "\\. \\|\\.$\\| $" localname)
(tramp-error
vec 'file-error
"Invalid file name %s" (tramp-make-tramp-file-name vec localname)))
......@@ -1775,7 +1772,7 @@ Result is the list (LOCALNAME MODE SIZE MTIME)."
(cl-return))
;; weekday.
(if (string-match "\\(\\w+\\)$" line)
(if (string-match-p "\\(\\w+\\)$" line)
(setq line (substring line 0 -5))
(cl-return))
......@@ -2086,7 +2083,6 @@ Returns nil if an error message has appeared."
(defun tramp-smb-call-winexe (vec)
"Apply a remote command, if possible, using `tramp-smb-winexe-program'."
;; Check for program.
(unless (executable-find tramp-smb-winexe-program)
(tramp-error
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment