Index: Core/Util/Util.cs
===================================================================
--- Core/Util/Util.cs	(revision 27004)
+++ Core/Util/Util.cs	(working copy)
@@ -122,7 +122,7 @@
 
     private const int CONNECT_UPDATE_PROFILE = 0x00000001;
     private const int RESOURCETYPE_DISK = 0x1;
-    private const int FileLookUpCacheThreadScanningIntervalMSecs = 1000;
+    private const int FileLookUpCacheThreadScanningIntervalMSecs = 5000;
 
     private static CRCTool crc = null;
 
@@ -2459,7 +2459,7 @@
     private static Thread _fileSystemManagerThread = null;
     private static Thread _fileExistsCacheThread = null;
 
-    private static DateTime _lastTimeFolderWasAdded = DateTime.MinValue;
+    private static bool _watchedFolderHasChanged = false;
     
     private static ManualResetEvent _fileExistsCacheThreadEvt = new ManualResetEvent(false);
 
@@ -2564,7 +2564,7 @@
         {
           //Log.Debug("AddFoldersLookedUp {0}", dir);
           _foldersLookedUp.Add(dir);
-          _lastTimeFolderWasAdded = DateTime.Now;
+          _watchedFolderHasChanged = true;
         }
       }
     }
@@ -2599,13 +2599,17 @@
     {
       FileSystemWatcher watcher = sender as FileSystemWatcher;
 
-      if (watcher != null)
+      if (!e.FullPath.Contains("db3-journal"))
       {
-        Log.Debug("fileSystemWatcher_Created file {0}", e.FullPath);
-        FileLookUpItem fileLookUpItem = new FileLookUpItem();
-        fileLookUpItem.Exists = true;
-        fileLookUpItem.Filename = e.FullPath;
-        UpdateLookUpCacheItem(fileLookUpItem, e.FullPath);
+        if (watcher != null)
+        {
+          Log.Debug("fileSystemWatcher_Created file {0}", e.FullPath);
+          FileLookUpItem fileLookUpItem = new FileLookUpItem();
+          fileLookUpItem.Exists = true;
+          fileLookUpItem.Filename = e.FullPath;
+          UpdateLookUpCacheItem(fileLookUpItem, e.FullPath);
+          _watchedFolderHasChanged = true;
+        }
       }
     }
 
@@ -2613,10 +2617,14 @@
     {
       FileSystemWatcher watcher = sender as FileSystemWatcher;
 
-      if (watcher != null)
+      if (!e.FullPath.Contains("db3-journal"))
       {
-        Log.Debug("fileSystemWatcher_Deleted file {0}", e.FullPath);
-        DoInsertNonExistingFileIntoCache(e.FullPath);
+        if (watcher != null)
+        {
+          Log.Debug("fileSystemWatcher_Deleted file {0}", e.FullPath);
+          DoInsertNonExistingFileIntoCache(e.FullPath);
+          _watchedFolderHasChanged = true;
+        }
       }
     }
 
@@ -2736,45 +2744,41 @@
       {
         lock (_watchersLock)
         {
-          if (_lastTimeFolderWasAdded != DateTime.MinValue)
+          if (_watchedFolderHasChanged)
           {
-            DateTime now = DateTime.Now;
-            TimeSpan ts = now - _lastTimeFolderWasAdded;
+            Log.Debug("FileSystemWatchManagerThread : updating watchers");
 
-            //Log.Debug("_lastTimeFolderWasAdded: {0}", _lastTimeFolderWasAdded);
-            //Log.Debug("ts.TotalSeconds: {0}", ts.TotalSeconds);
-
-            if (ts.TotalSeconds > 5)
+            string[] keyCopy = _watchers.Keys.ToArray();
+            foreach (string key in keyCopy)
             {
-              Log.Debug("FileSystemWatchManagerThread : updating watchers");
-              HashSet<string> folders = GetUniqueTopLevelFolders();
-
-              foreach (string dir in folders)
+              FileSystemWatcher fsw = null;
+              if (_watchers.TryGetValue(key, out fsw))
               {
-                if (!string.IsNullOrEmpty(dir))
-                {                  
-                  UpdateWatchers(dir);
+                if (!Directory.Exists(fsw.Path))
+                {
+                  RemoveWatcher(fsw.Path);
                 }
               }
-              _lastTimeFolderWasAdded = DateTime.MinValue;
-              Log.Debug("FileLookUpCacheThread items : {0}", _fileLookUpCache.Count);                      
             }
 
-            /*string[] keyCopy = _watchers.Keys.ToArray();
-            foreach (string key in keyCopy)
+            HashSet<string> folders = GetUniqueTopLevelFolders();
+
+            foreach (string dir in folders)
             {
-              FileSystemWatcher fsw = null;
-              if (_watchers.TryGetValue(key, out fsw))
+              if (!string.IsNullOrEmpty(dir) && !_watchers.ContainsKey(dir))
               {
-                Log.Debug("FileSystemWatcher : {0}", fsw.Path);
+                AddWatcher(dir);
               }
-            }*/
+            }
+            _watchedFolderHasChanged = false;
+            Log.Debug("FileLookUpCacheThread items : {0}", _fileLookUpCache.Count);
           }
-        }        
+        }
         Thread.Sleep(FileLookUpCacheThreadScanningIntervalMSecs);
       }
     }
 
+
     private static HashSet<string> GetUniqueTopLevelFolders()
     {
       HashSet<string> uniqueTopLevelFolders = new HashSet<string>();
@@ -2891,31 +2895,6 @@
       return isPathRoot;
     }
 
-    private static void UpdateWatchers(string dir4Watcher)
-    {           
-      int dir4WatcherLen = dir4Watcher.Length;
-
-      string[] keyCopy = _watchers.Keys.ToArray();
-      foreach (string key in keyCopy)
-      {
-        FileSystemWatcher fsw = null;
-        if (_watchers.TryGetValue(key, out fsw))
-        {
-          string path = fsw.Path;
-          int pathLen = path.Length;
-          if ((pathLen > dir4WatcherLen) && path.StartsWith(dir4Watcher))
-          {            
-            RemoveWatcher(path);
-          }
-        }
-      }
-
-      if (!_watchers.ContainsKey(dir4Watcher))
-      {
-        AddWatcher(dir4Watcher);
-      }
-    }
-
     private static void AddWatcher(string dir, int buffersize)
     {
       AddWatcher(dir);
@@ -2932,6 +2911,10 @@
 
     private static void AddWatcher(string dir)
     {
+      // don't add a watcher for a share
+      if (dir.Contains("\\\\"))
+        return;
+
       try
       {        
         FileSystemWatcher fsw = new FileSystemWatcher(dir);
@@ -3000,6 +2983,8 @@
         }
       }
 
+      _watchedFolderHasChanged = true;
+
       lock (_foldersLookedUpLock)
       {
         Log.Debug("RemoveWatcher removing folders from cache={0}", dir);
@@ -3037,7 +3022,7 @@
       if (!String.IsNullOrEmpty(path))
       {
         string dir2Lower = path.ToLower();
-        
+
         if (!HasFolderBeenScanned(dir2Lower))
         {
           Log.Debug("InsertFilesIntoCacheAsynch: pre-scanning dir : {0}", path);
@@ -3047,10 +3032,6 @@
             DoInsertExistingFileIntoCache(file);
           }
         }
-        /*else
-        {
-          Log.Debug("InsertFilesIntoCacheAsynch: dir already pre-scanned : {0}", path);      
-        }*/
       }
     }
 
