Function: tramp-smb-handle-set-file-acl

tramp-smb-handle-set-file-acl is a byte-compiled function defined in tramp-smb.el.gz.

Signature

(tramp-smb-handle-set-file-acl FILENAME ACL-STRING)

Documentation

Like set-file-acl for Tramp files.

Source Code

;; Defined in /usr/src/emacs/lisp/net/tramp-smb.el.gz
(defun tramp-smb-handle-set-file-acl (filename acl-string)
  "Like `set-file-acl' for Tramp files."
  (ignore-errors
    (with-parsed-tramp-file-name filename nil
      (tramp-flush-file-property v localname "file-acl")

      (when (and (stringp acl-string) (executable-find tramp-smb-acl-program))
	(let* ((share     (tramp-smb-get-share v))
	       (localname (tramp-compat-string-replace
			   "\\" "/" (tramp-smb-get-localname v)))
	       (args      (list (concat "//" host "/" share) "-E" "-S"
				(tramp-compat-string-replace
				 "\n" "," acl-string)))
	       (options   tramp-smb-options))

	  (if (not (zerop (length user)))
	      (setq args (append args (list "-U" user)))
	    (setq args (append args (list "-N"))))

	  (when domain (setq args (append args (list "-W" domain))))
	  (when port   (setq args (append args (list "-p" port))))
	  (when tramp-smb-conf
	    (setq args (append args (list "-s" tramp-smb-conf))))
	  (while options
	    (setq args
		  (append args `("--option" ,(format "%s" (car options))))
		  options (cdr options)))
	  (setq
	   args
	   (append args (list (tramp-unquote-shell-quote-argument localname)
			      "&&" "echo" "tramp_exit_status" "0"
			      "||" "echo" "tramp_exit_status" "1")))

	  (unwind-protect
	      (with-temp-buffer
		;; Set the transfer process properties.
		(tramp-set-connection-property
		 v "process-name" (buffer-name (current-buffer)))
		(tramp-set-connection-property
		 v "process-buffer" (current-buffer))

		;; Use an asynchronous process.  By this, password can
		;; be handled.
		(let ((p (apply
			  #'start-process
			  (tramp-get-connection-name v)
			  (tramp-get-connection-buffer v)
			  tramp-smb-acl-program args)))

		  (tramp-message v 6 "%s" (string-join (process-command p) " "))
		  (process-put p 'vector v)
		  (process-put p 'adjust-window-size-function #'ignore)
		  (set-process-query-on-exit-flag p nil)
		  (tramp-process-actions p v nil tramp-smb-actions-set-acl)
		  ;; This is meant for traces, and returning from the
		  ;; function.  No error is propagated outside, due to
		  ;; the `ignore-errors' closure.
		  (unless (tramp-search-regexp "tramp_exit_status [[:digit:]]+")
		    (tramp-error
		     v 'file-error
		     "Couldn't find exit status of `%s'" tramp-smb-acl-program))
		  (skip-chars-forward "^ ")
		  (when (zerop (read (current-buffer)))
		    ;; Success.
		    (tramp-set-file-property v localname "file-acl" acl-string)
		    t)))

	    ;; Reset the transfer process properties.
	    (tramp-flush-connection-property v "process-name")
	    (tramp-flush-connection-property v "process-buffer")))))))