repo: Use custom watcher on root folders and don't use FileSystemWatcher when it is active. #472
This commit is contained in:
parent
6dbc1170dd
commit
a990b5a466
|
@ -36,6 +36,8 @@ namespace SparkleLib {
|
||||||
|
|
||||||
public abstract class SparkleRepoBase {
|
public abstract class SparkleRepoBase {
|
||||||
|
|
||||||
|
public static bool UseCustomWatcher = false;
|
||||||
|
|
||||||
public abstract string CurrentRevision { get; }
|
public abstract string CurrentRevision { get; }
|
||||||
public abstract double Size { get; }
|
public abstract double Size { get; }
|
||||||
public abstract double HistorySize { get; }
|
public abstract double HistorySize { get; }
|
||||||
|
@ -149,7 +151,9 @@ namespace SparkleLib {
|
||||||
Status = status;
|
Status = status;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.watcher = new SparkleWatcher (LocalPath);
|
if (!UseCustomWatcher)
|
||||||
|
this.watcher = new SparkleWatcher (LocalPath);
|
||||||
|
|
||||||
new Thread (() => CreateListener ()).Start ();
|
new Thread (() => CreateListener ()).Start ();
|
||||||
|
|
||||||
this.remote_timer.Elapsed += delegate {
|
this.remote_timer.Elapsed += delegate {
|
||||||
|
@ -176,7 +180,8 @@ namespace SparkleLib {
|
||||||
|
|
||||||
public void Initialize ()
|
public void Initialize ()
|
||||||
{
|
{
|
||||||
this.watcher.ChangeEvent += OnFileActivity;
|
if (!UseCustomWatcher)
|
||||||
|
this.watcher.ChangeEvent += OnFileActivity;
|
||||||
|
|
||||||
// Sync up everything that changed
|
// Sync up everything that changed
|
||||||
// since we've been offline
|
// since we've been offline
|
||||||
|
@ -213,7 +218,9 @@ namespace SparkleLib {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
IsBuffering = true;
|
IsBuffering = true;
|
||||||
this.watcher.Disable ();
|
|
||||||
|
if (!UseCustomWatcher)
|
||||||
|
this.watcher.Disable ();
|
||||||
|
|
||||||
SparkleLogger.LogInfo ("Local", Name + " | Activity detected, waiting for it to settle...");
|
SparkleLogger.LogInfo ("Local", Name + " | Activity detected, waiting for it to settle...");
|
||||||
|
|
||||||
|
@ -250,7 +257,8 @@ namespace SparkleLib {
|
||||||
|
|
||||||
} while (IsBuffering);
|
} while (IsBuffering);
|
||||||
|
|
||||||
this.watcher.Enable ();
|
if (!UseCustomWatcher)
|
||||||
|
this.watcher.Enable ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -279,7 +287,8 @@ namespace SparkleLib {
|
||||||
|
|
||||||
private void SyncUpBase ()
|
private void SyncUpBase ()
|
||||||
{
|
{
|
||||||
this.watcher.Disable ();
|
if (!UseCustomWatcher)
|
||||||
|
this.watcher.Disable ();
|
||||||
|
|
||||||
SparkleLogger.LogInfo ("SyncUp", Name + " | Initiated");
|
SparkleLogger.LogInfo ("SyncUp", Name + " | Initiated");
|
||||||
HasUnsyncedChanges = true;
|
HasUnsyncedChanges = true;
|
||||||
|
@ -299,7 +308,8 @@ namespace SparkleLib {
|
||||||
SparkleLogger.LogInfo ("SyncUp", Name + " | Error");
|
SparkleLogger.LogInfo ("SyncUp", Name + " | Error");
|
||||||
SyncDownBase ();
|
SyncDownBase ();
|
||||||
|
|
||||||
this.watcher.Disable ();
|
if (!UseCustomWatcher)
|
||||||
|
this.watcher.Disable ();
|
||||||
|
|
||||||
if (ServerOnline && SyncUp ()) {
|
if (ServerOnline && SyncUp ()) {
|
||||||
HasUnsyncedChanges = false;
|
HasUnsyncedChanges = false;
|
||||||
|
@ -316,13 +326,15 @@ namespace SparkleLib {
|
||||||
ProgressPercentage = 0.0;
|
ProgressPercentage = 0.0;
|
||||||
ProgressSpeed = "";
|
ProgressSpeed = "";
|
||||||
|
|
||||||
this.watcher.Enable ();
|
if (!UseCustomWatcher)
|
||||||
|
this.watcher.Enable ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void SyncDownBase ()
|
private void SyncDownBase ()
|
||||||
{
|
{
|
||||||
this.watcher.Disable ();
|
if (!UseCustomWatcher)
|
||||||
|
this.watcher.Disable ();
|
||||||
|
|
||||||
SparkleLogger.LogInfo ("SyncDown", Name + " | Initiated");
|
SparkleLogger.LogInfo ("SyncDown", Name + " | Initiated");
|
||||||
|
|
||||||
|
@ -373,7 +385,8 @@ namespace SparkleLib {
|
||||||
ProgressPercentage = 0.0;
|
ProgressPercentage = 0.0;
|
||||||
ProgressSpeed = "";
|
ProgressSpeed = "";
|
||||||
|
|
||||||
this.watcher.Enable ();
|
if (!UseCustomWatcher)
|
||||||
|
this.watcher.Enable ();
|
||||||
|
|
||||||
SyncStatusChanged (SyncStatus.Idle);
|
SyncStatusChanged (SyncStatus.Idle);
|
||||||
}
|
}
|
||||||
|
@ -489,7 +502,8 @@ namespace SparkleLib {
|
||||||
this.listener.Disconnected -= ListenerDisconnectedDelegate;
|
this.listener.Disconnected -= ListenerDisconnectedDelegate;
|
||||||
this.listener.AnnouncementReceived -= ListenerAnnouncementReceivedDelegate;
|
this.listener.AnnouncementReceived -= ListenerAnnouncementReceivedDelegate;
|
||||||
|
|
||||||
this.watcher.Dispose ();
|
if (!UseCustomWatcher)
|
||||||
|
this.watcher.Dispose ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
using MonoMac.Foundation;
|
using MonoMac.Foundation;
|
||||||
using MonoMac.AppKit;
|
using MonoMac.AppKit;
|
||||||
|
@ -68,8 +69,9 @@ namespace SparkleShare {
|
||||||
{
|
{
|
||||||
base.Initialize ();
|
base.Initialize ();
|
||||||
|
|
||||||
|
SparkleRepoBase.UseCustomWatcher = true;
|
||||||
|
|
||||||
this.watcher.Changed += delegate (string path) {
|
this.watcher.Changed += delegate (string path) {
|
||||||
// Don't even bother with paths in .git/
|
|
||||||
if (path.Contains (".git"))
|
if (path.Contains (".git"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -80,18 +82,16 @@ namespace SparkleShare {
|
||||||
else
|
else
|
||||||
repo_name = path;
|
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 ());
|
repo_name = repo_name.Trim ("/".ToCharArray ());
|
||||||
FileSystemEventArgs fse_args = new FileSystemEventArgs (WatcherChangeTypes.Changed,
|
FileSystemEventArgs fse_args = new FileSystemEventArgs (WatcherChangeTypes.Changed,
|
||||||
Path.Combine (SparkleConfig.DefaultConfig.FoldersPath, path), Path.GetFileName (path));
|
Path.Combine (SparkleConfig.DefaultConfig.FoldersPath, path), Path.GetFileName (path));
|
||||||
|
|
||||||
foreach (SparkleRepoBase repo in Repositories) {
|
foreach (SparkleRepoBase repo in Repositories) {
|
||||||
if (repo.Name.Equals (repo_name))
|
if (repo.Name.Equals (repo_name)) {
|
||||||
repo.OnFileActivity (fse_args);
|
new Thread (() => {
|
||||||
|
repo.OnFileActivity (fse_args);
|
||||||
|
}).Start ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue