]> wimlib.net Git - wimlib/blobdiff - src/ntfs-apply.c
write_ntfs_data_streams(): Reserve space for streams
[wimlib] / src / ntfs-apply.c
index 0bfc060e9a55d0430e2dadbf67e786c96399f34c..090d5a1aab717b5ace815671b0d49e8222e14c81 100644 (file)
@@ -90,7 +90,6 @@ static int write_ntfs_data_streams(ntfs_inode *ni, const struct dentry *dentry,
 
        while (1) {
                struct lookup_table_entry *lte;
-               ntfs_attr *na;
 
                lte = inode_stream_lte_resolved(inode, stream_idx);
 
@@ -112,6 +111,8 @@ static int write_ntfs_data_streams(ntfs_inode *ni, const struct dentry *dentry,
                 * Otherwise, we must open the attribute and extract the data.
                 * */
                if (lte) {
+                       ntfs_attr *na;
+
                        na = ntfs_attr_open(ni, AT_DATA, stream_name, stream_name_len);
                        if (!na) {
                                ERROR_WITH_ERRNO("Failed to open a data stream of "
@@ -120,11 +121,17 @@ static int write_ntfs_data_streams(ntfs_inode *ni, const struct dentry *dentry,
                                ret = WIMLIB_ERR_NTFS_3G;
                                break;
                        }
+                       ret = ntfs_attr_truncate_solid(na, wim_resource_size(lte));
+                       if (ret != 0) {
+                               ntfs_attr_close(na);
+                               break;
+                       }
+
                        ret = extract_wim_resource_to_ntfs_attr(lte, na);
+                       ntfs_attr_close(na);
                        if (ret != 0)
                                break;
                        args->progress.extract.completed_bytes += wim_resource_size(lte);
-                       ntfs_attr_close(na);
                }
                if (stream_idx == inode->num_ads)
                        break;
@@ -506,7 +513,8 @@ out_set_dos_name:
                                                    dentry->file_name_utf8);
                        if (!ni) {
                                ERROR_WITH_ERRNO("Could not find NTFS inode for `%s'",
-                                                dir_name);
+                                                dentry->full_path_utf8);
+                               ntfs_inode_close(dir_ni);
                                return WIMLIB_ERR_NTFS_3G;
                        }
                }
@@ -527,6 +535,15 @@ out_set_dos_name:
        }
 
 out_close_dir_ni:
+       if (ni && dir_ni) {
+               if (ntfs_inode_close_in_dir(ni, dir_ni) != 0) {
+                       ni = NULL;
+                       if (ret == 0)
+                               ret = WIMLIB_ERR_NTFS_3G;
+                       ERROR_WITH_ERRNO("Failed to close inode for `%s'",
+                                        dentry->full_path_utf8);
+               }
+       }
        if (ntfs_inode_close(dir_ni) != 0) {
                if (ret == 0)
                        ret = WIMLIB_ERR_NTFS_3G;
@@ -535,7 +552,8 @@ out_close_dir_ni:
        if (ni && ntfs_inode_close(ni) != 0) {
                if (ret == 0)
                        ret = WIMLIB_ERR_NTFS_3G;
-               ERROR_WITH_ERRNO("Failed to close inode");
+               ERROR_WITH_ERRNO("Failed to close inode for `%s'",
+                                dentry->full_path_utf8);
        }
        return ret;
 }