url-nfs.el 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. ;;; url-nfs.el --- NFS URL interface
  2. ;; Copyright (C) 1996-1999, 2004-2012 Free Software Foundation, Inc.
  3. ;; Keywords: comm, data, processes
  4. ;; This file is part of GNU Emacs.
  5. ;;
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;;; Code:
  18. (eval-when-compile (require 'cl))
  19. (require 'url-parse)
  20. (require 'url-file)
  21. (defvar url-nfs-automounter-directory-spec
  22. "file:/net/%h%f"
  23. "*How to invoke the NFS automounter. Certain % sequences are recognized.
  24. %h -- the hostname of the NFS server
  25. %n -- the port # of the NFS server
  26. %u -- the username to use to authenticate
  27. %p -- the password to use to authenticate
  28. %f -- the filename on the remote server
  29. %% -- a literal %
  30. Each can be used any number of times.")
  31. (defun url-nfs-unescape (format host port user pass file)
  32. (with-current-buffer (get-buffer-create " *nfs-parse*")
  33. (erase-buffer)
  34. (insert format)
  35. (goto-char (point-min))
  36. (while (re-search-forward "%\\(.\\)" nil t)
  37. (let ((escape (aref (match-string 1) 0)))
  38. (replace-match "" t t)
  39. (case escape
  40. (?% (insert "%"))
  41. (?h (insert host))
  42. (?n (insert (or port "")))
  43. (?u (insert (or user "")))
  44. (?p (insert (or pass "")))
  45. (?f (insert (or file "/"))))))
  46. (buffer-string)))
  47. (defun url-nfs-build-filename (url)
  48. (let* ((host (url-host url))
  49. (port (url-port url))
  50. (pass (url-password url))
  51. (user (url-user url))
  52. (file (url-filename url)))
  53. (url-generic-parse-url
  54. (url-nfs-unescape url-nfs-automounter-directory-spec
  55. host port user pass file))))
  56. (defun url-nfs (url callback cbargs)
  57. (url-file (url-nfs-build-filename url) callback cbargs))
  58. (defmacro url-nfs-create-wrapper (method args)
  59. `(defun ,(intern (format "url-nfs-%s" method)) ,args
  60. ,(format "NFS URL wrapper around `%s' call." method)
  61. (setq url (url-nfs-build-filename url))
  62. (and url (,(intern (format "url-file-%s" method))
  63. ,@(remove '&rest (remove '&optional args))))))
  64. (url-nfs-create-wrapper file-exists-p (url))
  65. (url-nfs-create-wrapper file-attributes (url &optional id-format))
  66. (url-nfs-create-wrapper file-symlink-p (url))
  67. (url-nfs-create-wrapper file-readable-p (url))
  68. (url-nfs-create-wrapper file-writable-p (url))
  69. (url-nfs-create-wrapper file-executable-p (url))
  70. (url-nfs-create-wrapper directory-files (url &optional full match nosort))
  71. (url-nfs-create-wrapper file-truename (url &optional counter prev-dirs))
  72. (provide 'url-nfs)
  73. ;;; url-nfs.el ends here