forked from bcpierce00/unison
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathname.ml
61 lines (45 loc) · 1.99 KB
/
name.ml
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
53
54
55
56
57
58
59
60
61
(* Unison file synchronizer: src/name.ml *)
(* Copyright 1999-2016, Benjamin C. Pierce
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*)
(* NOTE: IF YOU CHANGE TYPE "NAME", THE ARCHIVE FORMAT CHANGES;
INCREMENT "UPDATE.ARCHIVEFORMAT" *)
type t = string
let compare n1 n2 = (Case.ops())#compare n1 n2
let eq a b = (0 = (compare a b))
let toString n = n
let fromString s =
if String.length s = 0 then
raise(Invalid_argument "Name.fromString(empty string)");
(* Make sure there are no slashes in the s *)
begin try
ignore(String.index s '/');
raise (Util.Transient (Printf.sprintf "Filename '%s' contains a '/'" s))
with Not_found -> () end;
(* We ought to consider further checks, e.g., in Windows, no colons *)
s
let hash n = (Case.ops())#hash n
let normalize n = (Case.ops())#normalizeFilename n
(****)
let badEncoding s = (Case.ops())#badEncoding s
(* Windows file naming conventions are descripted here:
<http://msdn.microsoft.com/en-us/library/aa365247(printer).aspx> *)
let badWindowsFilenameRx =
Rx.case_insensitive
(Rx.rx
"(.*[\000-\031<>:\"/\\|?*].*)|\
((con|prn|aux|nul|com[1-9]|lpt[1-9])(\\..*)?)|\
(.*[. ])")
let badWindowsFilenameRelaxedRx =
Rx.case_insensitive (Rx.rx "(con|prn|aux|nul|com[1-9]|lpt[1-9])(\\..*)?")
(* FIX: should also check for a max filename length, not sure how much *)
let badFile s = Rx.match_string badWindowsFilenameRx s