Fixed a harmless (as far as UQM is concerned) bug which caused unjustified

warnings with .zip files generated from DOS/Windows.

Fixed a potentially memory-corrupting bug when in a .zip file a subdir
is described before a dir higher in the dir hierarchy.

Fixed a bug where the path to a file was only partially printed in
an fprintf used in error handling. (harmless)

Renamed some functions to better reflect their functionality.


git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@1197 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
meep-eep
2003-09-05 03:12:19 +00:00
parent 9a86413eb4
commit e328972f6a
2 changed files with 23 additions and 22 deletions
+2
View File
@@ -112,6 +112,8 @@ uio_closeRepository(uio_Repository *repository) {
* be taken relative. * be taken relative.
* sourcePath - a path relative to sourceDir, which contains * sourcePath - a path relative to sourceDir, which contains
* the file/directory to be mounted. * the file/directory to be mounted.
* If sourceDir and sourcePath are NULL, the file
* system of the operating system will be used.
* inPath - the location relative to the root of the newly * inPath - the location relative to the root of the newly
* mounted fileSystem, pointing to the directory * mounted fileSystem, pointing to the directory
* that is to be grafted. * that is to be grafted.
+21 -22
View File
@@ -47,14 +47,14 @@ static int zip_badFile(zip_GPFileData *gPFileData, char *fileName);
static int zip_fillDirStructure(uio_GPDir *top, uio_Handle *handle); static int zip_fillDirStructure(uio_GPDir *top, uio_Handle *handle);
#if zip_USE_HEADERS == zip_USE_LOCAL_HEADERS #if zip_USE_HEADERS == zip_USE_LOCAL_HEADERS
static int zip_fillDirStructureLocal(uio_GPDir *top, uio_Handle *handle); static int zip_fillDirStructureLocal(uio_GPDir *top, uio_Handle *handle);
static int zip_fillDirStructureLocalProcessFile(uio_GPDir *topGPDir, static int zip_fillDirStructureLocalProcessEntry(uio_GPDir *topGPDir,
uio_FileBlock *fileBlock, off_t *pos); uio_FileBlock *fileBlock, off_t *pos);
#endif #endif
#if zip_USE_HEADERS == zip_USE_CENTRAL_HEADERS #if zip_USE_HEADERS == zip_USE_CENTRAL_HEADERS
static off_t zip_findEndOfCentralDirectoryRecord(uio_Handle *handle, static off_t zip_findEndOfCentralDirectoryRecord(uio_Handle *handle,
uio_FileBlock *fileBlock); uio_FileBlock *fileBlock);
static int zip_fillDirStructureCentral(uio_GPDir *top, uio_Handle *handle); static int zip_fillDirStructureCentral(uio_GPDir *top, uio_Handle *handle);
static int zip_fillDirStructureCentralProcessFile(uio_GPDir *topGPDir, static int zip_fillDirStructureCentralProcessEntry(uio_GPDir *topGPDir,
uio_FileBlock *fileBlock, off_t *pos); uio_FileBlock *fileBlock, off_t *pos);
static int zip_updatePFileDataFromLocalFileHeader(zip_GPFileData *gPFileData, static int zip_updatePFileDataFromLocalFileHeader(zip_GPFileData *gPFileData,
uio_FileBlock *fileBlock, int pos); uio_FileBlock *fileBlock, int pos);
@@ -641,7 +641,7 @@ zip_fillDirStructureCentral(uio_GPDir *top, uio_Handle *handle) {
pos = startCentralDir; pos = startCentralDir;
while (numEntries--) { while (numEntries--) {
if (zip_fillDirStructureCentralProcessFile(top, fileBlock, &pos) if (zip_fillDirStructureCentralProcessEntry(top, fileBlock, &pos)
== -1) { == -1) {
// errno is set // errno is set
goto err; goto err;
@@ -663,7 +663,7 @@ err:
} }
static int static int
zip_fillDirStructureCentralProcessFile(uio_GPDir *topGPDir, zip_fillDirStructureCentralProcessEntry(uio_GPDir *topGPDir,
uio_FileBlock *fileBlock, off_t *pos) { uio_FileBlock *fileBlock, off_t *pos) {
char *buf; char *buf;
zip_GPFileData *gPFileData; zip_GPFileData *gPFileData;
@@ -777,8 +777,6 @@ zip_fillDirStructureCentralProcessFile(uio_GPDir *topGPDir,
if (S_ISREG(gPFileData->mode)) { if (S_ISREG(gPFileData->mode)) {
if (zip_foundFile(topGPDir, fileName, gPFileData) == -1) { if (zip_foundFile(topGPDir, fileName, gPFileData) == -1) {
if (errno == EISDIR) { if (errno == EISDIR) {
fprintf(stderr, "Warning: file '%s' already exists as a dir - "
"skipped.\n", fileName);
zip_GPFileData_delete(gPFileData); zip_GPFileData_delete(gPFileData);
uio_free(fileName); uio_free(fileName);
return 0; return 0;
@@ -872,6 +870,7 @@ zip_makeFileMode(zip_OSType creatorOS, uio_uint32 modeBytes) {
case zip_OSType_FAT: case zip_OSType_FAT:
case zip_OSType_NTFS: case zip_OSType_NTFS:
case zip_OSType_VFAT: { case zip_OSType_VFAT: {
// Only the least signigicant byte is relevant.
mode_t mode; mode_t mode;
if (modeBytes == 0) { if (modeBytes == 0) {
@@ -879,7 +878,7 @@ zip_makeFileMode(zip_OSType creatorOS, uio_uint32 modeBytes) {
return S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | return S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP |
S_IROTH | S_IWOTH; S_IROTH | S_IWOTH;
} }
if (modeBytes & 0x00001000) { if (modeBytes & 0x10) {
// Directory // Directory
mode = S_IFDIR | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | mode = S_IFDIR | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP |
S_IROTH | S_IXOTH; S_IROTH | S_IXOTH;
@@ -887,7 +886,7 @@ zip_makeFileMode(zip_OSType creatorOS, uio_uint32 modeBytes) {
// Regular file // Regular file
mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH; mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH;
} }
if (modeBytes & 0x00000100) { if (modeBytes & 0x01) {
// readonly // readonly
return mode; return mode;
} else { } else {
@@ -998,7 +997,7 @@ zip_fillDirStructureLocal(uio_GPDir *top, uio_Handle *handle) {
break; break;
} }
pos += 4; pos += 4;
if (zip_fillDirStructureLocalProcessFile(top, fileBlock, &pos) == -1) if (zip_fillDirStructureLocalProcessEntry(top, fileBlock, &pos) == -1)
goto err; goto err;
} }
@@ -1016,7 +1015,7 @@ err:
} }
static int static int
zip_fillDirStructureLocalProcessFile(uio_GPDir *topGPDir, zip_fillDirStructureLocalProcessEntry(uio_GPDir *topGPDir,
uio_FileBlock *fileBlock, off_t *pos) { uio_FileBlock *fileBlock, off_t *pos) {
char *buf; char *buf;
zip_GPFileData *gPFileData; zip_GPFileData *gPFileData;
@@ -1149,8 +1148,6 @@ zip_fillDirStructureLocalProcessFile(uio_GPDir *topGPDir,
if (S_ISREG(gPFileData->mode)) { if (S_ISREG(gPFileData->mode)) {
if (zip_foundFile(topGPDir, fileName, gPFileData) == -1) { if (zip_foundFile(topGPDir, fileName, gPFileData) == -1) {
if (errno == EISDIR) { if (errno == EISDIR) {
fprintf(stderr, "Warning: file '%s' already exists as a dir - "
"skipped.\n", fileName);
zip_GPFileData_delete(gPFileData); zip_GPFileData_delete(gPFileData);
uio_free(fileName); uio_free(fileName);
return 0; return 0;
@@ -1332,6 +1329,7 @@ static inline int
zip_foundFile(uio_GPDir *gPDir, const char *path, zip_GPFileData *gPFileData) { zip_foundFile(uio_GPDir *gPDir, const char *path, zip_GPFileData *gPFileData) {
uio_GPFile *file; uio_GPFile *file;
size_t pathLen; size_t pathLen;
const char *rest;
const char *pathEnd; const char *pathEnd;
const char *start, *end; const char *start, *end;
char *buf; char *buf;
@@ -1347,7 +1345,7 @@ zip_foundFile(uio_GPDir *gPDir, const char *path, zip_GPFileData *gPFileData) {
} }
pathEnd = path + pathLen; pathEnd = path + pathLen;
switch (uio_walkGPPath(gPDir, path, pathLen, &gPDir, &path)) { switch (uio_walkGPPath(gPDir, path, pathLen, &gPDir, &rest)) {
case 0: case 0:
// The entire path was matched. The last part was not supposed // The entire path was matched. The last part was not supposed
// to be a dir. // to be a dir.
@@ -1365,7 +1363,7 @@ zip_foundFile(uio_GPDir *gPDir, const char *path, zip_GPFileData *gPFileData) {
} }
buf = uio_malloc(pathLen + 1); buf = uio_malloc(pathLen + 1);
getFirstPathComponent(path, pathEnd, &start, &end); getFirstPathComponent(rest, pathEnd, &start, &end);
while (1) { while (1) {
uio_GPDir *newGPDir; uio_GPDir *newGPDir;
@@ -1379,7 +1377,7 @@ zip_foundFile(uio_GPDir *gPDir, const char *path, zip_GPFileData *gPFileData) {
} }
if (end == pathEnd) { if (end == pathEnd) {
// This is the last component; it should be the name of the dir. // This is the last component; it should be the name of the dir.
path = start; rest = start;
break; break;
} }
memcpy(buf, start, end - start); memcpy(buf, start, end - start);
@@ -1398,7 +1396,7 @@ zip_foundFile(uio_GPDir *gPDir, const char *path, zip_GPFileData *gPFileData) {
file = uio_GPFile_new(gPDir->pRoot, (uio_GPFileExtra) gPFileData, file = uio_GPFile_new(gPDir->pRoot, (uio_GPFileExtra) gPFileData,
uio_gPFileFlagsFromPRootFlags(gPDir->pRoot->flags)); uio_gPFileFlagsFromPRootFlags(gPDir->pRoot->flags));
uio_GPDir_addFile(gPDir, path, file); uio_GPDir_addFile(gPDir, rest, file);
return 0; return 0;
} }
@@ -1406,6 +1404,7 @@ static inline int
zip_foundDir(uio_GPDir *gPDir, const char *path, zip_GPDirData *gPDirData) { zip_foundDir(uio_GPDir *gPDir, const char *path, zip_GPDirData *gPDirData) {
size_t pathLen; size_t pathLen;
const char *pathEnd; const char *pathEnd;
const char *rest;
const char *start, *end; const char *start, *end;
char *buf; char *buf;
@@ -1414,14 +1413,14 @@ zip_foundDir(uio_GPDir *gPDir, const char *path, zip_GPDirData *gPDirData) {
pathLen = strlen(path); pathLen = strlen(path);
pathEnd = path + pathLen; pathEnd = path + pathLen;
switch (uio_walkGPPath(gPDir, path, pathLen, &gPDir, &path)) { switch (uio_walkGPPath(gPDir, path, pathLen, &gPDir, &rest)) {
case 0: case 0:
// The dir already exists. Only need to add gPDirData // The dir already exists. Only need to add gPDirData
if (gPDir->extra) { if (gPDir->extra != NULL) {
fprintf(stderr, "Warning: '%s' is present more than once " fprintf(stderr, "Warning: '%s' is present more than once "
"in the zip file. Last entry will be used.\n", "in the zip file. The last entry will be used.\n",
path); path);
zip_GPDirData_free(gPDir->extra); zip_GPDirData_delete(gPDir->extra);
} }
gPDir->extra = gPDirData; gPDir->extra = gPDirData;
return 0; return 0;
@@ -1435,7 +1434,7 @@ zip_foundDir(uio_GPDir *gPDir, const char *path, zip_GPDirData *gPDirData) {
} }
buf = uio_malloc(pathLen + 1); buf = uio_malloc(pathLen + 1);
getFirstPathComponent(path, pathEnd, &start, &end); getFirstPathComponent(rest, pathEnd, &start, &end);
while (start < pathEnd) { while (start < pathEnd) {
uio_GPDir *newGPDir; uio_GPDir *newGPDir;
@@ -1453,12 +1452,12 @@ zip_foundDir(uio_GPDir *gPDir, const char *path, zip_GPDirData *gPDirData) {
newGPDir->flags |= uio_GPDir_COMPLETE; newGPDir->flags |= uio_GPDir_COMPLETE;
// It will be complete when we're done adding // It will be complete when we're done adding
// all files, and it won't be used before that. // all files, and it won't be used before that.
newGPDir->extra = gPDirData;
uio_GPDir_commitSubDir(gPDir, buf, newGPDir); uio_GPDir_commitSubDir(gPDir, buf, newGPDir);
gPDir = newGPDir; gPDir = newGPDir;
getNextPathComponent(pathEnd, &start, &end); getNextPathComponent(pathEnd, &start, &end);
} }
gPDir->extra = gPDirData;
uio_free(buf); uio_free(buf);
return 0; return 0;