annotate lisp/efs/efs-cp-p.el @ 42:8b8b7f3559a2 r19-15b104

Import from CVS: tag r19-15b104
author cvs
date Mon, 13 Aug 2007 08:54:51 +0200
parents 8fc7fe29b841
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1 ;; -*-Emacs-Lisp-*-
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4 ;; File: efs-cp-p.el
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5 ;; Release: $efs release: 1.15 $
42
8b8b7f3559a2 Import from CVS: tag r19-15b104
cvs
parents: 22
diff changeset
6 ;; Version: #Revision: 1.1 $
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
7 ;; RCS:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
8 ;; Description: Support for preserving file modtimes with copies. i.e. cp -p
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
9 ;; Author: Sandy Rutherford <sandy@ibm550.sissa.it>
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
10 ;; Created: Fri Feb 18 03:28:22 1994 by sandy on ibm550
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
11 ;; Modified: Sun Nov 27 12:17:33 1994 by sandy on gandalf
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
12 ;; Language: Emacs-Lisp
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
13 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
14 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
15
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
16 ;;; This file is part of efs. See efs.el for copyright
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
17 ;;; (it's copylefted) and warrranty (there isn't one) information.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
18
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
19 (provide 'efs-cp-p)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
20 (require 'efs)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
21
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
22 ;;;; Internal Variables
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
23
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
24 (defconst efs-cp-p-version
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
25 (concat (substring "$efs release: 1.15 $" 14 -2)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
26 "/"
42
8b8b7f3559a2 Import from CVS: tag r19-15b104
cvs
parents: 22
diff changeset
27 (substring "#Revision: 1.1 $" 11 -2)))
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
28
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
29 (defvar efs-local-timezone nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
30 ;; cache.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
31
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
32 ;;; Utility functions
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
33
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
34 (efs-define-fun efs-gmt-time ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
35 ;; Get the time as the number of seconds elapsed since midnight,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
36 ;; Jan 1, 1970, GMT. Emacs 18 doesn't have `current-time' function.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
37 (let ((time (current-time)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
38 (list (car time) (nth 1 time))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
39
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
40 (defun efs-local-time ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
41 (let ((str (current-time-string)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
42 (efs-seconds-elapsed
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
43 (string-to-int (substring str -4))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
44 (cdr (assoc (substring str 4 7) efs-month-alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
45 (string-to-int (substring str 8 10))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
46 (string-to-int (substring str 11 13))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
47 (string-to-int (substring str 14 16))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
48 0))) ; don't care about seconds
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
49
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
50 (defun efs-local-timezone ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
51 ;; Returns the local timezone as an integer. Right two digits the minutes,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
52 ;; others the hours.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
53 (or efs-local-timezone
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
54 (setq efs-local-timezone
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
55 (let* ((local (efs-local-time))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
56 (gmt (efs-gmt-time))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
57 (sign 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
58 (diff (efs-time-minus local gmt))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
59 hours minutes)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
60 ;; 2^16 is 36 hours.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
61 (if (zerop (car diff))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
62 (setq diff (nth 1 diff))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
63 (error "Weird timezone!"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
64 (setq diff (/ (- (nth 1 local) (nth 1 gmt)) 60))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
65 (setq hours (/ diff 60))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
66 (setq minutes (% diff 60))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
67 (if (< diff 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
68 (setq sign -1
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
69 hours (- hours)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
70 minutes (- minutes)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
71 ;; Round minutes
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
72 (setq minutes (* 10 (/ (+ minutes 5) 10)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
73 (if (= minutes 60)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
74 (setq hours (1+ hours)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
75 minutes 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
76 (* sign (+ (* hours 100) minutes))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
77
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
78 (defun efs-last-day-of-month (month year)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
79 ;; The last day in MONTH during YEAR.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
80 ;; Taken from calendar.el. Thanks.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
81 (if (and
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
82 (or
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
83 (and (= (% year 4) 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
84 (/= (% year 100) 0)) ; leap-year-p
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
85 (= (% year 400) 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
86 (= month 2))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
87 29
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
88 (aref [31 28 31 30 31 30 31 31 30 31 30 31] (1- month))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
89
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
90 (defun efs-make-date-local (year month day hour minutes seconds)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
91 ;; Takes a GMT date (list of integers), and returns the local time.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
92 (let* ((lzone (efs-local-timezone))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
93 (lminutes (% lzone 100))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
94 (lhour (/ lzone 100)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
95 (setq minutes (+ minutes lminutes))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
96 (cond ((> minutes 60)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
97 (setq minutes (- minutes 60)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
98 hour (1+ hour)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
99 ((< minutes 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
100 (setq minutes (+ minutes 60)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
101 hour (1- hour))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
102 (setq hour (+ lhour hour))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
103 (if (or (< hour 0) (> hour 23))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
104 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
105 (cond ((< hour 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
106 (setq hour (+ hour 24)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
107 day (1- day)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
108 ((> hour 23)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
109 (setq hour (- hour 24)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
110 day (1+ day))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
111 (if (or (zerop day) (> day
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
112 (efs-last-day-of-month month year)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
113 (cond ((zerop day)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
114 (setq month (1- month))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
115 (if (zerop month)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
116 (setq year (1- year)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
117 month 12))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
118 (setq day (efs-last-day-of-month month year)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
119 ((> day (efs-last-day-of-month month year))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
120 (setq month (1+ month)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
121 day 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
122 (if (= month 13)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
123 (setq year (1+ year)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
124 month 1)))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
125 (list year month day hour minutes seconds)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
126
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
127 ;;;; Entry function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
128
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
129 (defun efs-set-mdtm-of (filename newname &optional cont)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
130 ;; NEWNAME must be local
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
131 ;; Always works NOWAIT = 0
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
132 (let* ((parsed (efs-ftp-path filename))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
133 (host (car parsed))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
134 (user (nth 1 parsed))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
135 (file (nth 2 parsed)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
136 (if (efs-get-host-property host 'mdtm-failed)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
137 (and cont (efs-call-cont cont 'failed "" "") nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
138 (efs-send-cmd
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
139 host user
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
140 (list 'quote 'mdtm file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
141 nil nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
142 (efs-cont (result line cont-lines) (host newname cont)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
143 (if (or result
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
144 (not (string-match efs-mdtm-msgs line)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
145 (efs-set-host-property host 'mdtm-failed t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
146 (let ((time (apply 'efs-make-date-local
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
147 (mapcar 'string-to-int
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
148 (list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
149 (substring line 4 8)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
150 (substring line 8 10)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
151 (substring line 10 12)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
152 (substring line 12 14)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
153 (substring line 14 16)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
154 (substring line 16 18))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
155 (if time
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
156 (call-process "touch" nil 0 nil "-t"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
157 (format "%04d%02d%02d%02d%02d.%02d"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
158 (car time) (nth 1 time)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
159 (nth 2 time) (nth 3 time)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
160 (nth 4 time) (nth 5 time))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
161 newname))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
162 (if cont (efs-call-cont cont result line cont-lines)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
163 0))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
164
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
165 ;;; end of efs-cp-p.el