From 0da20afab9ec25f7b5af83f7507002d467b28685 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Fri, 15 Aug 2014 20:01:32 -0500 Subject: [PATCH] extract.c: Simplify mkdir_if_needed() 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 | 8 ++++++++ src/extract.c | 31 ++++++++++++++----------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/NEWS b/NEWS index 19e4b25c..cd5bc4a8 100644 --- 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. diff --git a/src/extract.c b/src/extract.c index fb96f13f..3b047041 100644 --- a/src/extract.c +++ b/src/extract.c @@ -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. */ -- 2.43.0