Function: tramp-smb-handle-delete-directory

tramp-smb-handle-delete-directory is a byte-compiled function defined in tramp-smb.el.gz.

Signature

(tramp-smb-handle-delete-directory DIRECTORY &optional RECURSIVE TRASH)

Documentation

Like delete-directory for Tramp files.

Source Code

;; Defined in /usr/src/emacs/lisp/net/tramp-smb.el.gz
(defun tramp-smb-handle-delete-directory (directory &optional recursive trash)
  "Like `delete-directory' for Tramp files."
  (tramp-skeleton-delete-directory directory recursive trash
    (when (file-exists-p directory)
      (when recursive
	(mapc
	 (lambda (file)
	   (if (file-directory-p file)
	       (delete-directory file recursive)
	     (delete-file file)))
	 ;; We do not want to delete "." and "..".
	 (directory-files directory 'full directory-files-no-dot-files-regexp)))

      ;; We must also flush the cache of the directory, because
      ;; `file-attributes' reads the values from there.
      (tramp-flush-directory-properties v localname)
      (unless (tramp-smb-send-command
	       v (format
		  "%s \"%s\""
		  (if (tramp-smb-get-cifs-capabilities v)
		      "posix_rmdir" "rmdir")
		  (tramp-smb-get-localname v)))
	;; Error.
	(with-current-buffer (tramp-get-connection-buffer v)
	  (goto-char (point-min))
	  (search-forward-regexp tramp-smb-errors nil t)
	  (tramp-error v 'file-error "%s `%s'" (match-string 0) directory)))

      ;; "rmdir" does not report an error.  So we check ourselves.
      (when (file-exists-p directory)
	(tramp-error v 'file-error "`%s' not removed." directory)))))