repo: Use custom watcher on root folders and don't use FileSystemWatcher when it is active. #472

This commit is contained in:
Hylke Bons 2012-08-19 11:43:41 +01:00
parent 3d78fa462f
commit 632e9b7e12
2 changed files with 32 additions and 18 deletions

View file

@ -36,6 +36,8 @@ namespace SparkleLib {
public abstract class SparkleRepoBase {
public static bool UseCustomWatcher = false;
public abstract string CurrentRevision { get; }
public abstract double Size { get; }
public abstract double HistorySize { get; }
@ -149,7 +151,9 @@ namespace SparkleLib {
Status = status;
};
this.watcher = new SparkleWatcher (LocalPath);
if (!UseCustomWatcher)
this.watcher = new SparkleWatcher (LocalPath);
new Thread (() => CreateListener ()).Start ();
this.remote_timer.Elapsed += delegate {
@ -176,7 +180,8 @@ namespace SparkleLib {
public void Initialize ()
{
this.watcher.ChangeEvent += OnFileActivity;
if (!UseCustomWatcher)
this.watcher.ChangeEvent += OnFileActivity;
// Sync up everything that changed
// since we've been offline
@ -213,7 +218,9 @@ namespace SparkleLib {
return;
IsBuffering = true;
this.watcher.Disable ();
if (!UseCustomWatcher)
this.watcher.Disable ();
SparkleLogger.LogInfo ("Local", Name + " | Activity detected, waiting for it to settle...");
@ -250,7 +257,8 @@ namespace SparkleLib {
} while (IsBuffering);
this.watcher.Enable ();
if (!UseCustomWatcher)
this.watcher.Enable ();
}
@ -279,7 +287,8 @@ namespace SparkleLib {
private void SyncUpBase ()
{
this.watcher.Disable ();
if (!UseCustomWatcher)
this.watcher.Disable ();
SparkleLogger.LogInfo ("SyncUp", Name + " | Initiated");
HasUnsyncedChanges = true;
@ -299,7 +308,8 @@ namespace SparkleLib {
SparkleLogger.LogInfo ("SyncUp", Name + " | Error");
SyncDownBase ();
this.watcher.Disable ();
if (!UseCustomWatcher)
this.watcher.Disable ();
if (ServerOnline && SyncUp ()) {
HasUnsyncedChanges = false;
@ -316,13 +326,15 @@ namespace SparkleLib {
ProgressPercentage = 0.0;
ProgressSpeed = "";
this.watcher.Enable ();
if (!UseCustomWatcher)
this.watcher.Enable ();
}
private void SyncDownBase ()
{
this.watcher.Disable ();
if (!UseCustomWatcher)
this.watcher.Disable ();
SparkleLogger.LogInfo ("SyncDown", Name + " | Initiated");
@ -373,7 +385,8 @@ namespace SparkleLib {
ProgressPercentage = 0.0;
ProgressSpeed = "";
this.watcher.Enable ();
if (!UseCustomWatcher)
this.watcher.Enable ();
SyncStatusChanged (SyncStatus.Idle);
}
@ -489,7 +502,8 @@ namespace SparkleLib {
this.listener.Disconnected -= ListenerDisconnectedDelegate;
this.listener.AnnouncementReceived -= ListenerAnnouncementReceivedDelegate;
this.watcher.Dispose ();
if (!UseCustomWatcher)
this.watcher.Dispose ();
}
}
}

View file

@ -18,6 +18,7 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using MonoMac.Foundation;
using MonoMac.AppKit;
@ -68,8 +69,9 @@ namespace SparkleShare {
{
base.Initialize ();
SparkleRepoBase.UseCustomWatcher = true;
this.watcher.Changed += delegate (string path) {
// Don't even bother with paths in .git/
if (path.Contains (".git"))
return;
@ -80,18 +82,16 @@ namespace SparkleShare {
else
repo_name = path;
// Ignore changes in the root of each subfolder, these
// are already handled by the repository
if (Path.GetFileNameWithoutExtension (path).Equals (repo_name))
return;
repo_name = repo_name.Trim ("/".ToCharArray ());
FileSystemEventArgs fse_args = new FileSystemEventArgs (WatcherChangeTypes.Changed,
Path.Combine (SparkleConfig.DefaultConfig.FoldersPath, path), Path.GetFileName (path));
foreach (SparkleRepoBase repo in Repositories) {
if (repo.Name.Equals (repo_name))
repo.OnFileActivity (fse_args);
if (repo.Name.Equals (repo_name)) {
new Thread (() => {
repo.OnFileActivity (fse_args);
}).Start ();
}
}
};
}