static int fetchFileSpec(FSSpec *spec,unsigned char *name,long *parentDirectory) { long aliasGestaltInfo; CInfoPBRec pb; Boolean result,ignore; FSSpec spec2; OSErr err; pb.hFileInfo.ioNamePtr = name; pb.hFileInfo.ioFVersNum = 0; pb.hFileInfo.ioFDirIndex = 0; pb.hFileInfo.ioVRefNum = spec->vRefNum; pb.hFileInfo.ioDirID = spec->parID; if (PBGetCatInfoSync(&pb) == noErr) { if (pb.hFileInfo.ioFlFndrInfo.fdFlags & kIsAlias) { err = FSMakeFSSpecCompat(spec->vRefNum, spec->parID, name,&spec2); #if TARGET_CPU_PPC if ((Gestalt(gestaltAliasMgrAttr, &aliasGestaltInfo) == noErr) && aliasGestaltInfo & (1<<gestaltAliasMgrResolveAliasFileWithMountOptions) && ((Ptr) ResolveAliasFileWithMountFlags != (Ptr)kUnresolvedCFragSymbolAddress)) { err = ResolveAliasFileWithMountFlags(&spec2,false,&ignore,&ignore,kResolveAliasFileNoUI); } else #endif err = ResolveAliasFile(&spec2,false,&ignore,&ignore); if (err == noErr) { fetchFileSpec(&spec2,spec2.name,parentDirectory); *spec = spec2; result = true; goto done; } } spec->parID = pb.hFileInfo.ioDirID; result = true; goto done; } result = false; done: if (parentDirectory != nil) *parentDirectory = pb.dirInfo.ioDrParID; return result; }
/*Get the file ID that unique IDs this file or directory, also resolve any alias if required */ int fetchFileInfo(int dirIndex,FSSpec *spec,unsigned char *name,Boolean doAlias,long *parentDirectory, int *isFolder,int *createDateStorage,int *modificationDateStorage,squeakFileOffsetType *sizeOfFile,Str255 *longFileName) { long aliasGestaltInfo; CInfoPBRec pb; Boolean isFolder2; OSErr error,result; *isFolder = false; pb.hFileInfo.ioNamePtr = name; pb.hFileInfo.ioFVersNum = 0; pb.hFileInfo.ioFDirIndex = dirIndex; pb.hFileInfo.ioVRefNum = spec->vRefNum; pb.hFileInfo.ioDirID = spec->parID; if ((error = PBGetCatInfoSync(&pb)) == noErr) { if ((pb.hFileInfo.ioFlFndrInfo.fdFlags & kIsAlias) && doAlias) { FSSpec spec2,spec3; Boolean isAlias; OSErr err; err = FSMakeFSSpecCompat(spec->vRefNum, spec->parID, name,&spec2); spec3 = spec2; #if TARGET_CPU_PPC if ((Gestalt(gestaltAliasMgrAttr, &aliasGestaltInfo) == noErr) && aliasGestaltInfo & (1<<gestaltAliasMgrResolveAliasFileWithMountOptions) && ((Ptr) ResolveAliasFileWithMountFlags != (Ptr)kUnresolvedCFragSymbolAddress)) { err = ResolveAliasFileWithMountFlags(&spec2,false,&isFolder2,&isAlias,kResolveAliasFileNoUI); } else { err = ResolveAliasFile(&spec2,false,&isFolder2,&isAlias); } #else err = ResolveAliasFile(&spec2,false,&isFolder2,&isAlias); #endif *isFolder = isFolder2; if (err == noErr) { resolveLongName(0,0,nil,&spec3,*isFolder,longFileName,sizeOfFile); result = noErr; goto done; } } if ((pb.hFileInfo.ioFlAttrib & kioFlAttribDirMask) != 0) *sizeOfFile = 0; else *sizeOfFile = pb.hFileInfo.ioFlLgLen; resolveLongName(pb.hFileInfo.ioVRefNum,pb.hFileInfo.ioFlParID,name,nil,((pb.hFileInfo.ioFlAttrib & kioFlAttribDirMask) > 0),longFileName,sizeOfFile); spec->parID = pb.hFileInfo.ioDirID; result = noErr; goto done; } result = error; memcpy(longFileName,name,sizeof(StrFileName)); done: *isFolder = ((pb.hFileInfo.ioFlAttrib & kioFlAttribDirMask) > 0) || *isFolder; *createDateStorage = pb.hFileInfo.ioFlCrDat; *modificationDateStorage = pb.hFileInfo.ioFlMdDat; *parentDirectory = pb.dirInfo.ioDrParID; return result; }
static OSErr fnameToFSSpec(const char *fname, FSSpec *spec) { Boolean alias = 0; Boolean folder = 0; OSErr err = fnameToFSSpecNoAlias(fname, spec); if (err == dirNFErr) /* might be an alias in the middle of the path. */ { /* * Has to be at least two ':' chars, or we wouldn't get a * dir-not-found condition. (no ':' means it was just a volume, * just one ':' means we would have gotten a fnfErr, if anything. */ char *ptr; char *start; char *path = alloca(strlen(fname) + 1); strcpy(path, fname); ptr = strchr(path, ':'); BAIL_IF_MACRO(!ptr, ERR_NO_SUCH_FILE, err); /* just in case */ ptr = strchr(ptr + 1, ':'); BAIL_IF_MACRO(!ptr, ERR_NO_SUCH_FILE, err); /* just in case */ *ptr = '\0'; err = fnameToFSSpecNoAlias(path, spec); /* get first dir. */ BAIL_IF_MACRO(oserr(err) != noErr, NULL, err); start = ptr; ptr = strchr(start + 1, ':'); /* Now check each element of the path for aliases... */ do { CInfoPBRec infoPB; memset(&infoPB, '\0', sizeof (CInfoPBRec)); infoPB.dirInfo.ioNamePtr = spec->name; infoPB.dirInfo.ioVRefNum = spec->vRefNum; infoPB.dirInfo.ioDrDirID = spec->parID; infoPB.dirInfo.ioFDirIndex = 0; err = PBGetCatInfoSync(&infoPB); if (err != noErr) /* not an alias, really just a bogus path. */ return(fnameToFSSpecNoAlias(fname, spec)); /* reset */ if ((infoPB.dirInfo.ioFlAttrib & kioFlAttribDirMask) != 0) spec->parID = infoPB.dirInfo.ioDrDirID; if (ptr != NULL) /* terminate string after next element. */ *ptr = '\0'; *start = strlen(start + 1); /* make it a pstring. */ err = FSMakeFSSpec(spec->vRefNum, spec->parID, (const unsigned char *) start, spec); if (err != noErr) /* not an alias, really a bogus path. */ return(fnameToFSSpecNoAlias(fname, spec)); /* reset */ err = ResolveAliasFileWithMountFlags(spec, 1, &folder, &alias, 0); if (err != noErr) /* not an alias, really a bogus path. */ return(fnameToFSSpecNoAlias(fname, spec)); /* reset */ start = ptr; /* move to the next element. */ if (ptr != NULL) ptr = strchr(start + 1, ':'); } while (start != NULL); } /* if */ else /* there's something there; make sure final file is not an alias. */ { BAIL_IF_MACRO(oserr(err) != noErr, NULL, err); err = ResolveAliasFileWithMountFlags(spec, 1, &folder, &alias, 0); BAIL_IF_MACRO(oserr(err) != noErr, NULL, err); } /* else */ return(noErr); /* w00t. */ } /* fnameToFSSpec */