Skip to content

Commit

Permalink
Enable customization of temporary file prefixes and suffixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pgossman committed Dec 4, 2020
1 parent 4713e60 commit 9a00ad7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/files.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 () ->
Expand Down
28 changes: 21 additions & 7 deletions src/os.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 *)
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/os.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/uicommon.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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")))

(* ---- *)
Expand Down

0 comments on commit 9a00ad7

Please sign in to comment.