/[meta-cvs]/meta-cvs/F-5E30677BF94A6FA7AD45BAA270984CFA.lisp
ViewVC logotype

Contents of /meta-cvs/F-5E30677BF94A6FA7AD45BAA270984CFA.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations)
Sun Nov 10 06:46:53 2002 UTC (11 years, 5 months ago) by kaz
Branch: MAIN
CVS Tags: mcvs-1-0-3
Changes since 1.3: +65 -29 lines
Merging from mcvs-1-0-branch.

* code/link.lisp (mcvs-link): Revamped link command to behave properly
when the destination object is a directory. It must create the link in
that directory, rather than try to create a link with that name.
Plus handles various tricky cases. Trailing slash in destination name,
destination that is a directory within target directory, attempted
link creation in MCVS etc.
1 ;;; This source file is part of the Meta-CVS program,
2 ;;; which is distributed under the GNU license.
3 ;;; Copyright 2002 Kaz Kylheku
4
5 (require "system")
6 (require "mapping")
7 (require "chatter")
8 (require "mcvs-package")
9 (provide "link")
10
11 (in-package "META-CVS")
12
13 (defun mcvs-link (target name)
14 (when (or (string= "" target)
15 (string= "" name))
16 (error "empty path names are invalid."))
17 (in-sandbox-root-dir
18 (let* ((mapping (mapping-read *mcvs-map*))
19 (real-name (sandbox-translate-path name))
20 (abs-name (real-to-abstract-path real-name))
21 (trailing-slash (string= (char name (1- (length name))) *path-sep*))
22 (file-info (no-existence-error (stat real-name)))
23 (in-map (mapping-lookup mapping abs-name))
24 (prefix-in-map (mapping-prefix-lookup mapping abs-name))
25 (is-non-dir (or in-map (and file-info (not (directory-p file-info)))))
26 (is-dir (and (not is-non-dir)
27 (or prefix-in-map (directory-p file-info) trailing-slash)))
28 (need-new-entry t))
29 (when (path-prefix-equal *mcvs-dir* abs-name)
30 (error "path ~a is in a reserved Meta-CVS area." abs-name))
31 (chatter-debug "Synchronizing.~%")
32 (mapping-synchronize)
33
34 (flet ((edit-map (entry)
35 (with-slots (path kind (tgt target)) entry
36 (chatter-debug "Clobbering existing object ~a.~%" path)
37 (unlink (abstract-to-real-path path))
38 (cond
39 ((eq kind :symlink)
40 (chatter-debug "Editing existing link.~%")
41 (setf tgt target)
42 (setf need-new-entry nil)
43 (symlink target (abstract-to-real-path path)))
44 (t (setf mapping
45 (remove entry mapping
46 :test #'eq))))))
47 (make-new-entry (abs-name)
48 (when need-new-entry
49 (chatter-debug "Making new symlink entry ~a.~%" abs-name)
50 (push (make-mapping-entry :kind :symlink
51 :id (mapping-generate-id :no-dir t :prefix "S-")
52 :path abs-name
53 :target target)
54 mapping))))
55
56 (cond
57 (in-map
58 (edit-map in-map)
59 (make-new-entry abs-name))
60 (is-dir
61 (let* ((base (basename target))
62 (real-name (canonicalize-path (path-cat real-name base)))
63 (abs-name (canonicalize-path (path-cat abs-name base)))
64 (name (path-cat name base))
65 (file-info (no-existence-error (stat real-name)))
66 (in-map (mapping-lookup mapping abs-name))
67 (prefix-in-map (mapping-prefix-lookup mapping abs-name))
68 (is-non-dir (or in-map (and file-info (not (directory-p file-info)))))
69 (is-dir (and (not is-non-dir)
70 (or prefix-in-map (directory-p file-info)))))
71 (when is-dir
72 (error "~a is a directory." name))
73 (when in-map
74 (edit-map in-map))
75 (make-new-entry abs-name)))
76 (t (make-new-entry abs-name))))
77 (mapping-write mapping *mcvs-map* :sort-map t)
78 (chatter-debug "Updating file structure.~%")
79 (mapping-update)))
80 (values))
81
82 (defun mcvs-link-wrapper (global-options command-options args)
83 (declare (ignore global-options command-options))
84 (when (/= (length args) 2)
85 (error "specify link target and link name."))
86 (mcvs-link (first args) (second args)))
87
88 (defconstant *link-help*
89 "Syntax:
90
91 mcvs link target-path name
92
93 Semantics:
94
95 Create a symbolic link with the given, pointing to the given target path.
96 Note the braindamaged reverse syntax, which is designed to be consistent
97 with the Unix ``ln'' command. To make the symbolic link @foo -> bar,
98 use ``mcvs ln bar foo''.
99
100 Another way to add links is to create a symlink, and then use the add
101 command.")

  ViewVC Help
Powered by ViewVC 1.1.5