[Unison-hackers] [unison-svn] r452 - trunk/src
bcpierce@seas.upenn.edu
bcpierce at seas.upenn.edu
Sun May 30 11:52:12 EDT 2010
Author: bcpierce
Date: 2010-05-30 11:52:12 -0400 (Sun, 30 May 2010)
New Revision: 452
Modified:
trunk/src/RECENTNEWS
trunk/src/mkProjectInfo.ml
trunk/src/uitext.ml
Log:
* Correct a bug in the watcher startup code for remote sync
Modified: trunk/src/RECENTNEWS
===================================================================
--- trunk/src/RECENTNEWS 2010-05-30 14:42:00 UTC (rev 451)
+++ trunk/src/RECENTNEWS 2010-05-30 15:52:12 UTC (rev 452)
@@ -1,5 +1,14 @@
CHANGES FROM VERSION 2.40.16
+* Correct a bug in the watcher startup code for remote sync
+
+
+
+
+
+-------------------------------
+CHANGES FROM VERSION 2.40.16
+
* Unison now passes path arguments and --follow directives to
fsmonitor.py. This seems to work except for one small issue with
how fsmonitor.py treats --follow directives for directories that
Modified: trunk/src/mkProjectInfo.ml
===================================================================
--- trunk/src/mkProjectInfo.ml 2010-05-30 14:42:00 UTC (rev 451)
+++ trunk/src/mkProjectInfo.ml 2010-05-30 15:52:12 UTC (rev 452)
@@ -99,3 +99,4 @@
+
Modified: trunk/src/uitext.ml
===================================================================
--- trunk/src/uitext.ml 2010-05-30 14:42:00 UTC (rev 451)
+++ trunk/src/uitext.ml 2010-05-30 15:52:12 UTC (rev 452)
@@ -612,9 +612,9 @@
displayWhenInteractive "\nProceed with propagating updates? ";
selectAction
(* BCP: I find it counterintuitive that every other prompt except this one
- would expect <CR> as a default. But I got talked out of offering a default
- here, because of safety considerations (too easy to press <CR> one time
- too many). *)
+ would expect <CR> as a default. But I got talked out of offering a
+ default here, because of safety considerations (too easy to press
+ <CR> one time too many). *)
(if Prefs.read Globals.batch then Some "y" else None)
[(["y";"g"],
"Yes: proceed with updates as selected above",
@@ -696,11 +696,12 @@
(exitStatus, failedPaths)
end
+let originalValueOfPathsPreference = ref []
+
(* ----------------- Filesystem watching mode ---------------- *)
-(* FIX: we should check that the child process has not died and restart it if so... *)
-(* FIX: also, we should trap fatal errors like losing the connection with the server
- and restart if needed (restoring the original paths, etc.) *)
+(* FIX: we should check that the child process has not died and
+ restart it if so... *)
let watchinterval = 5
@@ -711,10 +712,10 @@
let watchercmd r =
(* FIX: is the quoting of --follow parameters going to work on Win32? *)
(* FIX -- need to find the program using watcherosx preference *)
- let root = Common.root2string r in
+ let root = Fspath.toString (snd r) in
let changefile = watcherTemp root "changes" in
let statefile = watcherTemp root "state" in
- let paths = Safelist.map Path.toString (Prefs.read Globals.paths) in
+ let paths = Safelist.map Path.toString !originalValueOfPathsPreference in
let followpaths = Pred.extern Path.followPred in
let follow = Safelist.map (fun s -> "--follow '"^s^"'") followpaths in
let cmd = Printf.sprintf "fsmonitor.py %s --outfile %s --statefile %s %s %s\n"
@@ -774,7 +775,8 @@
end else begin
(* Wait for change file to be built *)
debug (fun() -> Util.msg
- "Waiting for change file %s\n" (System.fspathToPrintString wi.file));
+ "Waiting for change file %s\n"
+ (System.fspathToPrintString wi.file));
[]
end
else
@@ -783,9 +785,11 @@
with Not_found -> begin
(* Watcher process not running *)
let (changefile,cmd) = watchercmd r in
- debug (fun() -> Util.msg "Starting watcher on root %s\n" (Common.root2string r));
+ debug (fun() -> Util.msg
+ "Starting watcher on root %s\n" (Common.root2string r));
let _ = System.open_process_in cmd in
- let wi = {file = changefile; ch = ref None; lines = ref []; chars = ref ""} in
+ let wi = {file = changefile; ch = ref None;
+ lines = ref []; chars = ref ""} in
watchers := RootMap.add r wi !watchers;
[]
end)
@@ -828,13 +832,12 @@
(* ----------------- Repetition ---------------- *)
let synchronizeUntilNoFailures () =
- let initValueOfPathsPreference = Prefs.read Globals.paths in
let rec loop triesLeft =
let (exitStatus,failedPaths) = synchronizeOnce() in
if failedPaths <> [] && triesLeft <> 0 then begin
loop (triesLeft - 1)
end else begin
- Prefs.set Globals.paths initValueOfPathsPreference;
+ Prefs.set Globals.paths !originalValueOfPathsPreference;
exitStatus
end in
loop (Prefs.read Uicommon.retry)
@@ -857,14 +860,25 @@
exitStatus
else begin
(* Do it again *)
- Trace.status (Printf.sprintf "\nSleeping for %d seconds...\n" repeatinterval);
+ Trace.status (Printf.sprintf
+ "\nSleeping for %d seconds...\n" repeatinterval);
Unix.sleep repeatinterval;
synchronizeUntilDone ()
end
(* ----------------- Startup ---------------- *)
-let start interface =
+let handleException e =
+ restoreTerminal();
+ let msg = Uicommon.exn2string e in
+ Trace.log (msg ^ "\n");
+ if not !Trace.sendLogMsgsToStderr then begin
+ alwaysDisplay "\n";
+ alwaysDisplay msg;
+ alwaysDisplay "\n";
+ end
+
+let rec start interface =
if interface <> Uicommon.Text then
Util.msg "This Unison binary only provides the text GUI...\n";
begin try
@@ -901,6 +915,10 @@
setWarnPrinter();
Trace.statusFormatter := formatStatus;
+ (* Save away the user's path preferences in case they are needed for
+ restarting/repeating *)
+ originalValueOfPathsPreference := Prefs.read Globals.paths;
+
let exitStatus = synchronizeUntilDone() in
(* Put the terminal back in "sane" mode, if necessary, and quit. *)
@@ -908,16 +926,22 @@
exit exitStatus
with
- e ->
- restoreTerminal();
- let msg = Uicommon.exn2string e in
- Trace.log (msg ^ "\n");
- if not !Trace.sendLogMsgsToStderr then begin
- alwaysDisplay "\n";
- alwaysDisplay msg;
- alwaysDisplay "\n";
- end;
+ Sys.Break -> begin
+ (* If we've been killed, then die *)
+ handleException Sys.Break;
exit Uicommon.fatalExit
+ end
+ | e -> begin
+ (* If any other bad thing happened and the -repeat preference is
+ set, then restart *)
+ handleException e;
+ if Prefs.read Uicommon.repeat <> "" then begin
+ Util.msg "Restarting in 10 seconds...\n";
+ Unix.sleep 10;
+ start interface
+ end else
+ exit Uicommon.fatalExit
+ end
end
let defaultUi = Uicommon.Text
More information about the Unison-hackers
mailing list