Re: FSRefMakePath: error -35
Re: FSRefMakePath: error -35
- Subject: Re: FSRefMakePath: error -35
- From: Lawrence Sanbourne <email@hidden>
- Date: Sat, 22 Oct 2005 23:20:55 -0500
On 10/22/05, Rosyna <email@hidden> wrote:
> I'm very interested in what happens from the time you get the FSRef
> to the time you try to get the path (the code you are using for that).
Here's the full source for the function. I've put a /////////// near
the line that's giving the error.
Thanks for your help!
Larry
/*
Adapted from <http://www.cocoabuilder.com/archive/message/cocoa/2005/5/21/136555>.
*/
unsigned long long LSDirectorySizeAtPath(NSString *inPath)
{
unsigned long long totalSize = 0;
FSIterator thisDirEnum;
FSRef *theFileRef;
OSStatus makePathErr = FSRefMakePath(theFileRef, (UInt8 *)[inPath
UTF8String], [inPath length]);
if (makePathErr != noErr) {
NSLog(@"LSDirectorySizeAtPath: Unable to make path %@ into an FSRef:
error %d", inPath, makePathErr);
return totalSize;
}
if (FSOpenIterator(theFileRef, kFSIterateFlat, &thisDirEnum) == noErr)
{
const ItemCount kMaxEntriesPerFetch = 256;
typedef struct SFetchedInfo
{
FSRef fFSRefs[kMaxEntriesPerFetch];
FSCatalogInfo fInfos[kMaxEntriesPerFetch];
} SFetchedInfo;
// might as well allocate all the storage with a single call...
SFetchedInfo *fetched = (SFetchedInfo *)malloc(sizeof(SFetchedInfo));
if (fetched != NULL) {
ItemCount actualFetched;
OSErr fsErr = FSGetCatalogInfoBulk(thisDirEnum,
kMaxEntriesPerFetch, &actualFetched,
NULL, kFSCatInfoDataSizes |
kFSCatInfoNodeFlags, fetched->fInfos,
fetched->fFSRefs, NULL, NULL);
while (fsErr == noErr || fsErr == errFSNoMoreItems) {
ItemCount thisIndex;
for (thisIndex = 0; thisIndex < actualFetched; ++thisIndex) {
// Recurse if it's a directory.
if (fetched->fInfos[thisIndex].nodeFlags &
kFSNodeIsDirectoryMask) {
UInt8 utf8Path[PATH_MAX];
OSStatus makePathErr =
FSRefMakePath(&fetched->fFSRefs[thisIndex], utf8Path, PATH_MAX);
if (makePathErr == noErr)
totalSize += LSDirectorySizeAtPath([NSString
stringWithUTF8String:(char *)utf8Path]);///////////
else
NSLog(@"LSDirectorySizeAtPath: Error making FSRef into path:
error %d", makePathErr);
} else {
// add the size for this item
totalSize += fetched->fInfos[thisIndex].dataLogicalSize;
}
}
if (fsErr == errFSNoMoreItems) {
break;
} else {
// get more items
fsErr = FSGetCatalogInfoBulk(thisDirEnum,
kMaxEntriesPerFetch, &actualFetched,
NULL, kFSCatInfoDataSizes |
kFSCatInfoNodeFlags, fetched->fInfos,
fetched->fFSRefs, NULL, NULL);
}
}
free(fetched);
}
FSCloseIterator(thisDirEnum);
}
return totalSize;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden