Skip to content

Instantly share code, notes, and snippets.

@katzchang
Created June 3, 2013 04:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katzchang/5696100 to your computer and use it in GitHub Desktop.
Save katzchang/5696100 to your computer and use it in GitHub Desktop.
or $ gosh -E '(use file.util)(exit (if (< 600 (- (sys-time) (file-ctime "/tmp/foo"))) 1 0))'
#!/usr/bin/env gosh
(use gauche.parseopt)
(use file.util)
(define (main args)
(let-args (cdr args)
((help "h|help" => usage)
(quiet "q|quiet" #f)
(lag "l|lag=n" 600)
(else (opt . _) (usage "Unknown option : " opt)) . rest)
(when (null? rest) (usage "wrong number of arguments. required 1, got 0."))
(if (too-much-lag? lag quiet (car rest)) 1 0)))
(define (print-err . messages)
(let1 err (current-error-port)
(for-each (^[message] (display message err))
messages)
(newline err)))
(define (usage . messages)
(let1 msg "usage: ctimelag [opt] <path>
l|lag=n => time lag in second, default:600 sec
q|quiet => quiet mode
h|help => print this usage"
(if (not (null? messages)) (apply print-err messages))
(print-err msg)
(exit 1)))
(define (too-much-lag? lag quiet path)
(let ((ctime (file-ctime path))
(sys-time (sys-time)))
(if (eq? ctime #f) (error "file not found: " path)
(let1 lag? (< lag (- sys-time ctime))
(if (not quiet)
(begin
(print 'path: path)
(print 'ctime: ctime)
(print 'sys-time: sys-time)
(print 'too-much-lag?: lag?)))
lag?))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment