Parcourir la Source

Remove dependency on iolib by homebrewing WITH-CURRENT-DIRECTORY. Minor cleanups.

Brit Butler il y a 12 ans
Parent
commit
394d3d3bb8
4 fichiers modifiés avec 41 ajouts et 15 suppressions
  1. 1 1
      coleslaw.asd
  2. 12 13
      src/coleslaw.lisp
  3. 0 1
      src/packages.lisp
  4. 28 0
      src/util.lisp

+ 1 - 1
coleslaw.asd

@@ -6,7 +6,7 @@
6 6
   :author "Brit Butler <redline6561@gmail.com>"
7 7
   :pathname "src/"
8 8
   :depends-on (:alexandria :closure-template :3bmd :3bmd-ext-code-blocks
9
-               :local-time :trivial-shell :iolib.os :cl-fad)
9
+               :local-time :trivial-shell :cl-fad)
10 10
   :serial t
11 11
   :components ((:file "packages")
12 12
                (:file "config")

+ 12 - 13
src/coleslaw.lisp

@@ -39,20 +39,19 @@ If RAW is non-nil, write the content without wrapping it in the base template."
39 39
 (defgeneric deploy (staging)
40 40
   (:documentation "Deploy the STAGING dir, updating the .prev and .curr symlinks.")
41 41
   (:method (staging)
42
-    (flet ((deploy-path (path &rest args)
43
-             (merge-pathnames (apply 'format nil path args) (deploy *config*))))
44
-      (let ((new-build (deploy-path "generated/~a" (get-universal-time)))
45
-            (prev (deploy-path ".prev"))
46
-            (curr (deploy-path ".curr")))
42
+    (with-current-directory coleslaw-conf:*basedir*
43
+      (let* ((coleslaw-conf:*basedir* (deploy *config*))
44
+             (new-build (app-path "generated/~a" (get-universal-time)))
45
+             (prev (app-path ".prev"))
46
+             (curr (app-path ".curr")))
47 47
         (ensure-directories-exist new-build)
48
-        (with-current-directory coleslaw-conf:*basedir*
49
-          (run-program "mv ~a ~a" staging new-build)
50
-          (if (and (probe-file prev) (equal prev (truename prev)))
51
-              (delete-file prev)
52
-              (cl-fad:delete-directory-and-files (truename prev)))
53
-          (when (probe-file curr)
54
-            (update-symlink prev (truename curr)))
55
-          (update-symlink curr new-build))))))
48
+        (run-program "mv ~a ~a" staging new-build)
49
+        (if (and (probe-file prev) (equal prev (truename prev)))
50
+            (delete-file prev)
51
+            (cl-fad:delete-directory-and-files (truename prev)))
52
+        (when (probe-file curr)
53
+          (update-symlink prev (truename curr)))
54
+        (update-symlink curr new-build)))))
56 55
 
57 56
 (defun main ()
58 57
   "Load the user's config, then compile and deploy the blog."

+ 0 - 1
src/packages.lisp

@@ -1,7 +1,6 @@
1 1
 (defpackage :coleslaw
2 2
   (:documentation "Homepage: <a href=\"http://github.com/redline6561/coleslaw\">Github</a>")
3 3
   (:use :cl :closure-template)
4
-  (:import-from :iolib.os #:with-current-directory)
5 4
   (:import-from :alexandria #:hash-table-values
6 5
                             #:make-keyword)
7 6
   (:export #:main

+ 28 - 0
src/util.lisp

@@ -24,3 +24,31 @@ on files that match the given extension."
24 24
                  (when (and ,ext (string= ,ext ,extension))
25 25
                    ,@body)))
26 26
              `,body))))
27
+
28
+(defun current-directory ()
29
+  "Return the operating system's current directory."
30
+  #+sbcl (sb-posix:getcwd)
31
+  #+ccl (current-directory)
32
+  #+ecl (si:getcwd)
33
+  #+cmucl (unix:unix-current-directory)
34
+  #+clisp (ext:cd)
35
+  #-(or sbcl ccl ecl cmucl clisp) (error "Not implemented yet."))
36
+
37
+(defun (setf current-directory) (path)
38
+  "Change the operating system's current directory to PATH."
39
+  #+sbcl (sb-posix:chdir pathspec)
40
+  #+ccl (setf (current-directory) pathspec)
41
+  #+ecl (si:chdir pathspec)
42
+  #+cmucl (unix:unix-chdir (namestring pathspec))
43
+  #+clisp (ext:cd pathspec)
44
+  #-(or sbcl ccl ecl cmucl clisp) (error "Not implemented yet."))
45
+
46
+(defmacro with-current-directory (to-path &body body)
47
+  "Change the current OS directory to TO-PATH and execute BODY in
48
+an UNWIND-PROTECT, then change back to the current directory."
49
+  (alexandria:with-gensyms (old)
50
+    `(let ((,old (current-directory)))
51
+       (unwind-protect (progn
52
+                         (setf (current-directory) ,to-path)
53
+                         ,@body)
54
+         (setf (current-directory) ,old)))))