]> wimlib.net Git - wimlib/blobdiff - programs/imagex.c
Fix glob()
[wimlib] / programs / imagex.c
index 1972505824766aaad8be23eb9b91d5175ff0dcbf..0f65ae51cbdd1a18ef988fae3ef4f529f5a92717 100644 (file)
@@ -38,6 +38,7 @@
 #include <string.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include <locale.h>
 
 #ifdef HAVE_ALLOCA_H
 #include <alloca.h>
@@ -900,11 +901,17 @@ static int imagex_apply(int argc, char **argv)
                }
        }
 
+#ifdef __WIN32__
+       win32_acquire_restore_privileges();
+#endif
        ret = wimlib_extract_image(w, image, target, extract_flags,
                                   additional_swms, num_additional_swms,
                                   imagex_progress_func);
        if (ret == 0)
                printf("Done applying WIM image.\n");
+#ifdef __WIN32__
+       win32_release_restore_privileges();
+#endif
 out:
        wimlib_free(w);
        if (additional_swms) {
@@ -1081,6 +1088,9 @@ static int imagex_capture_or_append(int argc, char **argv)
                        }
                }
        }
+#ifdef __WIN32__
+       win32_acquire_capture_privileges();
+#endif
 
        ret = wimlib_add_image_multisource(w, capture_sources,
                                           num_sources, name,
@@ -1091,17 +1101,17 @@ static int imagex_capture_or_append(int argc, char **argv)
                                           add_image_flags,
                                           imagex_progress_func);
        if (ret != 0)
-               goto out;
+               goto out_release_privs;
        cur_image = wimlib_get_num_images(w);
        if (desc) {
                ret = wimlib_set_image_descripton(w, cur_image, desc);
                if (ret != 0)
-                       goto out;
+                       goto out_release_privs;
        }
        if (flags_element) {
                ret = wimlib_set_image_flags(w, cur_image, flags_element);
                if (ret != 0)
-                       goto out;
+                       goto out_release_privs;
        }
        if (cmd == APPEND) {
                ret = wimlib_overwrite(w, write_flags, num_threads,
@@ -1114,6 +1124,10 @@ static int imagex_capture_or_append(int argc, char **argv)
                ret = 0;
        if (ret != 0)
                imagex_error("Failed to write the WIM file `%s'", wimfile);
+out_release_privs:
+#ifdef __WIN32__
+       win32_release_capture_privileges();
+#endif
 out:
        wimlib_free(w);
        free(config_str);
@@ -2107,6 +2121,8 @@ int main(int argc, char **argv)
        const struct imagex_command *cmd;
        int ret;
 
+       setlocale(LC_ALL, "");
+
        if (argc < 2) {
                imagex_error("No command specified");
                usage_all();
@@ -2122,8 +2138,7 @@ int main(int argc, char **argv)
        /* The user may like to see more informative error messages. */
        wimlib_set_print_errors(true);
 
-       /* Calling wimlib_global_init() is not strictly necessary because
-        * 'imagex' is single-threaded. */
+       /* Do any initializations that the library needs */
        ret = wimlib_global_init();
        if (ret)
                goto out;
@@ -2162,8 +2177,9 @@ out:
                if (ret == WIMLIB_ERR_NTFS_3G && errno != 0)
                        imagex_error_with_errno("errno");
        }
-       /* Calling wimlib_global_cleanup() is not strictly necessary because the
-        * process is exiting anyway. */
+
+       /* Make the library free any resources it's holding (not strictly
+        * necessary because the process is ending anyway). */
        wimlib_global_cleanup();
        return ret;
 }