Author: rmottola Date: Sat Feb 13 23:20:20 2016 New Revision: 39370 URL: http://svn.gna.org/viewcvs/gnustep?rev=39370&view=rev Log: Enhance unmount with eject support on certain platforms, generate NSWorkspaceWillUnmountNotification notification.
Modified: libs/gui/trunk/ChangeLog libs/gui/trunk/Source/NSWorkspace.m Modified: libs/gui/trunk/ChangeLog URL: http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/ChangeLog?rev=39370&r1=39369&r2=39370&view=diff ============================================================================== --- libs/gui/trunk/ChangeLog (original) +++ libs/gui/trunk/ChangeLog Sat Feb 13 23:20:20 2016 @@ -1,3 +1,8 @@ +2016-02-13 Riccardo Mottola <r...@gnu.org> + + * Source/NSWorkspace.m (unmountAndEjectDeviceAtPath:) + Enhance unmount with eject support on certain platforms, generate NSWorkspaceWillUnmountNotification notification. + 2016-02-12 Riccardo Mottola <r...@gnu.org> * Source/NSWorkspace.m Modified: libs/gui/trunk/Source/NSWorkspace.m URL: http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/Source/NSWorkspace.m?rev=39370&r1=39369&r2=39370&view=diff ============================================================================== --- libs/gui/trunk/Source/NSWorkspace.m (original) +++ libs/gui/trunk/Source/NSWorkspace.m Sat Feb 13 23:20:20 2016 @@ -1804,44 +1804,87 @@ } /* - * Unmounting a Device + * Unmounting a Device and eject if possible */ - (BOOL) unmountAndEjectDeviceAtPath: (NSString*)path { + NSUInteger systype = [[NSProcessInfo processInfo] operatingSystem]; NSDictionary *userinfo; NSTask *task; - BOOL flag = NO; + + /* let's check if it is a local volume we may unmount */ + if (![[self mountedLocalVolumePaths] containsObject:path]) + { + NSLog(@"unmountAndEjectDeviceAtPath: Path %@ not mounted"); + return NO; + } userinfo = [NSDictionary dictionaryWithObject: path forKey: @"NSDevicePath"]; [_workspaceCenter postNotificationName: NSWorkspaceWillUnmountNotification object: self userInfo: userinfo]; - - // FIXME This is system specific - task = [NSTask launchedTaskWithLaunchPath: @"eject" + task = [NSTask launchedTaskWithLaunchPath: @"umount" arguments: [NSArray arrayWithObject: path]]; - if (task != nil) + + if (task) { [task waitUntilExit]; if ([task terminationStatus] != 0) { return NO; - } - else - { - flag = YES; - } + } } else { return NO; } - [_workspaceCenter postNotificationName: NSWorkspaceDidUnmountNotification - object: self - userInfo: userinfo]; - return flag; + [[self notificationCenter] postNotificationName: NSWorkspaceDidUnmountNotification + object: self + userInfo: userinfo]; + + /* this is system specific and we try our best + and the failure of eject doesn't mean unmount failed */ + task = nil; + if (systype == NSGNULinuxOperatingSystem) + { + task = [NSTask launchedTaskWithLaunchPath: @"eject" + arguments: [NSArray arrayWithObject: path]]; + } + else if (systype == NSBSDOperatingSystem || systype == NSSolarisOperatingSystem) + { + NSString *mountDir; + + // Note: it would be better to check the device, not the mount point + mountDir = [path lastPathComponent]; + if ([mountDir rangeOfString:@"cd"].location != NSNotFound || + [mountDir rangeOfString:@"dvd"].location != NSNotFound) + { + task = [NSTask launchedTaskWithLaunchPath: @"eject" + arguments: [NSArray arrayWithObject: @"cdrom"]]; + } + else if ([mountDir rangeOfString:@"fd"].location != NSNotFound || + [mountDir rangeOfString:@"floppy"].location != NSNotFound) + { + task = [NSTask launchedTaskWithLaunchPath: @"eject" + arguments: [NSArray arrayWithObject: @"floppy"]]; + } + } + else + { + NSLog(@"Don't know how to eject on %@", systype); + } + if (task != nil) + { + [task waitUntilExit]; + if ([task terminationStatus] != 0) + { + NSLog(@"eject failed"); + } + } + + return YES; } /* _______________________________________________ Gnustep-cvs mailing list Gnustep-cvs@gna.org https://mail.gna.org/listinfo/gnustep-cvs