-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathnfs-shared.cl
52 lines (43 loc) · 1.32 KB
/
nfs-shared.cl
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
;; -*- mode: common-lisp -*-
;; See the file LICENSE for the full license governing this code.
(in-package :user)
;; This file contains stuff that is shared between the nfs server code
;; and the configuration app code.
(eval-when (compile eval load)
(require :regexp2)
(require :shell)
(use-package :excl.shell))
(defun cleanup-dir (dir)
;; n: => n:\
;; n:\src\ => n:\src
;; \\foo\bar => \\foo\bar\
;; convert forward slashes to backslashes
(setq dir (namestring (pathname dir)))
(if* (=~ "^[A-Za-z]:$" dir)
then (+= dir "\\")
elseif (=~ "([A-Za-z]:.+)\\\\$" dir)
then $1
elseif (=~ "(\\\\\\\\[^\\\\]+\\\\[^\\\\]+)$" dir)
then (+= $1 "\\")
else dir))
#+ignore
(defun test-cleanup-dir ()
(let ((cases '(
;; (expected-result input)
("n:\\" "n:")
("n:\\" "n:/")
("n:\\" "n:\\")
("n:\\src" "n:/src")
("n:\\src" "n:\\src")
("n:\\src" "n:\\src\\")
("n:\\src" "n:/src/")
("\\\\server\\share\\" "\\\\server\\share")
("\\\\server\\share\\" "\\\\server\\share\\")
("\\\\server\\share\\" "//server/share")
("\\\\server\\share\\" "//server/share/")
)))
(loop for (expected input) in cases
do (let ((got (cleanup-dir input)))
(when (string/= got expected)
(error "(cleanup-dir ~s): expected ~s, got ~s."
input expected got))))))