52- (NSData *)bookmarkDataWithOptions:(
unsigned long)options includingResourceValuesForKeys:(NSArray *)keys relativeToURL:(NSURL *)relativeURL error:(NSError **)error;
56+ (id)URLByResolvingBookmarkData:(NSData *)bookmarkData options:(
unsigned long)options relativeToURL:(NSURL *)relativeURL bookmarkDataIsStale:(BOOL *)isStale error:(NSError **)error;
73 if (url ==
nil)
return nil;
75 NSMutableDictionary *result = [NSMutableDictionary dictionaryWithCapacity:3];
76 [result setObject:[url absoluteString] forKey:kURLKey];
81 if (CFURLGetFSRef((CFURLRef)[url absoluteURL], &fsRef))
83 AliasHandle alias = NULL;
84 if (FSNewAlias(NULL, &fsRef, &alias) == noErr)
86 NSData *aliasData = [NSData dataWithBytes:*alias length:GetAliasSize(alias)];
87 if (aliasData != NULL)
89 [result setObject:aliasData forKey:kAliasKey];
91 DisposeHandle((Handle)alias);
98 NSURL *refURL = [url fileReferenceURL];
101 NSData *bookmarkData = [refURL bookmarkDataWithOptions:0
102 includingResourceValuesForKeys:nil
105 if (bookmarkData !=
nil)
107 [result setObject:bookmarkData forKey:kBookmarkKey];
136 BOOL stale = NO, staleIfFile = NO;
141 NSData *bookmarkData = [fileRef objectForKey:kBookmarkKey];
142 if ([bookmarkData isKindOfClass:[NSData
class]])
144 result = [NSURL URLByResolvingBookmarkData:bookmarkData
145 options:BookmarkOptionsFromFlags(flags)
147 bookmarkDataIsStale:&stale
150 else staleIfFile = YES;
156 NSData *aliasData = [fileRef objectForKey:kAliasKey];
157 if ([aliasData isKindOfClass:[NSData
class]])
159 size_t size = [aliasData length];
160 AliasHandle alias = (AliasHandle)NewHandle(
size);
163 memcpy(*alias, [aliasData bytes],
size);
170 result = (NSURL *)CFURLCreateFromFSRef(kCFAllocatorDefault, &fsRef);
171#if 1050 <= MAC_OS_X_VERSION_MAX_ALLOWED
172 CFMakeCollectable((CFURLRef)result);
174 [result autorelease];
176 DisposeHandle((Handle)alias);
179 else staleIfFile = YES;
185 NSString *urlString = [fileRef objectForKey:kURLKey];
186 if ([urlString isKindOfClass:[NSString
class]])
188 result = [NSURL URLWithString:urlString relativeToURL:nil];
189 if ([result isFileURL] && ![[NSFileManager defaultManager] fileExistsAtPath:[result path]])
203 if ([result isFileURL] && staleIfFile) stale = YES;
210 if (![result isFileReferenceURL] && [result isFileURL])
212 NSURL *refURL = [result fileReferenceURL];
213 if (refURL !=
nil) result = refURL;
218 if ([result isFileReferenceURL])
220 NSURL *pathURL = [result filePathURL];
221 if (pathURL !=
nil) result = pathURL;
228 if (isStale != NULL) *isStale = stale;