- DEBUG("Freeing entries for zero-length streams");
- image_for_each_unhashed_stream_safe(lte, tmp, imd) {
- wimlib_assert(lte->unhashed);
- if (lte->size == 0) {
- struct wim_lookup_table_entry **back_ptr;
- back_ptr = retrieve_lte_pointer(lte);
- *back_ptr = NULL;
- list_del(<e->unhashed_list);
- free_lookup_table_entry(lte);
- }
- }
-
- xml_update_image_info(wim, wim->current_image);
- ret = wimlib_overwrite(wim, write_flags, 0, progress_func);
- if (ret)
- ERROR("Failed to commit changes to mounted WIM image");
- return ret;
-}
-
-/* Simple function that returns the concatenation of 2 strings. */
-static char *
-strcat_dup(const char *s1, const char *s2, size_t max_len)
-{
- size_t len = strlen(s1) + strlen(s2);
- if (len > max_len)
- len = max_len;
- char *p = MALLOC(len + 1);
- if (!p)
- return NULL;
- snprintf(p, len + 1, "%s%s", s1, s2);
- return p;
-}
-
-static int
-set_message_queue_names(struct wimfs_context *ctx, const char *mount_dir)
-{
- static const char *u2d_prefix = "/wimlib-unmount-to-daemon-mq";
- static const char *d2u_prefix = "/wimlib-daemon-to-unmount-mq";
- char *dir_path;
- char *p;
- int ret;
-
- dir_path = realpath(mount_dir, NULL);
- if (!dir_path) {
- ERROR_WITH_ERRNO("Failed to resolve path \"%s\"", mount_dir);
- if (errno == ENOMEM)
- return WIMLIB_ERR_NOMEM;
- else
- return WIMLIB_ERR_NOTDIR;
- }
-
- for (p = dir_path; *p; p++)
- if (*p == '/')
- *p = 0xff;
-
- ctx->unmount_to_daemon_mq_name = strcat_dup(u2d_prefix, dir_path,
- NAME_MAX);
- if (!ctx->unmount_to_daemon_mq_name) {
- ret = WIMLIB_ERR_NOMEM;
- goto out_free_dir_path;
- }
- ctx->daemon_to_unmount_mq_name = strcat_dup(d2u_prefix, dir_path,
- NAME_MAX);
- if (!ctx->daemon_to_unmount_mq_name) {
- ret = WIMLIB_ERR_NOMEM;
- goto out_free_unmount_to_daemon_mq_name;
+ ctx->staging_dir_fd = make_staging_dir_at(ctx->parent_dir_fd,
+ wim_basename,
+ &ctx->staging_dir_name);
+ if (ctx->staging_dir_fd < 0) {
+ ERROR_WITH_ERRNO("Can't create staging directory in \"%s\"",
+ parent_dir_path);
+ close(ctx->parent_dir_fd);
+ ret = WIMLIB_ERR_MKDIR;
+ goto out_restore_wim_filename;