- if (!staging_dir_name) {
- ret = WIMLIB_ERR_NOMEM;
- goto out;
- }
-
- if (real_user_prefix)
- sprintf(staging_dir_name, "%s/%s", real_user_prefix, wim_basename);
- else
- strcpy(staging_dir_name, ctx->wim->filename);
-
- strcat(staging_dir_name, common_suffix);
-
- randomize_char_array_with_alnum(staging_dir_name + prefix_len + common_suffix_len,
- random_suffix_len);
-
- staging_dir_name[staging_dir_name_len] = '\0';
-
- if (mkdir(staging_dir_name, 0700) != 0) {
- ERROR_WITH_ERRNO("Failed to create temporary directory `%s'",
- staging_dir_name);
- ret = WIMLIB_ERR_MKDIR;
- } else {
- ret = 0;
- }
-out:
- FREE(real_user_prefix);
- if (ret == 0) {
- ctx->staging_dir_name = staging_dir_name;
- ctx->staging_dir_name_len = staging_dir_name_len;
- } else {
- FREE(staging_dir_name);
- }
- return ret;
-}
-
-static int remove_file_or_directory(const char *fpath, const struct stat *sb,
- int typeflag, struct FTW *ftwbuf)
-{
- if (remove(fpath) == 0)
- return 0;
- else {
- ERROR_WITH_ERRNO("Cannot remove `%s'", fpath);
- return WIMLIB_ERR_DELETE_STAGING_DIR;
- }
-}
-
-
-/*
- * Deletes the staging directory and all the files contained in it.
- */
-static int delete_staging_dir(struct wimfs_context *ctx)
-{
- int ret;
- ret = nftw(ctx->staging_dir_name, remove_file_or_directory,
- 10, FTW_DEPTH);
- FREE(ctx->staging_dir_name);
- ctx->staging_dir_name = NULL;
- 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;