]> wimlib.net Git - wimlib/blobdiff - src/mount.c
Various fixes
[wimlib] / src / mount.c
index adfb7d6649eced85c7c267732c8381be7134b0d7..19e8d5d700a573b39063a8f69b89ae44daecece2 100644 (file)
@@ -220,9 +220,9 @@ int dentry_to_stbuf(const struct dentry *dentry, struct stat *stbuf)
                stbuf->st_size = 0;
        }
 
-       stbuf->st_atime   = ms_timestamp_to_unix(dentry->last_access_time);
-       stbuf->st_mtime   = ms_timestamp_to_unix(dentry->last_write_time);
-       stbuf->st_ctime   = ms_timestamp_to_unix(dentry->creation_time);
+       stbuf->st_atime   = wim_timestamp_to_unix(dentry->last_access_time);
+       stbuf->st_mtime   = wim_timestamp_to_unix(dentry->last_write_time);
+       stbuf->st_ctime   = wim_timestamp_to_unix(dentry->creation_time);
        stbuf->st_blocks  = (stbuf->st_size + 511) / 512;
        return 0;
 }
@@ -772,19 +772,22 @@ static void lte_list_change_lte_ptr(struct lookup_table_entry *lte,
 }
 
 
-static int calculate_sha1sum_of_staging_file(struct lookup_table_entry *lte,
-                                            struct lookup_table *table)
+static int update_lte_of_staging_file(struct lookup_table_entry *lte,
+                                     struct lookup_table *table)
 {
        struct lookup_table_entry *duplicate_lte;
        int ret;
        u8 hash[SHA1_HASH_SIZE];
+       struct stat stbuf;
+
+       wimlib_assert(lte->staging_file_name);
 
        ret = sha1sum(lte->staging_file_name, hash);
        if (ret != 0)
                return ret;
 
+
        lookup_table_unlink(table, lte);
-       copy_hash(lte->hash, hash);
 
        duplicate_lte = __lookup_resource(table, hash);
 
@@ -793,11 +796,17 @@ static int calculate_sha1sum_of_staging_file(struct lookup_table_entry *lte,
 
                lte_list_change_lte_ptr(lte, duplicate_lte);
                duplicate_lte->refcnt += lte->refcnt;
-               list_splice(&duplicate_lte->lte_group_list,
-                           &lte->lte_group_list);
+               list_splice(&lte->lte_group_list,
+                           &duplicate_lte->lte_group_list);
 
                free_lookup_table_entry(lte);
        } else {
+               if (stat(lte->staging_file_name, &stbuf) != 0) {
+                       ERROR_WITH_ERRNO("Failed to stat `%s'", lte->staging_file_name);
+                       return WIMLIB_ERR_STAT;
+               }
+               copy_hash(lte->hash, hash);
+               lte->resource_entry.original_size = stbuf.st_size;
                lookup_table_insert(table, lte);
        }
 
@@ -822,7 +831,7 @@ static int rebuild_wim(WIMStruct *w, bool check_integrity)
         * lookup table entries. */
        DEBUG("Calculating SHA1 checksums for all new staging files.");
        list_for_each_entry_safe(lte, tmp, &staging_list, staging_list) {
-               ret = calculate_sha1sum_of_staging_file(lte, w->lookup_table);
+               ret = update_lte_of_staging_file(lte, w->lookup_table);
                if (ret != 0)
                        return ret;
        }
@@ -1286,7 +1295,7 @@ static int wimfs_release(const char *path, struct fuse_file_info *fi)
        }
 
        if (flags_writable(fi->flags) && fd->dentry) {
-               u64 now = get_timestamp();
+               u64 now = get_wim_timestamp();
                fd->dentry->last_access_time = now;
                fd->dentry->last_write_time = now;
        }
@@ -1513,20 +1522,28 @@ static int wimfs_unlink(const char *path)
        return 0;
 }
 
-/* Change the timestamp on a file dentry. 
+/* 
+ * Change the timestamp on a file dentry. 
  *
- * There is no distinction between a file and its alternate data streams here.  */
+ * Note that alternate data streams do not have their own timestamps.
+ */
 static int wimfs_utimens(const char *path, const struct timespec tv[2])
 {
        struct dentry *dentry = get_dentry(w, path);
        if (!dentry)
                return -ENOENT;
-       time_t last_access_t = (tv[0].tv_nsec == UTIME_NOW) ? 
-                               time(NULL) : tv[0].tv_sec;
-       dentry->last_access_time = unix_timestamp_to_ms(last_access_t);
-       time_t last_mod_t = (tv[1].tv_nsec == UTIME_NOW) ?  
-                               time(NULL) : tv[1].tv_sec;
-       dentry->last_write_time = unix_timestamp_to_ms(last_mod_t);
+       if (tv[0].tv_nsec != UTIME_OMIT) {
+               if (tv[0].tv_nsec == UTIME_NOW)
+                       dentry->last_access_time = get_wim_timestamp();
+               else
+                       dentry->last_access_time = timespec_to_wim_timestamp(&tv[0]);
+       }
+       if (tv[1].tv_nsec != UTIME_OMIT) {
+               if (tv[1].tv_nsec == UTIME_NOW)
+                       dentry->last_write_time = get_wim_timestamp();
+               else
+                       dentry->last_write_time = timespec_to_wim_timestamp(&tv[1]);
+       }
        return 0;
 }