Remove useless comments from SPLIT-SEQUENCE.
[iolib.git] / net.sockets / namedb / file-monitor.lisp
blob0b0d79d62cfb2c4342a69e3a017c8e9985b209c3
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; indent-tabs-mode: nil -*-
2 ;;;
3 ;;; file-monitor.lisp --- Monitor files on disk.
4 ;;;
6 (in-package :net.sockets)
8 (defclass file-monitor ()
9 ((file :initform (error "Must supply a file name")
10 :initarg :file :accessor file-of)
11 (timestamp :initarg :timestamp :accessor timestamp-of)
12 (update-fn :initarg :update-fn :accessor update-fn-of)
13 (lock :initarg :lock :accessor lock-of))
14 (:default-initargs :timestamp 0))
16 (defmethod print-object ((monitor file-monitor) stream)
17 (print-unreadable-object (monitor stream :type nil :identity nil)
18 (format stream "File monitor for ~S" (file-of monitor))))
20 (defun monitor-oldp (monitor)
21 (declare (type file-monitor monitor))
22 (let ((mtime (file-write-date (file-of monitor))))
23 (values (< (timestamp-of monitor) mtime)
24 mtime)))
26 (defgeneric update-monitor (monitor)
27 (:method ((monitor file-monitor))
28 (bt:with-lock-held ((lock-of monitor))
29 (multiple-value-bind (oldp mtime) (monitor-oldp monitor)
30 (when oldp
31 (funcall (update-fn-of monitor) (file-of monitor))
32 (multiple-value-prog1
33 (values (timestamp-of monitor) mtime)
34 (setf (timestamp-of monitor) mtime)))))))