]> wimlib.net Git - wimlib/blobdiff - src/lookup_table.c
wimfs_write(), dentry_to_stbuf()
[wimlib] / src / lookup_table.c
index 2177cb1bca25075945257373dcdcf3c516f2940a..6ad8872f37c579bdebb1782c04066d448939f53a 100644 (file)
@@ -118,7 +118,8 @@ void lookup_table_unlink(struct lookup_table *table,
 /* Decrement the reference count for the dentry having hash value @hash in the
  * lookup table.  The lookup table entry is unlinked and freed if there are no
  * references to in remaining.  */
-bool lookup_table_decrement_refcnt(struct lookup_table* table, const u8 hash[])
+struct lookup_table_entry *
+lookup_table_decrement_refcnt(struct lookup_table* table, const u8 hash[])
 {
        size_t pos = *(size_t*)hash % table->capacity;
        struct lookup_table_entry *prev = NULL;
@@ -129,19 +130,21 @@ bool lookup_table_decrement_refcnt(struct lookup_table* table, const u8 hash[])
                if (memcmp(hash, entry->hash, WIM_HASH_SIZE) == 0) {
                        wimlib_assert(entry->refcnt != 0);
                        if (--entry->refcnt == 0) {
-                               if (entry->num_opened_fds == 0)
+                               if (entry->num_opened_fds == 0) {
                                        free_lookup_table_entry(entry);
+                                       entry = NULL;
+                               }
                                if (prev)
                                        prev->next = next;
                                else
                                        table->array[pos] = next;
-                               return true;
+                               break;
                        }
                }
                prev = entry;
                entry = next;
        }
-       return false;
+       return entry;
 }
 
 
@@ -258,7 +261,8 @@ int write_lookup_table_entry(struct lookup_table_entry *lte, void *__out)
                return 0;
 
        if (lte->output_resource_entry.flags & WIM_RESHDR_FLAG_METADATA)
-               DEBUG("Writing metadata entry at %lu", ftello(out));
+               DEBUG("Writing metadata entry at %lu (orig size = %zu)",
+                     ftello(out), lte->output_resource_entry.original_size);
 
        p = put_resource_entry(buf, &lte->output_resource_entry);
        p = put_u16(p, lte->part_number);
@@ -370,8 +374,12 @@ int lookup_resource(WIMStruct *w, const char *path,
        if (lookup_flags & LOOKUP_FLAG_ADS_OK) {
                const char *stream_name = path_stream_name(path);
                if (stream_name) {
+                       size_t stream_name_len = strlen(stream_name);
                        for (u16 i = 0; i < dentry->num_ads; i++) {
-                               if (strcmp(stream_name, dentry->ads_entries[i].stream_name) == 0) {
+                               if (ads_entry_has_name(&dentry->ads_entries[i],
+                                                      stream_name,
+                                                      stream_name_len))
+                               {
                                        hash = dentry->ads_entries[i].hash;
                                        goto do_lookup;
                                }