ERROR("Failed to commit changes\n");
return ret;
}
- ret = delete_staging_dir();
- if (ret != 0) {
- ERROR("Failed to delete the staging directory: %m\n");
- }
return ret;
}
DEBUG("Received message: [%d %d]\n", msg[0], msg[1]);
}
- if (commit && (mount_flags & WIMLIB_MOUNT_FLAG_READWRITE)) {
- status = chdir(working_directory);
- if (status != 0) {
- ERROR("chdir(): %m\n");
- status = WIMLIB_ERR_NOTDIR;
- goto done;
+ status = 0;
+ if (mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) {
+ if (commit) {
+ status = chdir(working_directory);
+ if (status != 0) {
+ ERROR("chdir(): %m\n");
+ status = WIMLIB_ERR_NOTDIR;
+ goto done;
+ }
+ status = rebuild_wim(w, (check_integrity != 0));
+ }
+ ret = delete_staging_dir();
+ if (ret != 0) {
+ ERROR("Failed to delete the staging directory: %m\n");
+ if (status == 0)
+ status = ret;
}
- status = rebuild_wim(w, (check_integrity != 0));
- } else {
- status = 0;
}
done:
ret = mq_send(daemon_to_unmount_mq, &status, 1, 1);
- if (ret == -1) {
+ if (ret == -1)
ERROR("Failed to send status to unmount process: %m\n");
- }
close_message_queues();
}
/* doesn't exist--- ok */
}
+ DEBUG("Creating staging file '%s'\n", name);
+
fd = creat(name, 0600);
if (fd == -1) {
errno_save = errno;
if (dentry_is_directory(dentry))
return -EISDIR;
lte = wim_lookup_resource(w, dentry);
- if (!lte)
- return 0;
-
- if (lte->staging_file_name) {
+ if (lte) {
/* If this file is in the staging directory and the file is not
* currently open, open it. */
- if (lte->staging_num_times_opened == 0) {
+ if (lte->staging_file_name && lte->staging_num_times_opened == 0) {
lte->staging_fd = open(lte->staging_file_name, O_RDWR);
if (lte->staging_fd == -1)
return -errno;
lte->staging_offset = 0;
- }
+ }
+ } else {
+ /* no lookup table entry, so the file must be empty. Create a
+ * lookup table entry for the file. */
+ char *tmpfile_name;
+ int err;
+ int fd;
+
+ lte = new_lookup_table_entry();
+ if (!lte)
+ return -ENOMEM;
+
+ fd = create_staging_file(&tmpfile_name);
+
+ if (fd == -1) {
+ err = errno;
+ free(lte);
+ return -errno;
+ }
+ lte->resource_entry.original_size = 0;
+ randomize_byte_array(lte->hash, WIM_HASH_SIZE);
+ memcpy(dentry->hash, lte->hash, WIM_HASH_SIZE);
+ lte->staging_file_name = tmpfile_name;
+ lte->staging_fd = fd;
+ lte->staging_offset = 0;
+ lookup_table_insert(w->lookup_table, lte);
}
lte->staging_num_times_opened++;
return 0;
if (!dentry)
return -EEXIST;
lte = wim_lookup_resource(w, dentry);
- if (!lte)
- return -EEXIST;
+
+ if (!lte) /* Already a zero-length file */
+ return 0;
if (lte->staging_file_name) {
/* File on disk. Call POSIX API */
if (lte->staging_num_times_opened != 0)
if (!dentry)
return -EEXIST;
lte = wim_lookup_resource(w, dentry);
- if (!lte)
+
+ if (!lte) /* this should not happen */
return -EEXIST;
+
if (lte->staging_num_times_opened == 0)
return -EBADF;
if (lte->staging_file_name) {