~ubuntu-branches/ubuntu/trusty/librep/trusty

« back to all changes in this revision

Viewing changes to lisp/rep/io/file-handlers/remote/utils.jl

  • Committer: Bazaar Package Importer
  • Author(s): Christian Marillat
  • Date: 2001-11-13 15:06:22 UTC
  • Revision ID: james.westby@ubuntu.com-20011113150622-vgmgmk6srj3kldr3
Tags: upstream-0.15.2
ImportĀ upstreamĀ versionĀ 0.15.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#| remote-util.jl -- Remote file access common functions
 
2
 
 
3
   $Id: utils.jl,v 1.5 2000/09/08 14:57:47 john Exp $
 
4
 
 
5
   Copyright (C) 1998 John Harper <john@dcs.warwick.ac.uk>
 
6
 
 
7
   This file is part of Jade.
 
8
 
 
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)
 
12
   any later version.
 
13
 
 
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.
 
18
 
 
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.
 
22
|#
 
23
 
 
24
(define-structure rep.io.file-handlers.remote.utils
 
25
 
 
26
    (export remote-get-user
 
27
            remote-split-filename
 
28
            remote-join-filename
 
29
            remote-register-file-handle)
 
30
 
 
31
    (open rep
 
32
          rep.system
 
33
          rep.regexp
 
34
          rep.io.files)
 
35
 
 
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.")
 
39
 
 
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.")
 
43
 
 
44
  ;; Remote filename syntax
 
45
  (defconst remote-file-regexp "^/(([a-zA-Z0-9._-]+)@)?([a-zA-Z0-9._-]+):")
 
46
 
 
47
  ;; guards remote file handles (closes them if necessary)
 
48
  (define remote-fh-guardian (make-guardian))
 
49
 
 
50
  (defun remote-get-user (host)
 
51
    (or (cdr (assoc-regexp host remote-host-user-alist)) remote-default-user))
 
52
 
 
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))
 
57
    (let
 
58
        ((host (substring filename (match-start 3) (match-end 3)))
 
59
         (file (substring filename (match-end))))
 
60
      (list
 
61
       (and (match-start 2)
 
62
            (substring filename (match-start 2) (match-end 2)))
 
63
       host file)))
 
64
 
 
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))
 
68
 
 
69
  (defun remote-register-file-handle (fh)
 
70
    (remote-fh-guardian fh))
 
71
 
 
72
  (defun remote-after-gc ()
 
73
    (do ((fh (remote-fh-guardian) (remote-fh-guardian)))
 
74
        ((not fh))
 
75
      (when (file-binding fh)
 
76
        (close-file fh))))
 
77
 
 
78
  (add-hook 'after-gc-hook remote-after-gc))