diff options
author | Rob Bresalier <rbresalier@gmail.com> | 2016-12-12 02:42:21 +0000 |
---|---|---|
committer | Rob Bresalier <rbresalier@gmail.com> | 2016-12-12 02:42:21 +0000 |
commit | d79476dbe7f323772c77e698f1ecffba1757cc2b (patch) | |
tree | e88426428a19c892aa34c5ada187775ca16b1170 /src | |
parent | 89914e4de5b621a6f808fdd9b33249e7cd893a7f (diff) | |
download | unison-d79476dbe7f323772c77e698f1ecffba1757cc2b.zip unison-d79476dbe7f323772c77e698f1ecffba1757cc2b.tar.gz unison-d79476dbe7f323772c77e698f1ecffba1757cc2b.tar.bz2 |
Rename the DANGER.README file just before deleting it because a virus scanner may not have it deleted by the time DANGER.README is deleted again for the next file.
Diffstat (limited to 'src')
-rw-r--r-- | src/files.ml | 15 | ||||
-rw-r--r-- | src/os.ml | 9 | ||||
-rw-r--r-- | src/os.mli | 1 | ||||
-rw-r--r-- | src/ubase/util.ml | 6 | ||||
-rw-r--r-- | src/ubase/util.mli | 1 |
5 files changed, 24 insertions, 8 deletions
diff --git a/src/files.ml b/src/files.ml index 3728c92..92dead6 100644 --- a/src/files.ml +++ b/src/files.ml @@ -46,11 +46,20 @@ let writeCommitLog source target tempname = Printf.fprintf c "(and delete this notice when you've done so).\n"; close_out c) -let clearCommitLog () = +let clearCommitLog pathTo = debug (fun() -> (Util.msg "Deleting commit log\n")); + + let tmpPathDir = Fspath.canonize (Some Util.homeDirStr) in (* tmpPathDir is a Fspath.t *) + (* Use pathTo in the temporary name (instead of DANGER.README) to reduce chance of reuse *) + let tmpPath = Os.tempPath tmpPathDir pathTo in (* tmpPath is a Path.local *) + let dangerFspath = Fspath.canonize (Some (System.fspathToString commitLogName)) in + let dangerFsPathTmp = Fspath.concat tmpPathDir tmpPath in + + Os.renameFspath "DANGER.README" dangerFspath dangerFsPathTmp; + Util.convertUnixErrorsToFatal "clearing commit log" - (fun () -> System.unlink commitLogName) + (fun () -> System.unlink (System.fspathFromString (Fspath.toString dangerFsPathTmp)) ) let processCommitLog () = if System.file_exists commitLogName then begin @@ -280,7 +289,7 @@ let performRename fspathTo localPathTo workingDir pathFrom pathTo prevArch = (Fspath.toDebugString target)); Os.rename "renameLocal(2)" source Path.empty target Path.empty)) - (fun _ -> clearCommitLog()); + (fun _ -> clearCommitLog pathTo); (* It is ok to leave a temporary file. So, the log can be cleared before deleting it. *) Os.delete temp Path.empty @@ -185,10 +185,8 @@ and delete fspath path = | `ABSENT -> ()) -let rename fname sourcefspath sourcepath targetfspath targetpath = - let source = Fspath.concat sourcefspath sourcepath in +let renameFspath fname source target = let source' = Fspath.toPrintString source in - let target = Fspath.concat targetfspath targetpath in let target' = Fspath.toPrintString target in if source = target then raise (Util.Transient ("Rename ("^fname^"): identical source and target " ^ source')); @@ -205,6 +203,11 @@ let rename fname sourcefspath sourcepath targetfspath targetpath = Fs.unlink targetDouble end) +let rename fname sourcefspath sourcepath targetfspath targetpath = + let source = Fspath.concat sourcefspath sourcepath in + let target = Fspath.concat targetfspath targetpath in + renameFspath fname source target + let symlink = if Util.isCygwin || (Util.osType != `Win32) then fun fspath path l -> @@ -18,6 +18,7 @@ val childrenOf : Fspath.t -> Path.local -> Name.t list val readLink : Fspath.t -> Path.local -> string val symlink : Fspath.t -> Path.local -> string -> unit +val renameFspath : string -> Fspath.t -> Fspath.t -> unit val rename : string -> Fspath.t -> Path.local -> Fspath.t -> Path.local -> unit val createDir : Fspath.t -> Path.local -> Props.t -> unit val delete : Fspath.t -> Path.local -> unit diff --git a/src/ubase/util.ml b/src/ubase/util.ml index 656b3d3..ba8aa03 100644 --- a/src/ubase/util.ml +++ b/src/ubase/util.ml @@ -425,8 +425,7 @@ let padto n s = s ^ (String.make (max 0 (n - String.length s)) ' ') (* Building pathnames in the user's home dir *) (*****************************************************************************) -let homeDir () = - System.fspathFromString +let homeDirStr = (if (osType = `Unix) || isCygwin then safeGetenv "HOME" else if osType = `Win32 then @@ -444,6 +443,9 @@ let homeDir () = else assert false (* osType can't be anything else *)) +let homeDir () = + System.fspathFromString homeDirStr + let fileInHomeDir n = System.fspathConcat (homeDir ()) n (*****************************************************************************) diff --git a/src/ubase/util.mli b/src/ubase/util.mli index 59b5d61..103e10c 100644 --- a/src/ubase/util.mli +++ b/src/ubase/util.mli @@ -79,6 +79,7 @@ val percentageOfTotal : val monthname : int -> string val percent2string : float -> string val fileInHomeDir : string -> System.fspath +val homeDirStr : string (* Just like the versions in the Unix module, but raising Transient instead of Unix_error *) |