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;
};
if (!UseCustomWatcher)
this.watcher = new SparkleWatcher (LocalPath);
new Thread (() => CreateListener ()).Start ();
this.remote_timer.Elapsed += delegate {
@ -176,6 +180,7 @@ namespace SparkleLib {
public void Initialize ()
{
if (!UseCustomWatcher)
this.watcher.ChangeEvent += OnFileActivity;
// Sync up everything that changed
@ -213,6 +218,8 @@ namespace SparkleLib {
return;
IsBuffering = true;
if (!UseCustomWatcher)
this.watcher.Disable ();
SparkleLogger.LogInfo ("Local", Name + " | Activity detected, waiting for it to settle...");
@ -250,6 +257,7 @@ namespace SparkleLib {
} while (IsBuffering);
if (!UseCustomWatcher)
this.watcher.Enable ();
}
@ -279,6 +287,7 @@ namespace SparkleLib {
private void SyncUpBase ()
{
if (!UseCustomWatcher)
this.watcher.Disable ();
SparkleLogger.LogInfo ("SyncUp", Name + " | Initiated");
@ -299,6 +308,7 @@ namespace SparkleLib {
SparkleLogger.LogInfo ("SyncUp", Name + " | Error");
SyncDownBase ();
if (!UseCustomWatcher)
this.watcher.Disable ();
if (ServerOnline && SyncUp ()) {
@ -316,12 +326,14 @@ namespace SparkleLib {
ProgressPercentage = 0.0;
ProgressSpeed = "";
if (!UseCustomWatcher)
this.watcher.Enable ();
}
private void SyncDownBase ()
{
if (!UseCustomWatcher)
this.watcher.Disable ();
SparkleLogger.LogInfo ("SyncDown", Name + " | Initiated");
@ -373,6 +385,7 @@ namespace SparkleLib {
ProgressPercentage = 0.0;
ProgressSpeed = "";
if (!UseCustomWatcher)
this.watcher.Enable ();
SyncStatusChanged (SyncStatus.Idle);
@ -489,6 +502,7 @@ namespace SparkleLib {
this.listener.Disconnected -= ListenerDisconnectedDelegate;
this.listener.AnnouncementReceived -= ListenerAnnouncementReceivedDelegate;
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))
if (repo.Name.Equals (repo_name)) {
new Thread (() => {
repo.OnFileActivity (fse_args);
}).Start ();
}
}
};
}