Hi,

On 2018-07-24 22:24:19 +0000 Patrick CARDONA <[email protected]> wrote:



It was the same behaviour. As I can understand, GWorkspace checks /etc/mtab only when it loads the desktop. So, when I use the workaround (hide and show again the desktop) this works to show the disk icon. What is strange, is that when I unmount ($ udisksctl unmount -p [device_path]) the disk icon is hidden as expected : so the behaviour is dynamic with unmounting, not at mounting.

your description made me suspicious and I spent several hours debugging the code.
I hope I fixed both yout and my issues.

I ound an additional issue: if a volume is mounted *before* starting GWorkspace it would not get recognized.

If you like, try the attached patch.
I simplified the code and hopefully fixed it. It relied on wrong assumptions, I guess. I did not try it with multipme volumes (e.g, cdrom, usb key, floppy..... multiple USB disks) because I just had one USB device with me on travel currently.

However, with this code I can mound/unomount from the command line and see the device appear/disappear. Parallely, even i the desktop is not showing and a volume gets touched or mounted before GWorkspace it works.

If you want to test before me committing it, go! I did try mounting on FreeBSD and not ubuntu and my SystemPreferences is setup fine to mount automatically, for your information.


Riccardo

<mount-watching.patch>
diff --git a/FSNode/FSNodeRepIcons.m b/FSNode/FSNodeRepIcons.m
index 58256c9d..f94c1cdf 100644
--- a/FSNode/FSNodeRepIcons.m
+++ b/FSNode/FSNodeRepIcons.m
@@ -1,6 +1,6 @@
 /* FSNodeRepIcons.m
  *  
- * Copyright (C) 2005-2016 Free Software Foundation, Inc.
+ * Copyright (C) 2005-2018 Free Software Foundation, Inc.
  *
  * Author: Enrico Sersale <[email protected]>
  *         Riccardo Mottola
@@ -135,8 +135,7 @@ static unsigned char darkerLUT[256] = {
 	{
 	  key = nodepath;
 	}
-      else if (([node isMountPoint] && [volumes containsObject: nodepath])
-	       || [volumes containsObject: nodepath])
+      else if ([node isMountPoint] || [volumes containsObject: nodepath])
 	{
 	  key = @"disk";
 	  baseIcon = hardDiskIcon;
@@ -358,8 +357,7 @@ static unsigned char darkerLUT[256] = {
       icon = [self darkerIcon: [self iconOfSize: size forNode: node]];
     }      
   } else {
-    if (([node isMountPoint] && [volumes containsObject: [node path]])
-                                    || [volumes containsObject: [node path]]) {
+    if ([node isMountPoint] || [volumes containsObject: [node path]]) {
       icon = [self darkerIcon: hardDiskIcon];
     } else {
       icon = [self darkerIcon: [self iconOfSize: size forNode: node]];
diff --git a/GWorkspace/Desktop/GWDesktopManager.h b/GWorkspace/Desktop/GWDesktopManager.h
index d270345e..fe25ce42 100644
--- a/GWorkspace/Desktop/GWDesktopManager.h
+++ b/GWorkspace/Desktop/GWDesktopManager.h
@@ -1,6 +1,6 @@
 /* GWDesktopManager.h
  *  
- * Copyright (C) 2005-2016 Free Software Foundation, Inc.
+ * Copyright (C) 2005-2018 Free Software Foundation, Inc.
  *
  * Author: Enrico Sersale <[email protected]>
  * Date: January 2005
@@ -186,7 +186,7 @@ typedef enum DockPosition {
 
 @interface MPointWatcher : NSObject
 {
-  NSMutableArray *volinfo;
+  NSArray *mountedRemovableVolumes;
   NSTimer *timer;
   BOOL active;
   GWDesktopManager *manager;
diff --git a/GWorkspace/Desktop/GWDesktopManager.m b/GWorkspace/Desktop/GWDesktopManager.m
index 498f5abd..f8bb5f90 100644
--- a/GWorkspace/Desktop/GWDesktopManager.m
+++ b/GWorkspace/Desktop/GWDesktopManager.m
@@ -1,8 +1,10 @@
 /* GWDesktopManager.m
  *  
- * Copyright (C) 2005-2016 Free Software Foundation, Inc.
+ * Copyright (C) 2005-2018 Free Software Foundation, Inc.
+ *
+ * Authors: Enrico Sersale <[email protected]>
+ *          Riccardo Mottola <[email protected]>
  *
- * Author: Enrico Sersale <[email protected]>
  * Date: January 2005
  *
  * This file is part of the GNUstep GWorkspace application
@@ -866,97 +868,84 @@ static GWDesktopManager *desktopManager = nil;
 
 - (void)dealloc
 {
-	if (timer && [timer isValid]) {
-		[timer invalidate];
-	}  
-  RELEASE (volinfo);  
-	[super dealloc];
+  if (timer && [timer isValid])
+    {
+      [timer invalidate];
+    }
+
+  RELEASE (mountedRemovableVolumes);
+  [super dealloc];
 }
 
 - (id)initForManager:(GWDesktopManager *)mngr
 {
   self = [super init];
   
-  if (self) {
-    manager = mngr;    
-    volinfo = [NSMutableArray new];
-    active = NO;
-    fm = [NSFileManager defaultManager];
-    
-    timer = [NSTimer scheduledTimerWithTimeInterval: 1.0 
-												                     target: self 
-                                           selector: @selector(watchMountPoints:) 
-										                       userInfo: nil 
-                                            repeats: YES];
-  }
+  if (self)
+    {
+      manager = mngr;
+      active = NO;
+      fm = [NSFileManager defaultManager];
+
+      timer = [NSTimer scheduledTimerWithTimeInterval: 1.5
+					       target: self
+					     selector: @selector(watchMountPoints:)
+					     userInfo: nil
+					      repeats: YES];
+    }
   
   return self;
 }
 
 - (void)startWatching
 {
-  NSSet *volumes = [[FSNodeRep sharedInstance] volumes];
-  NSEnumerator *enumerator = [volumes objectEnumerator];
-  NSString *path;
-  
-  [volinfo removeAllObjects];
-
-  while ((path = [enumerator nextObject])) {
-    NSDictionary *attributes = [fm fileAttributesAtPath: path traverseLink: NO];
-    
-    if (attributes) {
-      NSDate *moddate = [attributes fileModificationDate];
-      NSMutableDictionary *dict = [NSMutableDictionary dictionary];
-      
-      [dict setObject: path forKey: @"path"];
-      [dict setObject: moddate forKey: @"moddate"];
-      
-      [volinfo addObject: dict];  
-    }
-  }
-
+  [mountedRemovableVolumes release];
+  mountedRemovableVolumes = [[NSWorkspace sharedWorkspace] mountedRemovableMedia];
+  [mountedRemovableVolumes retain];
   active = YES;
 }
 
 - (void)stopWatching
 {
   active = NO;
-  [volinfo removeAllObjects];
+  [mountedRemovableVolumes release];
+  mountedRemovableVolumes = nil;
 }
 
 - (void)watchMountPoints:(id)sender
 {
-  if (active) {
-    int count = [volinfo count];
-    BOOL changed = NO;
-    NSUInteger i;
-    
-    for (i = 0; i < count; i++) {
-      NSMutableDictionary *dict = [volinfo objectAtIndex: i];
-      NSString *path = [dict objectForKey: @"path"];
-      NSDate *moddate = [dict objectForKey: @"moddate"];
-      NSDictionary *attributes = [fm fileAttributesAtPath: path traverseLink: NO];      
-      
-      if (attributes) {
-        NSDate *lastmod = [attributes fileModificationDate];
-      
-        if ([moddate isEqualToDate: lastmod] == NO) {
-          [dict setObject: lastmod forKey: @"moddate"];
-          changed = YES;
-        }
-        
-      } else {
-        [volinfo removeObjectAtIndex: i]; 
-        count--;
-        i--;
-        changed = YES;       
-      }      
-    }
-    
-    if (changed) {
-      [manager mountedVolumesDidChange]; 
+  if (active)
+    {
+      BOOL removed = NO;
+      BOOL added = NO;
+      NSUInteger i;
+      NSArray *newVolumes = [[NSWorkspace sharedWorkspace] mountedRemovableMedia];
+
+      for (i = 0; i < [mountedRemovableVolumes count]; i++)
+	{
+	  NSString *vol;
+
+	  vol = [mountedRemovableVolumes objectAtIndex:i];
+	  if (![newVolumes containsObject:vol])
+	    removed |= YES;
+	}
+
+      for (i = 0; i < [newVolumes count]; i++)
+	{
+	  NSString *vol;
+
+	  vol = [newVolumes objectAtIndex:i];
+	  if (![mountedRemovableVolumes containsObject:vol])
+	    added |= YES;
+	}
+
+      if (added || removed)
+	[manager mountedVolumesDidChange];
+
+      [mountedRemovableVolumes release];
+      mountedRemovableVolumes = newVolumes;
+      [mountedRemovableVolumes retain];
     }
-  }
 }
 
 @end
diff --git a/GWorkspace/Desktop/GWDesktopView.m b/GWorkspace/Desktop/GWDesktopView.m
index 402e948c..597a0440 100644
--- a/GWorkspace/Desktop/GWDesktopView.m
+++ b/GWorkspace/Desktop/GWDesktopView.m
@@ -159,9 +159,6 @@
   if ([mountedVolumes isEqual: rvpaths] == NO) {
     NSUInteger count = [icons count];
     int i;
-        
-    [mountedVolumes removeAllObjects];
-    [mountedVolumes addObjectsFromArray: rvpaths];
 
     for (i = 0; i < count; i++) {
       FSNIcon *icon = [icons objectAtIndex: i];
@@ -173,14 +170,15 @@
       }
     }
 
+    [mountedVolumes removeAllObjects];
+    [mountedVolumes addObjectsFromArray: rvpaths];
+
     for (i = 0; i < [mountedVolumes count]; i++) {
       NSString *vpath = [mountedVolumes objectAtIndex: i];
 
       if ([vpath isEqual: path_separator()] == NO) {
-        FSNode *vnode = [FSNode nodeWithPath: vpath];
 
-        [vnode setMountPoint: YES];
-        [self addRepForSubnode: vnode];
+	[self newVolumeMountedAtPath:vpath];
       }
     }
 
_______________________________________________
Discuss-gnustep mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/discuss-gnustep

Reply via email to