2012-03-10 11 views
1

FSCopyURLForVolumeというファイルの完全なURLを取得する際に問題が発生しています。私はこの問題Determine AFP share from a file URLからコードを使用していますが、それは私に完全なURLを与えていません。以下のようなパスでFSCopyURLForVolumeの完全なURL

:たとえば/Volume/server/html/index.html

私は戻って取得すべてがベースのURLですマウント:nfs://real_server_name/vol

葉のディレクトリとファイル名がオフのままにされ、完全なパスはで利用可能ですファイル情報には、この情報を取得する方法が必要です。

EDIT:

いくつかのより多くの掘削をしたら、私は親ノード(ファイル)のIDを取得するためにkFSCatInfoParentDirIDkFSCatInfoNodeIDを使用したいが、私は何か有用なものにこれを有効にするかどうかはわかりませんように思えます。

+0

「FSCopyURLForVolume」は、実際にはボリュームの完全なURLを提供します。そのボリューム上のアイテムのURLが必要な場合は、その目的のためにNSURLのメソッドまたはCFURLの関数を使用して、自分で作成する必要があります。 –

答えて

0

この問題を解決するには、ここで私が思い付いた最後の関数である、Apple Dev Forums上で示唆された:FSPathMakeRef、FSGetCatalogInfoとFSCopyURLForVolumeは、マックOS X 10.8から廃止されましたので、

- (NSURL *)volumeMountPathFromPath:(NSString *)path{ 
    NSString *mountPath = nil; 
    NSString *testPath = [path copy]; 
    while(![testPath isEqualToString:@"/"]){ 
     NSURL *testUrl = [NSURL fileURLWithPath:testPath]; 
     NSNumber *isVolumeKey; 
     [testUrl getResourceValue:&isVolumeKey forKey:NSURLIsVolumeKey error:nil]; 
     if([isVolumeKey boolValue]){ 
      mountPath = testPath; 
      break; 
     }   
     testPath = [testPath stringByDeletingLastPathComponent]; 
    } 

    if(mountPath == nil){ 
     return nil; 
    } 

    NSString *pathCompointents = [path substringFromIndex:[mountPath length]]; 

    FSRef pathRef; 
    FSPathMakeRef((UInt8*)[path fileSystemRepresentation], &pathRef, NULL); 
    FSCatalogInfo catalogInfo; 
    OSErr osErr = FSGetCatalogInfo(&pathRef, kFSCatInfoVolume|kFSCatInfoParentDirID, 
            &catalogInfo, NULL, NULL, NULL); 
    FSVolumeRefNum volumeRefNum = 0; 
    if(osErr == noErr){ 
     volumeRefNum = catalogInfo.volume; 
    } 

    CFURLRef serverLocation; 
    OSStatus result = FSCopyURLForVolume(volumeRefNum, &serverLocation); 
    if(result == noErr){ 
     NSString *fullUrl = [NSString stringWithFormat:@"%@%@", 
          CFURLGetString(serverLocation), pathCompointents];   
     return [NSURL URLWithString:fullUrl]; 
    }else{ 
     NSLog(@"Error getting the mount path: %i", result); 
    } 
    return nil; 
} 
+1

なぜ 'stringWithFormat:'を使用していますか?別のURLに関連したURLを作成できます。 –

2

は、私は、コードを近代化Mac OS XがマウントしたボリュームでUNCネットワークパスを取得する

NSError *error=nil; //Error 
    NSURL *volumePath=nil; //result of UNC network mounting path 

    NSString* testPath [email protected]"/Volumes/SCAMBIO/testreport.exe"; //File path to test 

    NSURL *testUrl = [NSURL fileURLWithPath:testPath]; //Create a NSURL from file path 
    NSString* mountPath = [testPath stringByDeletingLastPathComponent]; //Get only mounted volume part i.e. /Volumes/SCAMBIO 
    NSString* pathComponents = [testPath substringFromIndex:[mountPath length]]; //Get the rest of the path starting after the mounted path i.e. /testereport.exe 
    [testUrl getResourceValue:&volumePath forKey:NSURLVolumeURLForRemountingKey error:&error]; //Get real UNC network mounted path i.e. smb://.... 

    NSLog(@"Path: %@%@", volumePath,pathComponents); //Write result to debug console 

結果は、私の場合には パスです:SMB://[email protected]/SCAMBIO/testreport.exe

あなたのネットワークマッピングされたボリュームを指定する必要があります。

ciao。

関連する問題