Skip to content

Commit af8669b

Browse files
authored
Merge pull request #757 from tleedjarv/system-win
Reduce the amount of Windows-specific code in the System module
2 parents 08dbd39 + a3b9c79 commit af8669b

40 files changed

+308
-1005
lines changed

src/.depend

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ fileinfo.cmx : \
205205
fileinfo.cmi
206206
fileinfo.cmi : \
207207
ubase/umarshal.cmi \
208-
system.cmi \
209208
props.cmi \
210209
ubase/prefs.cmi \
211210
path.cmi \
@@ -275,7 +274,6 @@ files.cmx : \
275274
files.cmi
276275
files.cmi : \
277276
uutil.cmi \
278-
system.cmi \
279277
props.cmi \
280278
path.cmi \
281279
lwt/lwt_util.cmi \
@@ -338,17 +336,18 @@ fpcache.cmx : \
338336
fileinfo.cmx \
339337
fpcache.cmi
340338
fpcache.cmi : \
341-
system.cmi \
342339
props.cmi \
343340
path.cmi \
344341
osx.cmi \
345342
os.cmi \
346343
fspath.cmi \
347344
fileinfo.cmi
348345
fs.cmo : \
346+
system.cmi \
349347
fspath.cmi \
350348
fs.cmi
351349
fs.cmx : \
350+
system.cmx \
352351
fspath.cmx \
353352
fs.cmi
354353
fs.cmi : \
@@ -431,7 +430,6 @@ fspath.cmx : \
431430
fspath.cmi
432431
fspath.cmi : \
433432
ubase/umarshal.cmi \
434-
system.cmi \
435433
path.cmi \
436434
name.cmi
437435
fswatch.cmo : \
@@ -555,8 +553,7 @@ lock.cmx : \
555553
ubase/util.cmx \
556554
system.cmx \
557555
lock.cmi
558-
lock.cmi : \
559-
system.cmi
556+
lock.cmi :
560557
lwt/example/editor.cmo : \
561558
lwt/lwt_unix.cmi
562559
lwt/example/editor.cmx : \
@@ -598,9 +595,11 @@ lwt/pqueue.cmx : \
598595
lwt/pqueue.cmi
599596
lwt/pqueue.cmi :
600597
lwt/win/lwt_unix_impl.cmo : \
598+
system/system_win.cmo \
601599
lwt/pqueue.cmi \
602600
lwt/lwt.cmi
603601
lwt/win/lwt_unix_impl.cmx : \
602+
system/system_win.cmx \
604603
lwt/pqueue.cmx \
605604
lwt/lwt.cmx
606605
lwt/win/lwt_win.cmo : \
@@ -711,7 +710,6 @@ osx.cmo : \
711710
ubase/util.cmi \
712711
ubase/umarshal.cmi \
713712
ubase/trace.cmi \
714-
system.cmi \
715713
ubase/safelist.cmi \
716714
ubase/prefs.cmi \
717715
path.cmi \
@@ -725,7 +723,6 @@ osx.cmx : \
725723
ubase/util.cmx \
726724
ubase/umarshal.cmx \
727725
ubase/trace.cmx \
728-
system.cmx \
729726
ubase/safelist.cmx \
730727
ubase/prefs.cmx \
731728
path.cmx \
@@ -868,10 +865,8 @@ remote.cmo : \
868865
lwt/lwt_unix.cmi \
869866
lwt/lwt.cmi \
870867
fspath.cmi \
871-
fs.cmi \
872868
common.cmi \
873869
clroot.cmi \
874-
case.cmi \
875870
bytearray.cmi \
876871
remote.cmi
877872
remote.cmx : \
@@ -888,10 +883,8 @@ remote.cmx : \
888883
lwt/lwt_unix.cmx \
889884
lwt/lwt.cmx \
890885
fspath.cmx \
891-
fs.cmx \
892886
common.cmx \
893887
clroot.cmx \
894-
case.cmx \
895888
bytearray.cmx \
896889
remote.cmi
897890
remote.cmi : \
@@ -998,21 +991,15 @@ system/system_intf.cmo : \
998991
system/system_intf.cmx : \
999992
ubase/umarshal.cmx
1000993
system/system_win.cmo : \
1001-
unicode.cmi \
1002-
ubase/umarshal.cmi \
1003994
system/system_generic.cmo \
1004995
ubase/rx.cmi
1005996
system/system_win.cmx : \
1006-
unicode.cmx \
1007-
ubase/umarshal.cmx \
1008997
system/system_generic.cmx \
1009998
ubase/rx.cmx
1010999
system/win/system_impl.cmo : \
1011-
system/system_win.cmo \
1012-
system/system_generic.cmo
1000+
system/system_win.cmo
10131001
system/win/system_impl.cmx : \
1014-
system/system_win.cmx \
1015-
system/system_generic.cmx
1002+
system/system_win.cmx
10161003
terminal.cmo : \
10171004
ubase/util.cmi \
10181005
system.cmi \
@@ -1174,8 +1161,7 @@ ubase/prefs.cmx : \
11741161
ubase/prefs.cmi
11751162
ubase/prefs.cmi : \
11761163
ubase/util.cmi \
1177-
ubase/umarshal.cmi \
1178-
system.cmi
1164+
ubase/umarshal.cmi
11791165
ubase/projectInfo.cmo :
11801166
ubase/projectInfo.cmx :
11811167
ubase/proplist.cmo : \
@@ -1241,8 +1227,7 @@ ubase/util.cmx : \
12411227
ubase/safelist.cmx \
12421228
ubase/projectInfo.cmx \
12431229
ubase/util.cmi
1244-
ubase/util.cmi : \
1245-
system.cmi
1230+
ubase/util.cmi :
12461231
ui.cmi :
12471232
uicommon.cmo : \
12481233
xferhint.cmi \

