- if (!lte)
- goto out_close;
-
- /* Hack alert: WriteEncryptedFileRaw() requires the callback function
- * to work with a buffer whose size we cannot control. This doesn't
- * play well with our read_resource_prefix() function, which itself uses
- * a callback function to extract WIM_CHUNK_SIZE chunks of data. We
- * work around this problem by calling WriteEncryptedFileRaw() in a
- * different thread and feeding it the data as needed. */
- ctx.file_ctx = file_ctx;
- ctx.buf_filled = 0;
- ctx.done = false;
- ctx.wimlib_err_code = 0;
- if (pthread_mutex_init(&ctx.mutex, NULL)) {
- ERROR_WITH_ERRNO("Can't create mutex");
- ret = WIMLIB_ERR_NOMEM;
- goto out_close;
- }
- if (pthread_cond_init(&ctx.cond, NULL)) {
- ERROR_WITH_ERRNO("Can't create condition variable");
- ret = WIMLIB_ERR_NOMEM;
- goto out_pthread_mutex_destroy;
- }
- ret = pthread_create(&import_thread, NULL,
- win32_encrypted_import_proc, &ctx);
- if (ret) {
- errno = ret;
- ERROR_WITH_ERRNO("Failed to create thread");
- ret = WIMLIB_ERR_FORK;
- goto out_pthread_cond_destroy;
- }
-
- ret = extract_wim_resource(lte, wim_resource_size(lte),
- win32_extract_raw_encrypted_chunk, &ctx);
- pthread_mutex_lock(&ctx.mutex);
- ctx.done = true;
- pthread_cond_signal(&ctx.cond);
- pthread_mutex_unlock(&ctx.mutex);
- ret2 = pthread_join(import_thread, NULL);
- if (ret2) {
- errno = ret2;
- ERROR_WITH_ERRNO("Failed to join encrypted import thread");
- if (ret == 0)