-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.rkt
52 lines (44 loc) · 1.19 KB
/
core.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#lang racket
(require racket/file)
(provide NOVALUE
get
put
mkdir
archive-copy
check-file-exists?
remove-extension)
;; key-value struct
(define config (make-hash))
(define NOVALUE 'NOVALUE)
(define (get key)
(define result (hash-ref config key NOVALUE))
(printf "- getting ~a: ~s~n" key result)
result
)
(define (put key value)
(hash-set! config key value))
;;;;;;;;;;;;;;;;;;;;;;;;;;
;; DEFAULTS
(put 'redundancy 30)
(put 'split-size "500M")
(put 'dry-run false)
(put 'bucket false)
(put 'temp (make-temporary-directory #:base-dir "/tmp"))
(put 'dd-path false)
(define (mkdir p)
(define path (normalize-path p))
(with-handlers ([exn? (lambda (e) e)])
(printf "mkdir: ~a~n" path)
(when (not (directory-exists? path))
(make-directory* path))))
(define (archive-copy src dst)
(let ([nsrc (normalize-path src)]
[ndst (normalize-path dst)])
(printf "copying:~n\t~a~n\t~a~n" nsrc ndst)
(copy-directory/files nsrc ndst)))
(define (check-file-exists? p)
(when (not (file-exists? p))
(printf "File does not exist: ~a~n" p))
true)
(define (remove-extension p)
(path-replace-extension (file-name-from-path p) ""))