-
Notifications
You must be signed in to change notification settings - Fork 12
/
update-client-version.lisp
57 lines (50 loc) · 2.21 KB
/
update-client-version.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
;;;; update-client-version.lisp
(in-package #:quicklisp-controller)
(defvar *client-directory* "~/src/quicklisp-client/")
(defun client-pathname (pathname)
(merge-pathnames pathname *client-directory*))
(defun old-client-version ()
(with-open-file (stream (client-pathname "version.txt"))
(values (read-line stream))))
(defun new-client-version (&optional (step 0))
(multiple-value-bind (second minute hour day month year)
(get-decoded-time)
(declare (ignore second minute hour))
(format nil "~4,'0D~2,'0D~2,'0D~2,'0D"
year month day step)))
(defun replace-version (old-version new-version string)
(let ((pos (search old-version string)))
(when pos
(replace string new-version :start1 pos)
string)))
(defun update-file-versions (old-version new-version file)
(let ((temp-file (make-pathname :name (format nil "~A-version"
(pathname-name file))
:defaults file))
(dirty nil))
(unwind-protect
(with-open-file (instream file)
(with-open-file (outstream temp-file :direction :output
:if-exists :error)
(loop for line = (read-line instream nil)
while line do
(let ((replacement (replace-version old-version new-version
line)))
(when replacement
(setf dirty t
line replacement))
(write-line line outstream))))
(when dirty
(rename-file temp-file file))
(values file dirty))
(when (probe-file temp-file)
(delete-file temp-file)))))
(defun update-client-versions (&optional (step 0))
(let ((files (list* (client-pathname "version.txt")
(client-pathname "quicklisp.asd")
(directory (merge-pathnames "*.lisp"
*client-directory*))))
(old-version (old-client-version))
(new-version (new-client-version step)))
(dolist (file files)
(update-file-versions old-version new-version file))))