• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Detecting a remote volume
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Detecting a remote volume


  • Subject: Re: Detecting a remote volume
  • From: Mark Fleming <email@hidden>
  • Date: Wed, 04 Aug 2010 09:10:36 -0400


Date: Mon, 2 Aug 2010 21:26:36 +0200 From: Knut Lorenzen <email@hidden> Subject: Detecting a remote volume To: Cocoa-Dev <email@hidden> Message-ID: <email@hidden> Content-Type: text/plain; charset=us-ascii


Dear List,

my app should copy a few files to a remote (afp://) volume, hence it notifies the user if there is no connection, using NSFileManager's fileExistsAtPath: method.

However, if the user connects to the Server using Finder's "Connect As...", NSFileManager's fileExistsAtPath: @"/Volumes/Mailbackup" still returns NO. It only works, i.e. returns YES, if the user actually clicks on the "Mailbackup" folder in Finder. There is no entry in "/Volumes" either, until the user clicks.

Instead of fileExistsAtPath: I have tried several other methods (like isReadableFileAtPath: or changeCurrentDirectoryPath:) as well as NSWorkspace's mountedLocalVolumePaths to no avail. It only works after actually opening the folder in Finder.

Is there a way to update NSFileManager or NSWorkspace without opening the folder in question?

Knut

Here is what I use for:
- detecting WebDAV Volumes... can change the -t to afp to list AFP volumes.
- for mounting and unmounting WebDAV volumes.


In terminal.app see 'man mount' for more information about /sbin/mount

- (void) updateMountList
{
// list currently mounted items: /sbin/mount -t webdav -v
NSData *output = [NTSynchronousTask task:@"/sbin/mount" directory: @"/" withArgs:[NSArray arrayWithObjects:@"-t", @"webdav",nil] input:nil];
NSMutableString *strData = [[NSMutableString alloc] initWithData:output encoding:NSUTF8StringEncoding];

[strData replaceOccurrencesOfString:@" on " withString:@"\n\t at:" options:NSCaseInsensitiveSearch
range:NSMakeRange(0,[strData length])];

NSLog(@"current Mounts: %@", strData);
[currentDAVMounts setStringValue:strData];
}


/*
OSStatus FSMountServerVolumeSync ( CFURLRef url,
CFURLRef mountDir,
CFStringRef user,
CFStringRef password,
FSVolumeRefNum * mountedVolumeRefNum,
OptionBits flags
);
Parameters
url The server to mount.
mountDir The directory to mount the server to. If this parameter is NULL, the default location is used.
user A string to pass as the user for authentication.
password A string to pass as the password for authenticated log in.
mountedVolumeRefNum On return, a pointer to the volume reference number of the newly mounted volume.
flags Options for future use.


 Return Value
 A result code. See “File Manager Result Codes”.

Discussion
This function will mount the server specified by the url parameter at the location specified by the mountDir parameter. If mountDir is NULL, the default locationis used. An optional user and password can be passed in for authentication. If no user or password is provided then the underlying file system will handle authentication if required. This function returns after the mount is complete.


 */


- (OSStatus) Mount { CFURLRef url, mountDir = nil; CFStringRef user = nil, password = nil;

	NSString *urlStr = [[self mountItem] objectForKey:urlKey];
	NSString *path = [[self mountItem] objectForKey:openKey];

	if (path) {
		if ([urlStr hasSuffix:@"/"])
				urlStr = [urlStr stringByAppendingString: path];
		else	urlStr = [urlStr stringByAppendingFormat:@"/%@",path];
	}

	user = (CFStringRef) [[self mountItem] objectForKey:usernameKey];

// This method expects URLString to contain any necessary percent escape codes, which are ‘:’, ‘/’, ‘%’, ‘#’, ‘;’, and ‘@’. Note that ‘%’ escapes are translated via UTF-8.
url = (CFURLRef) [NSURL URLWithString: urlStr];
// NSLog(@"url = %@", url);


OSStatus rc = FSMountServerVolumeSync ( url, mountDir, user, password, (FSVolumeRefNum * )&mountedVolumeRefNum, 0);
if (rc) NSLog(@" Mount failed with RC = %ld (-48 already mounted, -5016 = Server not responding)", rc);
return rc;
}
/*
Parameters
vRefNum The volume reference number of the volume to unmount.
flags Options for future use.
dissenter On return, a pointer to the pid of the process which denied the unmount if the unmount is denied.


 Return Value
 A result code. See “File Manager Result Codes”.

Discussion
This function unmounts the volume specified by the vRefNum parameter. If the volume cannot be unmounted the pid of the process which denied the u
*/
- (OSStatus) unMount
{ pid_t dissenter;


OSStatus rc = FSUnmountVolumeSync ((int) mountedVolumeRefNum, 0, &dissenter);
if (rc) NSLog(@" unMount failed with RC = %ld (-5016 = Server not responding)", rc);
return rc;

}_______________________________________________


Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Detecting a remote volume
      • From: Knut Lorenzen <email@hidden>
  • Prev by Date: Re: Need help understanding first responder and multiple nibs
  • Next by Date: Re: Detecting a remote volume
  • Previous by thread: Re: Detecting a remote volume
  • Next by thread: Re: Detecting a remote volume
  • Index(es):
    • Date
    • Thread