;;; -*- Mode:LISP; Readtable:CL; Base:10 -*-
;
; Tape software
;
; nic 6/25/85

(defun rew ()
  "Rewinds half-inch tape.  Doesn't work unless tapemaster has been initialized with some other function."
    (fs:mt-rewind))

(defun dump (directory)
  "Dumps the latest version of every file in 'directory', including subdirectories."
    (fs:copy-directory  directory "mt:" :copy-only :newest)
    (fs:mt-write-eof))

(defun restore (directory)
  "Restores a tape, prepending 'directory' to each file name.  This is going to be changed"
    (fs:restore-magtape :transform
			#'(lambda (host dir name type version)
			    (fs:make-pathname
			      :host host
			      :directory (if (stringp dir) directory (rplaca (copylist dir) directory))
			      :name name
			      :type type
			      :version version))))

(defun lf()
  "Lists all the files on a tape"
    (fs:magtape-list-files))

(defparameter *dump-list '("doug;" "israel;" "nick;" "jeff;" "ken;" "actt;" "daveh;" "claire;" "liz;" "lisa;" "adcon;" "adrs;" "basics;"))

(defun complete-dump (&optional (really-p t) &aux time)
  "Does a complete dump of everything on *dump-list, and logs it to \"nick.login;complete-dump-log.text\"
If really-p is set nil, will do the dump but not log it to the file."
  (format t "~&~%Salvaging file system ...~&")
  (fs:lm-salvage)
  (format t "~&~%Beginning dump on ~A ...~&" (setq time (time:print-current-time nil)))
  (dolist (dir *dump-list)
    (fs:copy-directory dir "mt:"
		       :copy-only :newest))
  (fs:mt-write-eof)
  (if really-p
      (with-open-file (file "nick.login;complete-dump-log.text"
			    :direction :output
			    :if-exists :append
			    :if-does-not-exist :create)
	(format file "~&~A" time)))
  (format t "~&~%Done.  Rewinding ...~&")
  (rew))

(defun incremental-dump (&aux time foo)
  "Does an incremental dump of everything on *dump-list, reading the time of the last
complete dump from  \"nick.login;complete-dump-log.text\"
If there are no files that need backup, will error out thinking the tape was stolen by slot NIL"
  (format t "~&~%Salvaging file system ...~&")
  (fs:lm-salvage)
  (with-open-file (file "nick.login;complete-dump-log.text"
			:direction :input)
    (loop until (= 0 (length (setq foo (send file :line-in)))) doing
	  (setq time foo)))
  (format t "~&~%Beginning incremental dump of everything since ~A ...~&" time)
  (dolist (dir *dump-list) 
    (fs:copy-directory dir "mt:"
		       :copy-only :newest
		       :since time))
  (fs:mt-write-eof)
  (format t "~&~%Done.  Rewinding ...~&")
  (rew))