]> wimlib.net Git - wimlib/commitdiff
extract.c: Simplify mkdir_if_needed()
authorEric Biggers <ebiggers3@gmail.com>
Sat, 16 Aug 2014 01:01:32 +0000 (20:01 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Sat, 16 Aug 2014 01:08:32 +0000 (20:08 -0500)
Just go ahead and try mkdir().  If it works or it fails with EEXIST,
we're done.  (On Windows, a quirk also requires a check for EACCES.)

This aoids the need to call tstat(), which on Windows was really
_wstat(), which is horribly broken: it will fail on paths ending in a
slash.

NEWS
src/extract.c

diff --git a/NEWS b/NEWS
index 19e4b25cbbdbd2ed9122de4c07b00839776bec96..cd5bc4a80592c5d75c622d05b761354036a30a32 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,11 @@
+Version 1.7.2-BETA:
+       Made yet another round of performance improvements to the XPRESS, LZX,
+       and LZMS compressors.
+
+       On Windows, wimextract and its underlying library function
+       wimlib_extract_paths() will no longer fail if given a target directory
+       path ending in a slash.
+
 Version 1.7.1:
        Made more improvements to the XPRESS, LZX, and LZMS compressors.
 
index fb96f13f8723bf26d0e24f9acfd4e9d051bb22c6..3b0470419ba248dbeba85439e1e2022fac37569c 100644 (file)
@@ -1481,23 +1481,20 @@ out:
 static int
 mkdir_if_needed(const tchar *target)
 {
-       struct stat stbuf;
-       if (tstat(target, &stbuf)) {
-               if (errno == ENOENT) {
-                       if (tmkdir(target, 0755)) {
-                               ERROR_WITH_ERRNO("Failed to create directory "
-                                                "\"%"TS"\"", target);
-                               return WIMLIB_ERR_MKDIR;
-                       }
-               } else {
-                       ERROR_WITH_ERRNO("Failed to stat \"%"TS"\"", target);
-                       return WIMLIB_ERR_STAT;
-               }
-       } else if (!S_ISDIR(stbuf.st_mode)) {
-               ERROR("\"%"TS"\" is not a directory", target);
-               return WIMLIB_ERR_NOTDIR;
-       }
-       return 0;
+       if (!tmkdir(target, 0755))
+               return 0;
+
+       if (errno == EEXIST)
+               return 0;
+
+#ifdef __WIN32__
+       /* _wmkdir() fails with EACCES if called on a drive root directory.  */
+       if (errno == EACCES)
+               return 0;
+#endif
+
+       ERROR_WITH_ERRNO("Failed to create directory \"%"TS"\"", target);
+       return WIMLIB_ERR_MKDIR;
 }
 
 /* Make sure the extraction flags make sense, and update them if needed.  */