PHYSFS_setWriteDir() shouldn't create an empty file if the dir doesn't exist. default
authorRyan C. Gordon <icculus@icculus.org>
Wed, 16 May 2018 19:54:51 -0400
changeset 1643 2653b3bc19c9
parent 1642 ccfe2177e394
PHYSFS_setWriteDir() shouldn't create an empty file if the dir doesn't exist.
src/physfs.c
--- a/src/physfs.c	Thu Apr 19 10:06:38 2018 -0400
+++ b/src/physfs.c	Wed May 16 19:54:51 2018 -0400
@@ -879,13 +879,20 @@
 
     if (io == NULL)
     {
+        /* file doesn't exist, etc? Just fail out. */
+        PHYSFS_Stat statbuf;
+        BAIL_IF_ERRPASS(!__PHYSFS_platformStat(d, &statbuf, 1), NULL);
+
         /* DIR gets first shot (unlike the rest, it doesn't deal with files). */
-        retval = tryOpenDir(io, &__PHYSFS_Archiver_DIR, d, forWriting, &claimed);
-        if (retval || claimed)
-            return retval;
+        if (statbuf.filetype == PHYSFS_FILETYPE_DIRECTORY)
+        {
+            retval = tryOpenDir(io, &__PHYSFS_Archiver_DIR, d, forWriting, &claimed);
+            if (retval || claimed)
+                return retval;
+        } /* if */
 
         io = __PHYSFS_createNativeIo(d, forWriting ? 'w' : 'r');
-        BAIL_IF_ERRPASS(!io, 0);
+        BAIL_IF_ERRPASS(!io, NULL);
         created_io = 1;
     } /* if */