*/
/*
- *
- * Copyright (C) 2010 Carl Thijssen
* Copyright (C) 2012 Eric Biggers
*
* This file is part of wimlib, a library for working with WIM files.
*
* wimlib is free software; you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free
- * Software Foundation; either version 2.1 of the License, or (at your option)
- * any later version.
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 3 of the License, or (at your option) any later
+ * version.
*
* wimlib is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
- * details.
+ * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
- * You should have received a copy of the GNU Lesser General Public License
- * along with wimlib; if not, see http://www.gnu.org/licenses/.
+ * You should have received a copy of the GNU General Public License along with
+ * wimlib; if not, see http://www.gnu.org/licenses/.
*/
#include <errno.h>
DEBUG("Add alternate data stream %s:%s",
dentry->file_name_utf8, stream_name);
- if (dentry->num_ads == 0xffff)
+ if (dentry->num_ads == 0xffff) {
+ ERROR("Too many alternate data streams in one dentry!");
return NULL;
+ }
num_ads = dentry->num_ads + 1;
ads_entries = REALLOC(dentry->ads_entries,
num_ads * sizeof(struct ads_entry));
- if (!ads_entries)
+ if (!ads_entries) {
+ ERROR("Failed to allocate memory for new alternate data stream");
return NULL;
+ }
if (ads_entries != dentry->ads_entries) {
/* We moved the ADS entries. Adjust the stream lists. */
for (u16 i = 0; i < dentry->num_ads; i++) {
FREE(dentry->file_name_utf8);
FREE(dentry->short_name);
FREE(dentry->full_path_utf8);
- FREE(dentry->extracted_file);
+ if (dentry->extracted_file != dentry->full_path_utf8)
+ FREE(dentry->extracted_file);
}
/* Frees a WIM dentry. */
p = put_u64(p, dentry->creation_time);
p = put_u64(p, dentry->last_access_time);
p = put_u64(p, dentry->last_write_time);
- if (dentry->resolved && dentry->lte)
- hash = dentry->lte->hash;
- else
- hash = dentry->hash;
+ hash = dentry_stream_hash(dentry, 0);
p = put_bytes(p, SHA1_HASH_SIZE, hash);
if (dentry->attributes & FILE_ATTRIBUTE_REPARSE_POINT) {
p = put_zeroes(p, 4);
for (u16 i = 0; i < dentry->num_ads; i++) {
p = put_u64(p, ads_entry_total_length(&dentry->ads_entries[i]));
p = put_u64(p, 0); /* Unused */
- if (dentry->resolved && dentry->ads_entries[i].lte)
- hash = dentry->ads_entries[i].lte->hash;
- else
- hash = dentry->ads_entries[i].hash;
+ hash = dentry_stream_hash(dentry, i + 1);
p = put_bytes(p, SHA1_HASH_SIZE, hash);
p = put_u16(p, dentry->ads_entries[i].stream_name_len);
if (dentry->ads_entries[i].stream_name_len) {