I am trying to code my own API isFileOnARemoteVolume since I didn't find
anything similar on Cocoa. If any, please let me know.

I use statfs to detect whether the filePath I pass as variable is on a
remote volume. Anyway, this wont work in case of broken symlinks.
So I have used a dirty trick to get the volumePath then I pass the
volumePath  to the function statfs. Did I do right? Is a better or faster
way?

- (BOOL)isFileOnARemoteVolume:(NSString*)filePath
{    
    if([filePath length] == 0 ||
        [filePath characterAtIndex:0] != '/') return NO;
    
    NSMutableString    *volumePath = [NSMutableString
                                                stringWithString:@"/"];
    if([filePath startsWith:@"/Volumes"]){
        NSArray    *comps = [filePath componentsSeparatedByString:@"/"];
        [volumePath appendString:[comps objectAtIndex:1]];
        [volumePath appendString:@"/"];
        [volumePath appendString:[comps objectAtIndex:2]];
    }
    const char    *cPathVolume = [mManager
                        fileSystemRepresentationWithPath:volumePath];
    
    struct        statfs stf;
    if(statfs(cPathVolume, &stf) != 0) return NO;
    
    BOOL        isRemoteVolume = ((stf.f_flags & MNT_LOCAL) == 0);
    
    return isRemoteVolume;
}

On the previous version of this method I used FSGetVolParms then
(volParms.vMServerAdr != 0) but now I would like to avoid to use the Carbon
routines.

Regards
--
Leonardo


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to