Skip to content

Commit 9a00ad7

Browse files
committed
Enable customization of temporary file prefixes and suffixes
1 parent 4713e60 commit 9a00ad7

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

src/files.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ let diffCmd =
659659
^ "Without any of these substrings, the two filenames will be appended to the command. In all "
660660
^ "cases, the filenames are suitably quoted.")
661661

662-
let tempName s = Os.tempFilePrefix ^ s
662+
let tempName s = (Os.tempFilePrefix ()) ^ s
663663

664664
let rec diff root1 path1 ui1 root2 path2 ui2 showDiff id =
665665
debug (fun () ->

src/os.ml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,33 @@ let serverHostName = localCanonicalHostName
3939
let myCanonicalHostName () =
4040
if !Trace.runningasserver then serverHostName else Prefs.read clientHostName
4141

42-
let tempFilePrefix = ".unison."
43-
let tempFileSuffixFixed = ".unison.tmp"
44-
let tempFileSuffix = ref tempFileSuffixFixed
42+
let tempFilePrefixPref : string Prefs.t =
43+
Prefs.createString "tempfileprefix" ".unison"
44+
"!set the prefix for temporary files"
45+
("When specified, all filenames of temporary files created by unison" ^
46+
"will begin with the set prefix.")
47+
48+
let tempFileSuffixPref : string Prefs.t =
49+
Prefs.createString "tempfilesuffix" ".unison.tmp"
50+
"!set the suffix for temporary files"
51+
("When specified, all filenames of temporary files created by unison" ^
52+
"will end with the set suffix.")
53+
54+
let tempFilePrefix () = Prefs.read tempFilePrefixPref
55+
let tempFileSuffixFixed () = Prefs.read tempFileSuffixPref
56+
57+
let tempFileSuffix = ref (tempFileSuffixFixed ())
4558
let includeInTempNames s =
4659
(* BCP: Added this in Jan 08. If (as I believe) it never fails, then this tricky
4760
stuff can be deleted. *)
4861
assert (s<>"");
4962
tempFileSuffix :=
50-
if s = "" then tempFileSuffixFixed
51-
else "." ^ s ^ tempFileSuffixFixed
63+
if s = "" then (tempFileSuffixFixed ())
64+
else "." ^ s ^ (tempFileSuffixFixed ())
5265

5366
let isTempFile file =
54-
Util.endswith file tempFileSuffixFixed &&
55-
Util.startswith file tempFilePrefix
67+
Util.endswith file (tempFileSuffixFixed ()) &&
68+
Util.startswith file (tempFilePrefix ())
5669

5770
(*****************************************************************************)
5871
(* QUERYING THE FILESYSTEM *)
@@ -360,4 +373,5 @@ let genTempPath fresh fspath path prefix suffix =
360373
in f 0
361374

362375
let tempPath ?(fresh=true) fspath path =
376+
let tempFilePrefix = tempFilePrefix () in
363377
genTempPath fresh fspath path tempFilePrefix !tempFileSuffix

src/os.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
val myCanonicalHostName : unit -> string
55

66
val tempPath : ?fresh:bool -> Fspath.t -> Path.local -> Path.local
7-
val tempFilePrefix : string
7+
val tempFilePrefix : unit -> string
88
val isTempFile : string -> bool
99
val includeInTempNames : string -> unit
1010

src/uicommon.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ let scanProfiles () =
545545
with Not_found -> ());
546546
(f, info))
547547
(Safelist.filter (fun name -> not ( Util.startswith name ".#"
548-
|| Util.startswith name Os.tempFilePrefix))
548+
|| Util.startswith name (Os.tempFilePrefix ())))
549549
(Files.ls Util.unisonDir "*.prf")))
550550

551551
(* ---- *)

0 commit comments

Comments
 (0)