src/Makefile.OCaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ OCAMLOBJS += \
219219
ubase/rx.cmo \
220220
\
221221
unicode_tables.cmo unicode.cmo bytearray.cmo \
222-
$(WINOBJS) system/system_generic.cmo \
222+
system/system_generic.cmo $(WINOBJS) \
223223
system/$(SYSTEM)/system_impl.cmo \
224224
system.cmo \
225225
\

src/case.ml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ let unicode =
4848
"When set to {\\tt true}, this flag causes Unison to perform \
4949
case insensitive file comparisons assuming Unicode encoding. \
5050
This is the default. When the flag is set to {\\tt false}, \
51-
a Latin 1 encoding is assumed. When Unison runs in case sensitive \
52-
mode, this flag only makes a difference if one host is running \
53-
Windows or Mac OS X. Under Windows, the flag selects between using \
54-
the Unicode or 8bit Windows API for accessing the filesystem. \
51+
Latin 1 encoding is assumed (this means that all bytes that are \
52+
not letters in Latin 1 encoding will be compared byte-for-byte, \
53+
even if they may be valid characters in some other encoding). \
54+
When Unison runs in case sensitive mode, this flag only makes \
55+
a difference if one host is running Mac OS X. \
5556
Under Mac OS X, it selects whether comparing the filenames up to \
5657
decomposition, or byte-for-byte."
5758

@@ -64,8 +65,6 @@ let useUnicode () =
6465
let pref = Prefs.read unicode in
6566
pref = `True || pref = `Default
6667

67-
let useUnicodeAPI = useUnicode
68-
6968
let unicodeCaseSensitive =
7069
Prefs.createBool "unicodeCS" false
7170
~category:(`Internal `Pseudo)

src/case.mli

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
val caseInsensitiveMode : [`True|`False|`Default] Prefs.t
55
val unicodeEncoding : bool Prefs.t
6-
val useUnicodeAPI : unit -> bool
76

87
type mode = Sensitive | Insensitive | UnicodeSensitive | UnicodeInsensitive
98

src/fileinfo.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ val get : bool (* fromRoot *) -> Fspath.t -> Path.local -> t
1717
val set : Fspath.t -> Path.local ->
1818
[`Set of Props.t | `Copy of Path.local | `Update of Props.t] ->
1919
Props.t -> unit
20-
val get' : System.fspath -> t
20+
val get' : string -> t
2121

2222
(* IF THIS CHANGES, MAKE SURE TO INCREMENT THE ARCHIVE VERSION NUMBER! *)
2323
type stamp251 =

src/files.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ let clearCommitLog tmpName =
5151

5252
let commitLogNameWin () =
5353
(* Work around an issue in Windows where unlink may not be immediate. *)
54-
let p = System.fspathAddSuffixToFinalName commitLogName (Filename.basename (Path.toString tmpName)) in
54+
let p = commitLogName ^ (Filename.basename (Path.toString tmpName)) in
5555
let rec tmp n =
56-
let p = System.fspathAddSuffixToFinalName p (string_of_int n) in
56+
let p = p ^ (string_of_int n) in
5757
if System.file_exists p then tmp (n + 1)
5858
else (System.rename commitLogName p; p)
5959
in
@@ -74,7 +74,7 @@ let processCommitLog () =
7474
"Warning: the previous run of %s terminated in a dangerous state.
7575
Please consult the file %s, delete it, and try again."
7676
Uutil.myName
77-
(System.fspathToPrintString commitLogName)))
77+
commitLogName))
7878
end else
7979
Lwt.return ()
8080

src/files.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ val diff :
6868
val processCommitLogs : unit -> unit
6969

7070
(* List the files in a directory matching a pattern. *)
71-
val ls : System.fspath -> string -> string list
71+
val ls : string -> string -> string list
7272

7373
val merge :
7474
Common.root (* first root *)

src/fpcache.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
(* Copyright 1999-2020, Benjamin C. Pierce (see COPYING for details) *)
33

44
(* Initialize the cache *)
5-
val init : bool -> bool -> System.fspath -> unit
5+
val init : bool -> bool -> string -> unit
66

77
(* Close the cache file and clear the in-memory cache *)
88
val finish : unit -> unit

