1
#| remote-util.jl -- Remote file access common functions
3
$Id: utils.jl,v 1.5 2000/09/08 14:57:47 john Exp $
5
Copyright (C) 1998 John Harper <john@dcs.warwick.ac.uk>
7
This file is part of Jade.
9
Jade is free software; you can redistribute it and/or modify it
10
under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 2, or (at your option)
14
Jade is distributed in the hope that it will be useful, but
15
WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
19
You should have received a copy of the GNU General Public License
20
along with Jade; see the file COPYING. If not, write to
21
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24
(define-structure rep.io.file-handlers.remote.utils
26
(export remote-get-user
29
remote-register-file-handle)
36
(defvar remote-host-user-alist nil
37
"Alist of (HOST-REGEXP . USER-NAME) matching host names to usernames.
38
Only used when no username is given in a filename.")
40
(defvar remote-default-user (user-login-name)
41
"Default username to use for file-transfer when none is specified, either
42
explicitly, or by the remote-ftp-host-user-alist variable.")
44
;; Remote filename syntax
45
(defconst remote-file-regexp "^/(([a-zA-Z0-9._-]+)@)?([a-zA-Z0-9._-]+):")
47
;; guards remote file handles (closes them if necessary)
48
(define remote-fh-guardian (make-guardian))
50
(defun remote-get-user (host)
51
(or (cdr (assoc-regexp host remote-host-user-alist)) remote-default-user))
53
;; Return (USER-OR-NIL HOST FILE)
54
(defun remote-split-filename (filename)
55
(unless (string-match remote-file-regexp filename)
56
(error "Malformed remote file specification: %s" filename))
58
((host (substring filename (match-start 3) (match-end 3)))
59
(file (substring filename (match-end))))
62
(substring filename (match-start 2) (match-end 2)))
65
;; Create a remote file name. USER may be nil
66
(defun remote-join-filename (user host file)
67
(concat ?/ (and user (concat user ?@)) host ?: file))
69
(defun remote-register-file-handle (fh)
70
(remote-fh-guardian fh))
72
(defun remote-after-gc ()
73
(do ((fh (remote-fh-guardian) (remote-fh-guardian)))
75
(when (file-binding fh)
78
(add-hook 'after-gc-hook remote-after-gc))