Minor brainfart fix in verifySecurity() and optimized mkdir().

This commit is contained in:
Ryan C. Gordon 2003-03-19 06:31:53 +00:00
parent 8bdc0ea570
commit 3744f54064
1 changed files with 8 additions and 6 deletions

View File

@ -1232,14 +1232,14 @@ int __PHYSFS_verifySecurity(DirHandle *h, const char *fname, int allowMissing)
} /* if */ } /* if */
/* break out early if path element is missing. */ /* break out early if path element is missing. */
if ((!retval) && (!allowMissing)) if (!retval)
{ {
/* /*
* We need to clear it if it's the last element of the path, * We need to clear it if it's the last element of the path,
* since this might be a non-existant file we're opening * since this might be a non-existant file we're opening
* for writing... * for writing...
*/ */
if (end == NULL) if ((end == NULL) || (allowMissing))
retval = 1; retval = 1;
break; break;
} /* if */ } /* if */
@ -1264,6 +1264,7 @@ int PHYSFS_mkdir(const char *dname)
char *start; char *start;
char *end; char *end;
int retval = 0; int retval = 0;
int exists = 1; /* force existance check on first path element. */
BAIL_IF_MACRO(dname == NULL, ERR_INVALID_ARGUMENT, 0); BAIL_IF_MACRO(dname == NULL, ERR_INVALID_ARGUMENT, 0);
while (*dname == '/') while (*dname == '/')
@ -1279,14 +1280,15 @@ int PHYSFS_mkdir(const char *dname)
while (1) while (1)
{ {
int already_exists;
end = strchr(start, '/'); end = strchr(start, '/');
if (end != NULL) if (end != NULL)
*end = '\0'; *end = '\0';
retval = h->funcs->isDirectory(h, str, &already_exists); /* only check for existance if all parent dirs existed, too... */
if ((!retval) && (!already_exists)) if (exists)
retval = h->funcs->isDirectory(h, str, &exists);
if (!exists)
retval = h->funcs->mkdir(h, str); retval = h->funcs->mkdir(h, str);
if (!retval) if (!retval)