wimh / SparkleShare

SparkleShare is a file sharing and collaboration tool inspired by Dropbox.
http://www.sparkleshare.org/
GNU General Public License v3.0
39 stars 6 forks source link

non-readable files causing an endless loop #10

Closed tvollstaedt closed 11 years ago

tvollstaedt commented 12 years ago

Opening a Microsoft Word or Excel file for example causing Sparkleshare to endlessly add the temporary files from office (~filename.ext). Since the add + commit fails, sparkleshare thinks there is still a change to commit --> causes an endless loop of commits and notifications.

wimh commented 12 years ago

I don't have word/excel at home, but I can see something similar with other software. I think the easiest way to fix this, is to ignore all files starting with a ~. I have pushed a fix which should do that, but it will not change existing folders.

If you manually modify the file .git\info\exclude and add a line containing

~*

it should fix this too.

This causes all files starting with a ~ not to be added any more. Can those temp files also be recognised by for example the extension? For example use something like ~*.doc[x]?

tvollstaedt commented 12 years ago

Ignoring those files is only a workaround since this could be caused by any file locking software. I believe it would be much more efficient to check whether the file is readable for sparkleshare and skip it if not (or maybe add it to the exception list).

hbons commented 12 years ago

Temporary files are often also readable, so blacklisting is the only reliable means we have...

tvollstaedt commented 12 years ago

Sorry, i'm not very familiar with github yet, so i'm attaching this via comment meanwhile. It's a simple patch which basically solves the issue for me.

diff --git a/SparkleLib/SparkleRepoBase.cs b/SparkleLib/SparkleRepoBase.cs
index f781d57..7d3d756 100644
--- a/SparkleLib/SparkleRepoBase.cs
+++ b/SparkleLib/SparkleRepoBase.cs
@@ -314,6 +314,19 @@ namespace SparkleLib {
                 !args.FullPath.Contains (Path.DirectorySeparatorChar + ".notes"))
                 return;

+            /*
+             * Check wheter the file which triggered the action
+             * is readable so that git can actually commit it
+             */
+
+            try {
+                FileStream file = File.OpenRead(args.FullPath);
+                file.Close();
+            } catch {
+                SparkleHelpers.DebugInfo("Warning", "File " + args.FullPath + " is not readable. Skipping.");
+                return;
+            }
+
             WatcherChangeTypes wct = args.ChangeType;

             if (AnyDifferences) {
hbons commented 12 years ago

@tvollstaedt I wonder if that will also work when it's a different file that triggered the process. If a different file triggers the process whilst another file is unreadable, it could cause the same problem.

tvollstaedt commented 12 years ago

Okay, i wasn't so deep into sh code yet. Your'e right. In this case, we need to do both, skip the file and add it to exception list.

tvollstaedt commented 12 years ago

@hbons: I just pushed a branch for a fix on this topic. Please see my pull request for details.

wimh commented 12 years ago

@tvollstaedt, I have now merged your branch into the windows version. I leave this issue open until any problems are resolved and it is also merged into the linux version.

hbons commented 12 years ago

I've added an exclude rule for Office files: http://support.microsoft.com/kb/211632

~*.tmp

wimh commented 12 years ago

~*.tmp seems not sufficient, see #20.

hbons commented 12 years ago

added more: https://github.com/hbons/SparkleShare/commit/a7c130295f477bf2c12ad14d042fd379c8f320cc

wimh commented 11 years ago

Closing all open issues - there are too many changes upstream, won't merge any more.