diff --git a/src/files.ml b/src/files.ml index 25aabddef..3073b1f00 100644 --- a/src/files.ml +++ b/src/files.ml @@ -659,7 +659,7 @@ let diffCmd = ^ "Without any of these substrings, the two filenames will be appended to the command. In all " ^ "cases, the filenames are suitably quoted.") -let tempName s = Os.tempFilePrefix ^ s +let tempName s = (Os.tempFilePrefix ()) ^ s let rec diff root1 path1 ui1 root2 path2 ui2 showDiff id = debug (fun () -> diff --git a/src/os.ml b/src/os.ml index ad27e217e..8a471e4e6 100644 --- a/src/os.ml +++ b/src/os.ml @@ -39,20 +39,33 @@ let serverHostName = localCanonicalHostName let myCanonicalHostName () = if !Trace.runningasserver then serverHostName else Prefs.read clientHostName -let tempFilePrefix = ".unison." -let tempFileSuffixFixed = ".unison.tmp" -let tempFileSuffix = ref tempFileSuffixFixed +let tempFilePrefixPref : string Prefs.t = + Prefs.createString "tempfileprefix" ".unison" + "!set the prefix for temporary files" + ("When specified, all filenames of temporary files created by unison" ^ + "will begin with the set prefix.") + +let tempFileSuffixPref : string Prefs.t = + Prefs.createString "tempfilesuffix" ".unison.tmp" + "!set the suffix for temporary files" + ("When specified, all filenames of temporary files created by unison" ^ + "will end with the set suffix.") + +let tempFilePrefix () = Prefs.read tempFilePrefixPref +let tempFileSuffixFixed () = Prefs.read tempFileSuffixPref + +let tempFileSuffix = ref (tempFileSuffixFixed ()) let includeInTempNames s = (* BCP: Added this in Jan 08. If (as I believe) it never fails, then this tricky stuff can be deleted. *) assert (s<>""); tempFileSuffix := - if s = "" then tempFileSuffixFixed - else "." ^ s ^ tempFileSuffixFixed + if s = "" then (tempFileSuffixFixed ()) + else "." ^ s ^ (tempFileSuffixFixed ()) let isTempFile file = - Util.endswith file tempFileSuffixFixed && - Util.startswith file tempFilePrefix + Util.endswith file (tempFileSuffixFixed ()) && + Util.startswith file (tempFilePrefix ()) (*****************************************************************************) (* QUERYING THE FILESYSTEM *) @@ -360,4 +373,5 @@ let genTempPath fresh fspath path prefix suffix = in f 0 let tempPath ?(fresh=true) fspath path = + let tempFilePrefix = tempFilePrefix () in genTempPath fresh fspath path tempFilePrefix !tempFileSuffix diff --git a/src/os.mli b/src/os.mli index 8c08804f4..453de0489 100644 --- a/src/os.mli +++ b/src/os.mli @@ -4,7 +4,7 @@ val myCanonicalHostName : unit -> string val tempPath : ?fresh:bool -> Fspath.t -> Path.local -> Path.local -val tempFilePrefix : string +val tempFilePrefix : unit -> string val isTempFile : string -> bool val includeInTempNames : string -> unit diff --git a/src/uicommon.ml b/src/uicommon.ml index 7eb1c42ca..fe391c8ca 100644 --- a/src/uicommon.ml +++ b/src/uicommon.ml @@ -545,7 +545,7 @@ let scanProfiles () = with Not_found -> ()); (f, info)) (Safelist.filter (fun name -> not ( Util.startswith name ".#" - || Util.startswith name Os.tempFilePrefix)) + || Util.startswith name (Os.tempFilePrefix ()))) (Files.ls Util.unisonDir "*.prf"))) (* ---- *)