return 0;
}
+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;
+}
+
+
static int
do_wimlib_extract_paths(WIMStruct *wim,
int image,
if (ret)
return ret;
+ if ((extract_flags & (WIMLIB_EXTRACT_FLAG_NTFS |
+ WIMLIB_EXTRACT_FLAG_NO_PRESERVE_DIR_STRUCTURE)) ==
+ (WIMLIB_EXTRACT_FLAG_NO_PRESERVE_DIR_STRUCTURE))
+ {
+ ret = mkdir_if_needed(target);
+ if (ret)
+ return ret;
+ }
+
if (extract_flags & WIMLIB_EXTRACT_FLAG_GLOB_PATHS) {
struct append_dentry_ctx append_dentry_ctx = {
int ret;
int image;
const tchar *image_name;
- struct stat stbuf;
extract_flags |= WIMLIB_EXTRACT_FLAG_MULTI_IMAGE;
return WIMLIB_ERR_INVALID_PARAM;
}
- 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;
- }
-
+ ret = mkdir_if_needed(target);
+ if (ret)
+ return ret;
tmemcpy(buf, target, output_path_len);
buf[output_path_len] = OS_PREFERRED_PATH_SEPARATOR;
for (image = 1; image <= wim->hdr.image_count; image++) {