Re: [Banshee-List] Keeping in sync



Hello everyone,

Attaching three more patches:

1) sync_subfolderfix.patch

This changes IsSubfolder function's name to IsBelow(which is still
wrong:)). What is the right name for a function that checks if a file
or folder is the descendant of a folder in the file system tree? Also,
fixes a small issue. "..../Queenscythe/" was thought to be below
"..../Queen/" this should fix it, hopefully.

2) sync_cleanup.patch

Some cleanups.

3) sync_hot.patch

Watch gets hot when a new file is set to be imported or removed. And
the update thread can't touch the watch while it is hot. Hopefully,
this will group more files together so that they can be imported(or
removed) at once.

Aaron, also putting the update thread to sleep for 5 seconds may be
too long, if the hot patch gets in. A short interval may be better.

Good day,
Doğacan Güney
diff -rpu2 banshee.old/src/FileSystemMonitor/Watch.cs banshee/src/FileSystemMonitor/Watch.cs
--- banshee.old/src/FileSystemMonitor/Watch.cs	2005-11-14 12:28:49.000000000 +0200
+++ banshee/src/FileSystemMonitor/Watch.cs	2005-11-14 12:26:41.000000000 +0200
@@ -12,4 +12,6 @@ namespace Banshee.FileSystemMonitor {
         protected ArrayList to_remove;
         
+        private bool hot;
+        
         public Watch(ArrayList im, ArrayList rm, string folder)
         {
@@ -18,4 +20,6 @@ namespace Banshee.FileSystemMonitor {
             to_import = im;
             to_remove = rm;
+            
+            hot = false;
         }
         
@@ -48,4 +52,6 @@ namespace Banshee.FileSystemMonitor {
             bool added = false;
             
+            hot = true;
+            
             for(int i = 0; i < aList.Count; i++) {
                 cur = aList[i] as string;
@@ -74,4 +80,14 @@ namespace Banshee.FileSystemMonitor {
         
         public abstract void Stop();
+        
+        public bool Hot
+        {
+            get {
+                return hot;
+            }
+            set {
+                hot = value;
+            }
+        }
     }
 }
diff -rpu2 banshee.old/src/FileSystemMonitor/Watcher.cs banshee/src/FileSystemMonitor/Watcher.cs
--- banshee.old/src/FileSystemMonitor/Watcher.cs	2005-11-14 12:28:44.000000000 +0200
+++ banshee/src/FileSystemMonitor/Watcher.cs	2005-11-14 12:26:45.000000000 +0200
@@ -36,5 +36,6 @@ namespace Banshee.FileSystemMonitor {
             while(true) {
     		    lock(watch) {
-                    if(to_remove.Count != 0) {
+    		    
+                    if(to_remove.Count != 0 && !watch.Hot) {
                         Console.WriteLine("to_remove begin");
                         
@@ -66,5 +67,5 @@ namespace Banshee.FileSystemMonitor {
                     }
                     
-                    if(to_import.Count != 0) {
+                    if(to_import.Count != 0 && !watch.Hot) {
                         FileLoadTransaction transaction = 
                             new FileLoadTransaction(null, true, true);
@@ -84,6 +85,10 @@ namespace Banshee.FileSystemMonitor {
                         to_import.Clear();
                     }
+                    
+                    if(watch.Hot)
+                        watch.Hot = false;
                 }
                 
+                
                 Thread.Sleep(5000);
 		    }










? sync_subfolderfix.patch
? burn-sharp/.deps
? burn-sharp/.libs
? burn-sharp/glue.lo
? burn-sharp/libnautilusburnglue.la
? data/images/ipod/Makefile
? data/images/ipod/Makefile.in
? libbanshee/.deps
? libbanshee/.libs
? libbanshee/cd-detect.lo
? libbanshee/cd-rip.lo
? libbanshee/gst-encode.lo
? libbanshee/gst-init.lo
? libbanshee/gst-misc.lo
? libbanshee/gst-player-engine.lo
? libbanshee/inotify-glue.lo
? libbanshee/libbanshee.la
? libbanshee/xing/.deps
? po/.intltool-merge-cache
? src/FileSystemMonitor/test.cs
Index: src/FileSystemMonitor/Watch.cs
===================================================================
RCS file: /cvs/gnome/banshee/src/FileSystemMonitor/Watch.cs,v
retrieving revision 1.1
diff -p -u -2 -r1.1 Watch.cs
--- src/FileSystemMonitor/Watch.cs	13 Nov 2005 20:13:01 -0000	1.1
+++ src/FileSystemMonitor/Watch.cs	14 Nov 2005 10:12:28 -0000
@@ -52,8 +52,8 @@ namespace Banshee.FileSystemMonitor
                 cur = aList[i] as string;
             
-                if(IsSubfolder(item, cur))
+                if(IsBelow(item, cur))
                     return;
                 
-                if(IsSubfolder(cur, item)) {
+                if(IsBelow(cur, item)) {
                     aList[i] = item;
                     added = true;
@@ -65,9 +65,7 @@ namespace Banshee.FileSystemMonitor
 		}
 		
-		protected bool IsSubfolder(string f1, string f2)
+		protected bool IsBelow(string f1, string f2)
 		{
-            CompareInfo comp =  CultureInfo.InvariantCulture.CompareInfo;
-
-            return comp.IsPrefix(f1, f2);
+            return CultureInfo.InvariantCulture.CompareInfo.IsPrefix(f1, f2 + '/');
 		}
 		










? sync_cleanup.patch
? burn-sharp/.deps
? burn-sharp/.libs
? burn-sharp/glue.lo
? burn-sharp/libnautilusburnglue.la
? data/images/ipod/Makefile
? data/images/ipod/Makefile.in
? libbanshee/.deps
? libbanshee/.libs
? libbanshee/cd-detect.lo
? libbanshee/cd-rip.lo
? libbanshee/gst-encode.lo
? libbanshee/gst-init.lo
? libbanshee/gst-misc.lo
? libbanshee/gst-player-engine.lo
? libbanshee/inotify-glue.lo
? libbanshee/libbanshee.la
? libbanshee/xing/.deps
? po/.intltool-merge-cache
Index: src/FileSystemMonitor/FileSystemWatcherWatch.cs
===================================================================
RCS file: /cvs/gnome/banshee/src/FileSystemMonitor/FileSystemWatcherWatch.cs,v
retrieving revision 1.1
diff -p -u -2 -r1.1 FileSystemWatcherWatch.cs
--- src/FileSystemMonitor/FileSystemWatcherWatch.cs	13 Nov 2005 20:13:01 -0000	1.1
+++ src/FileSystemMonitor/FileSystemWatcherWatch.cs	14 Nov 2005 09:57:46 -0000
@@ -3,8 +3,8 @@ using System.Collections;
 using System.IO;
 
-namespace Banshee.FileSystemMonitor
-{
-    public sealed class FileSystemWatcherWatch : Watch
-    {
+namespace Banshee.FileSystemMonitor {
+
+    public sealed class FileSystemWatcherWatch : Watch {
+
         private Hashtable watchMap;
         private bool verbose = false;
@@ -56,5 +56,5 @@ namespace Banshee.FileSystemMonitor
         {
             lock(this) {
-                UniqueAdd(toImport, e.FullPath);
+                UniqueAdd(to_import, e.FullPath);
             }
         }
@@ -63,5 +63,5 @@ namespace Banshee.FileSystemMonitor
         {
             lock(this) {
-                UniqueAdd(toRemove, e.FullPath);
+                UniqueAdd(to_remove, e.FullPath);
             }
         }
@@ -70,6 +70,6 @@ namespace Banshee.FileSystemMonitor
         {
             lock(this) {
-                UniqueAdd(toImport, e.FullPath);
-                UniqueAdd(toRemove, e.OldFullPath);
+                UniqueAdd(to_import, e.FullPath);
+                UniqueAdd(to_remove, e.OldFullPath);
             }
         }
Index: src/FileSystemMonitor/InotifyWatch.cs
===================================================================
RCS file: /cvs/gnome/banshee/src/FileSystemMonitor/InotifyWatch.cs,v
retrieving revision 1.1
diff -p -u -2 -r1.1 InotifyWatch.cs
--- src/FileSystemMonitor/InotifyWatch.cs	13 Nov 2005 20:13:01 -0000	1.1
+++ src/FileSystemMonitor/InotifyWatch.cs	14 Nov 2005 09:57:47 -0000
@@ -3,8 +3,8 @@ using System.Collections;
 using System.IO;
 
-namespace Banshee.FileSystemMonitor
-{
-    public sealed class InotifyWatch : Watch 
-    {
+namespace Banshee.FileSystemMonitor {
+
+    public sealed class InotifyWatch : Watch {
+    
         private bool verbose = false;
                  
@@ -55,13 +55,13 @@ namespace Banshee.FileSystemMonitor
             lock(this) {
                 if(HasFlag(type, Inotify.EventType.MovedTo) || HasFlag(type, Inotify.EventType.CloseWrite)) {
-                    UniqueAdd(toImport, fullPath);
+                    UniqueAdd(to_import, fullPath);
                         
                     if(srcpath != null) {
-                        UniqueAdd(toRemove, srcpath);
+                        UniqueAdd(to_remove, srcpath);
                     }
                 } else if(HasFlag(type, Inotify.EventType.Create)) { /*HasFlag (type, Inotify.EventType.IsDirectory)) */
-                    UniqueAdd(toImport, fullPath);
+                    UniqueAdd(to_import, fullPath);
                 } else if(HasFlag(type, Inotify.EventType.Delete) || HasFlag(type, Inotify.EventType.MovedFrom)) {
-                    UniqueAdd(toRemove, fullPath);
+                    UniqueAdd(to_remove, fullPath);
                 }
             }
Index: src/FileSystemMonitor/Watch.cs
===================================================================
RCS file: /cvs/gnome/banshee/src/FileSystemMonitor/Watch.cs,v
retrieving revision 1.1
diff -p -u -2 -r1.1 Watch.cs
--- src/FileSystemMonitor/Watch.cs	13 Nov 2005 20:13:01 -0000	1.1
+++ src/FileSystemMonitor/Watch.cs	14 Nov 2005 09:57:47 -0000
@@ -4,12 +4,11 @@ using System.Globalization;
 using System.IO;
 
-namespace Banshee.FileSystemMonitor
-{
-    public abstract class Watch 
-    {
+namespace Banshee.FileSystemMonitor {
+
+    public abstract class Watch {
         protected string musicFolder;
         
-        protected ArrayList toImport;
-        protected ArrayList toRemove;
+        protected ArrayList to_import;
+        protected ArrayList to_remove;
         
         public Watch(ArrayList im, ArrayList rm, string folder)
@@ -17,6 +16,6 @@ namespace Banshee.FileSystemMonitor
             musicFolder = folder;
             
-            toImport = im;
-            toRemove = rm;
+            to_import = im;
+            to_remove = rm;
         }
         
Index: src/FileSystemMonitor/Watcher.cs
===================================================================
RCS file: /cvs/gnome/banshee/src/FileSystemMonitor/Watcher.cs,v
retrieving revision 1.1
diff -p -u -2 -r1.1 Watcher.cs
--- src/FileSystemMonitor/Watcher.cs	13 Nov 2005 20:13:01 -0000	1.1
+++ src/FileSystemMonitor/Watcher.cs	14 Nov 2005 09:57:48 -0000
@@ -4,10 +4,10 @@ using System.Data;
 using System.Threading;
 
-namespace Banshee.FileSystemMonitor
-{
-    public class Watcher : IDisposable
-    {
-        private ArrayList toImport;
-        private ArrayList toRemove;
+namespace Banshee.FileSystemMonitor {
+
+    public class Watcher : IDisposable {
+    
+        private ArrayList to_import;
+        private ArrayList to_remove;
         
         private Thread updateThread;
@@ -17,6 +17,6 @@ namespace Banshee.FileSystemMonitor
         public Watcher(string watchDirectory)
         {
-            toImport = new ArrayList();
-            toRemove = new ArrayList();
+            to_import = new ArrayList();
+            to_remove = new ArrayList();
         
             updateThread = new Thread(new ThreadStart(Update));
@@ -24,7 +24,7 @@ namespace Banshee.FileSystemMonitor
             if(Inotify.Enabled) {
                 Console.WriteLine("The power of inotify!");
-                watch = new InotifyWatch(toImport, toRemove, watchDirectory);
+                watch = new InotifyWatch(to_import, to_remove, watchDirectory);
             } else {
-                watch = new FileSystemWatcherWatch(toImport, toRemove, watchDirectory);
+                watch = new FileSystemWatcherWatch(to_import, to_remove, watchDirectory);
             }
             
@@ -36,10 +36,10 @@ namespace Banshee.FileSystemMonitor
             while(true) {
     		    lock(watch) {
-                    if(toRemove.Count != 0) {
-                        Console.WriteLine("toRemove begin");
+                    if(to_remove.Count != 0) {
+                        Console.WriteLine("to_remove begin");
                         
                         string query = " FROM TRACKS WHERE";                     
     		    
-            		    foreach(string s in toRemove) {
+            		    foreach(string s in to_remove) {
             		        Console.WriteLine(s as string);
                             query +=" Uri LIKE \"file://" + s + "/%\"";
@@ -49,5 +49,5 @@ namespace Banshee.FileSystemMonitor
                         }
                         
-                        Console.WriteLine("toRemove end");
+                        Console.WriteLine("to_remove end");
                         
                         query = query.Substring(0, query.Length - 3);
@@ -63,14 +63,14 @@ namespace Banshee.FileSystemMonitor
                         Core.Library.Db.Execute(deleteQuery);
                       
-                        toRemove.Clear();
+                        to_remove.Clear();
                     }
                     
-                    if(toImport.Count != 0) {
+                    if(to_import.Count != 0) {
                         FileLoadTransaction transaction = 
                             new FileLoadTransaction(null, true, true);
                             
-                        Console.WriteLine("toImport begin");
+                        Console.WriteLine("to_import begin");
 
-              		    foreach(string s in toImport) {
+              		    foreach(string s in to_import) {
                             Console.WriteLine(s);
                             transaction.AddPath(s);
@@ -78,9 +78,9 @@ namespace Banshee.FileSystemMonitor
                         }
                         
-                        Console.WriteLine("toImport end");
+                        Console.WriteLine("to_import end");
                         
                         transaction.Register();
                         
-                        toImport.Clear();
+                        to_import.Clear();
                     }
                 }












[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]