src/fs.ml

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,48 +15,50 @@
1515
along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*)
1717

18-
module System = System_impl.Fs
19-
2018
type fspath = Fspath.t
2119
let mfspath = Fspath.m
2220
type dir_handle = System.dir_handle
2321
= { readdir : unit -> string; closedir : unit -> unit }
2422

25-
let symlink l f = System.symlink l (Fspath.toString f)
23+
let path p = Fspath.toString p |> System.extendedPath
24+
25+
(****)
2626

27-
let readlink f = System.readlink (Fspath.toString f)
27+
let symlink l f = System.symlink l (path f)
2828

29-
let chown f usr grp = System.chown (Fspath.toString f) usr grp
29+
let readlink f = System.readlink (path f)
3030

31-
let chmod f mode = System.chmod (Fspath.toString f) mode
31+
let chown f usr grp = System.chown (path f) usr grp
3232

33-
let utimes f t1 t2 = System.utimes (Fspath.toString f) t1 t2
33+
let chmod f mode = System.chmod (path f) mode
3434

35-
let unlink f = System.unlink (Fspath.toString f)
35+
let utimes f t1 t2 = System.utimes (path f) t1 t2
3636

37-
let rmdir f = System.rmdir (Fspath.toString f)
37+
let unlink f = System.unlink (path f)
3838

39-
let mkdir f mode = System.mkdir (Fspath.toString f) mode
39+
let rmdir f = System.rmdir (path f)
4040

41-
let rename f f' = System.rename (Fspath.toString f) (Fspath.toString f')
41+
let mkdir f mode = System.mkdir (path f) mode
4242

43-
let stat f = System.stat (Fspath.toString f)
43+
let rename f f' = System.rename (path f) (path f')
4444

45-
let lstat f = System.lstat (Fspath.toString f)
45+
let stat f = System.stat (path f)
4646

47-
let openfile f flags perms = System.openfile (Fspath.toString f) flags perms
47+
let lstat f = System.lstat (path f)
4848

49-
let opendir f = System.opendir (Fspath.toString f)
49+
let openfile f flags perms = System.openfile (path f) flags perms
50+
51+
let opendir f = System.opendir (path f)
5052

5153
let open_in_gen flags mode f =
52-
System.open_in_gen flags mode (Fspath.toString f)
54+
System.open_in_gen flags mode (path f)
5355

5456
let open_out_gen flags mode f =
55-
System.open_out_gen flags mode (Fspath.toString f)
57+
System.open_out_gen flags mode (path f)
5658

5759
(****)
5860

59-
let open_in_bin f = open_in_gen [Open_rdonly; Open_binary] 0 f
61+
let open_in_bin f = System.open_in_bin (path f)
6062

6163
let file_exists f =
6264
try
@@ -66,11 +68,8 @@ let file_exists f =
6668

6769
(****)
6870

69-
let fingerprint f = System.fingerprint (Fspath.toString f)
71+
let fingerprint f = System.fingerprint (path f)
7072

71-
let canSetTime f = System.canSetTime (Fspath.toString f)
7273
let hasInodeNumbers () = System.hasInodeNumbers ()
7374
let hasSymlink () = System.hasSymlink ()
7475
let hasCorrectCTime = System.hasCorrectCTime
75-
76-
let setUnicodeEncoding = System.setUnicodeEncoding

src/fs.mli

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,3 @@
44
(* Operations on fspaths *)
55

66
include System_intf.Core with type fspath = Fspath.t
7-
8-
val setUnicodeEncoding : bool -> unit

src/fsmonitor/windows/watcher.ml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ let get_win_path root dir ((ev_path, act) as ev) =
8888
let p = if event_kind ev = `DEL then None else
8989
follow_win_path dir (Lwt_win.longpathname root ev_path) 0 in
9090
match p with
91-
| Some _ as pathnm -> (pathnm, ev)
91+
| Some _ -> (p, ev)
9292
| None ->
9393
(* If path is not found or event is a deletion then look up the
9494
parent directory and report a modification on it. It is not
@@ -110,21 +110,11 @@ let flags =
110110
let watch_root_directory path dir =
111111
let h = Lwt_win.open_directory path in
112112
let path = Lwt_win.longpathname "" path in
113-
let path =
114-
if String.sub path 0 4 = "\\\\?\\" then begin
115-
let n = String.sub path 4 (String.length path - 4) in
116-
if String.sub n 0 3 = "UNC" then
117-
"\\" ^ String.sub n 3 (String.length n - 3)
118-
else
119-
n
120-
end else
121-
path
122-
in
123113
let rec loop () =
124114
Lwt_win.readdirectorychanges h true flags >>= fun l ->
125115
let time = Unix.gettimeofday () in
126116
List.iter
127-
(fun ((ev_path, _) as ev) ->
117+
(fun ev ->
128118
if !previous_event <> Some ev then begin
129119
previous_event := Some ev;
130120
if !Watchercommon.debug then print_event ev;

0 commit comments

Comments
 (0)