r9949: delete-directory-and-files update
[kmrcl.git] / os.lisp
diff --git a/os.lisp b/os.lisp
index 818a4da07f2f7d78508b3b3e44cbfb95acd0dfd1..5b6fff3aa3d90aad02dd8ce57fa88f25c0560f87 100644 (file)
--- a/os.lisp
+++ b/os.lisp
@@ -19,24 +19,34 @@ synchronously execute the result using a Bourne-compatible shell,
 returns (VALUES string-output error-output exit-status)"
   (let ((command (apply #'format nil control-string args)))
     #+sbcl
-    (let ((process (sb-ext:run-program  
+    (let* ((process (sb-ext:run-program  
                    "/bin/sh"
                    (list "-c" command)
-                   :input nil :output :stream :error :stream)))
+                   :input nil :output :stream :error :stream))
+          (output (read-stream-to-string (sb-impl::process-output process)))
+          (error (read-stream-to-string (sb-impl::process-error process))))
+      (close (sb-impl::process-output process))
+      (close (sb-impl::process-error process))
       (values
-       (sb-impl::process-output process)
-       (sb-impl::process-error process)
-       (sb-impl::process-exit-code process)))
+       output
+       error
+       (sb-impl::process-exit-code process)))    
+
     
     #+(or cmu scl)
-    (let ((process (ext:run-program  
-                   "/bin/sh"
-                   (list "-c" command)
-                   :input nil :output :stream :error :stream)))
+    (let* ((process (ext:run-program  
+                    "/bin/sh"
+                    (list "-c" command)
+                    :input nil :output :stream :error :stream))
+          (output (read-stream-to-string (ext::process-output process)))
+          (error (read-stream-to-string (ext::process-error process))))
+      (close (ext::process-output process))
+      (close (ext::process-error process))
+
       (values
-       (ext::process-output process)
-       (ext::process-error process)
-       (ext::process-exit-code process)))    
+       output
+       error
+       (ext::process-exit-code process)))
 
     #+allegro
     (multiple-value-bind (output error status)
@@ -125,3 +135,16 @@ returns (VALUES output-string pid)"
     (error "RUN-SHELL-PROGRAM not implemented for this Lisp")
 
     ))
+
+(defun delete-directory-and-files (dir &key (if-does-not-exist :error) (quiet t) force)
+  #+allegro (excl:delete-directory-and-files dir :if-does-not-exist if-does-not-exist
+                                            :quiet quiet :force force)
+  #-(or allegro) (declare (ignore force))
+  #-(or allegro) (cond
+                  ((probe-directory dir)
+                   (let ((cmd (format nil "rm -rf ~A" (namestring dir))))
+                     (unless quiet
+                       (format *trace-output* ";; ~A" cmd))
+                     (command-output cmd)))
+                  ((eq if-does-not-exist :error)
+                   (error "Directory ~A does not exist [delete-directory-and-files]." dir))))