From: Rolf K. <lab...@us...> - 2008-02-27 20:48:18
|
Update of /cvsroot/opengtoolkit/lvzip/c_source In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv15572 Modified Files: lvutil.c Log Message: Made some changes that hopefully will get the Mac OS X long path problem simpler to handle Index: lvutil.c =================================================================== RCS file: /cvsroot/opengtoolkit/lvzip/c_source/lvutil.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** lvutil.c 17 Dec 2007 13:41:22 -0000 1.6 --- lvutil.c 27 Feb 2008 20:48:21 -0000 1.7 *************** *** 8,11 **** --- 8,12 ---- #include <stdio.h> #include <string.h> + #define ZLIB_INTERNAL #include "zlib.h" #include "ioapi.h" *************** *** 39,42 **** --- 40,96 ---- #if Mac + static OSErr FSpLocationFromFullPath(CStr fullPath, + int32 fullPathLength, + FSSpec *spec) + { + AliasHandle alias; + OSErr err; + Boolean wasChanged; + Str32 nullString; + + if (fullPathLength < 255) { + StringPtr myString = (StringPtr)DSNewPtr(fullPathLength + 1); + + MoveBlock(fullPath, myString + 1, fullPathLength); + myString[0] = (uInt8)fullPathLength; + + err = FSMakeFSSpec(0, 0L, myString, spec); + if (err) + { + DEBUGPRINTF(("FSMakeFSSpec: err = %d", err)); + if (fnfErr == err) + { + /* fileNotFound is expected and normal. */ + err = mgNoErr; + } + } + DSDisposePtr(myStringPtr); + } + else { + /* Create a minimal alias from the full pathname */ + nullString[0] = 0; /* null string to indicate no zone or server name */ + err = NewAliasMinimalFromFullPath(fullPathLength, fullPath, nullString, nullString, &alias); + if (err == noErr) + { + /* Let the Alias Manager resolve the alias. */ + err = ResolveAlias(NULL, alias, spec, &wasChanged); + if (err) + { + DEBUGPRINTF(("ResolveAlias: err = %d", err)); + } + /* work around Alias Mgr sloppy volume matching bug */ + if (spec->vRefNum == 0) + { + /* invalidate wrong FSSpec */ + spec->parID = 0; + spec->name[0] = 0; + err = nsvErr; + } + DisposeHandle((Handle)alias); /* Free up memory used */ + } + } + return (err); + } + static MgErr MakeMacSpec(Path path, FSSpec *fss) { *************** *** 46,62 **** DEBUGPRINTF(("FPathToText1: path = %z", path)); err = FPathToText(path, (LStrPtr)&pathLen); ! if (err) ! { ! DEBUGPRINTF(("FPathToText2: err = %ld", err)); ! } ! else { - OSErr ret; LStrPtr lstr; - Str255 name; - if (pathLen > 255) - return mgArgErr; - lstr = (LStrPtr)DSNewPClr(sizeof(int32) + pathLen + 1); if (!lstr) --- 100,107 ---- DEBUGPRINTF(("FPathToText1: path = %z", path)); err = FPathToText(path, (LStrPtr)&pathLen); ! if (!err) { LStrPtr lstr; lstr = (LStrPtr)DSNewPClr(sizeof(int32) + pathLen + 1); if (!lstr) *************** *** 66,81 **** err = FPathToText(path, lstr); lstr->str[lstr->cnt] = 0; ! if (err) ! { ! DEBUGPRINTF(("FPathToText3: err = %ld", err)); ! } ! else { ! CToPStr(lstr->str, name); ! ret = MakeFileSpec(0, 0, name, fss); ! err = OSErrToLVErr(ret); if (err) ! DEBUGPRINTF(("MakeFileSpec: ret = %d, err = %ld, len = %ld, len2 = %d, path = %s", ! ret, err, lstr->cnt, (int16)name[0], lstr->str)); } DSDisposePtr(lstr); --- 111,120 ---- err = FPathToText(path, lstr); lstr->str[lstr->cnt] = 0; ! if (!err) { ! err = OSErrToLVErr(FSpLocationFromFullPath(lstr->str, lstr->cnt, fss)); if (err) ! DEBUGPRINTF(("FSpLocationFromFullPath: err = %ld, len = %ld, path = %s", ! err, lstr->cnt, lstr->str)); } DSDisposePtr(lstr); *************** *** 99,103 **** /* MacOSX seems to return sometimes bdNamErr for longer filenames, so we try to catch that too. */ ! Str255 temp; DEBUGPRINTF(("MakeFileSpec: trying with subpaths")); --- 138,142 ---- /* MacOSX seems to return sometimes bdNamErr for longer filenames, so we try to catch that too. */ ! Str255 temp = NULL; DEBUGPRINTF(("MakeFileSpec: trying with subpaths")); *************** *** 108,114 **** hpb.volumeParam.ioVRefNum = vRefNum; if (path == NULL ) { - hpb.volumeParam.ioNamePtr = NULL; hpb.volumeParam.ioVolIndex = 0; /* use ioVRefNum only */ } --- 147,153 ---- hpb.volumeParam.ioVRefNum = vRefNum; + hpb.volumeParam.ioNamePtr = (StringPtr)temp; if (path == NULL ) { hpb.volumeParam.ioVolIndex = 0; /* use ioVRefNum only */ } *************** *** 116,120 **** { PStrCpy(temp, path); ! hpb.volumeParam.ioNamePtr = (StringPtr)temp; hpb.volumeParam.ioVolIndex = -1; /* use ioNamePtr/ioVRefNum combination */ } --- 155,159 ---- { PStrCpy(temp, path); ! hpb.volumeParam.ioNamePtr = temp; hpb.volumeParam.ioVolIndex = -1; /* use ioNamePtr/ioVRefNum combination */ } *************** *** 133,137 **** /* remove the last elt(s) of the path and see if we have success */ ! PStrCpy(temp, path); p = (uChar*)&temp[PStrLen(path)]; --- 172,177 ---- /* remove the last elt(s) of the path and see if we have success */ ! if (path) ! PStrCpy(temp, path); p = (uChar*)&temp[PStrLen(path)]; *************** *** 147,151 **** } if (p <= temp) ! return err; PStrLen(temp) = PStrLen(path) - i; err = FSMakeFSSpec(vRefNum, dirID, temp, &fst); --- 187,191 ---- } if (p <= temp) ! return bdNamErr; PStrLen(temp) = PStrLen(path) - i; err = FSMakeFSSpec(vRefNum, dirID, temp, &fst); *************** *** 162,168 **** memset(&cpb, 0, sizeof(CInfoPBRec)); cpb.hFileInfo.ioNamePtr = fst.name; ! cpb.hFileInfo.ioVRefNum = vRefNum; cpb.hFileInfo.ioDirID = fst.parID; ! cpb.dirInfo.ioFDirIndex = 0; /* use ioNamePtr and ioDirID */ err = OSErrToLVErr(PBGetCatInfoSync(&cpb)); if (err) --- 202,208 ---- memset(&cpb, 0, sizeof(CInfoPBRec)); cpb.hFileInfo.ioNamePtr = fst.name; ! cpb.hFileInfo.ioVRefNum = fst.vRefNum; cpb.hFileInfo.ioDirID = fst.parID; ! cpb.hFileInfo.ioFDirIndex = 0; /* use ioNamePtr and ioDirID */ err = OSErrToLVErr(PBGetCatInfoSync(&cpb)); if (err) *************** *** 170,174 **** else { ! err = MakeFileSpec(vRefNum, cpb.dirInfo.ioDrDirID, p, fss); if (err) DEBUGPRINTF(("MakeFileSpec: err = %ld, path = %p", err, p)); --- 210,214 ---- else { ! err = MakeFileSpec(fst.vRefNum, cpb.dirInfo.ioDrDirID, p, fss); if (err) DEBUGPRINTF(("MakeFileSpec: err = %ld, path = %p", err, p)); |