From b3fe3e8b3de5794762f21000d5771b0491e8a041 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 6 Feb 2015 12:25:34 +0100 Subject: TagBuilder: allow adding duplicate tag types in Complement() Build a table of pre-existing tag types before adding new items. The old way would check HasType() each time, which would return true after the first instance of that tag type had been added, preventing duplicate tag types to be merged. This broke duplicate tag types loaded from the state file, because this code path uses TagBuilder::Complement(). --- src/tag/TagBuilder.cxx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/tag/TagBuilder.cxx b/src/tag/TagBuilder.cxx index 93518f6e9..0882f9561 100644 --- a/src/tag/TagBuilder.cxx +++ b/src/tag/TagBuilder.cxx @@ -25,6 +25,8 @@ #include "Tag.hxx" #include "util/WritableBuffer.hxx" +#include + #include #include #include @@ -168,12 +170,19 @@ TagBuilder::Complement(const Tag &other) has_playlist |= other.has_playlist; + /* build a table of tag types that were already present in + this object, which will not be copied from #other */ + std::array present; + present.fill(false); + for (const TagItem *i : items) + present[i->type] = true; + items.reserve(items.size() + other.num_items); tag_pool_lock.lock(); for (unsigned i = 0, n = other.num_items; i != n; ++i) { TagItem *item = other.items[i]; - if (!HasType(item->type)) + if (!present[item->type]) items.push_back(tag_pool_dup_item(item)); } tag_pool_lock.unlock(); -- cgit v1.2.3 From d38034bb5c7bb58c01ce817fbeb394b178961a13 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 6 Feb 2015 14:36:55 +0100 Subject: fs/io/FileOutputStream: don't auto-delete file on WIN32 The file handle is never reset to INVALID_HANDLE_VALUE, and thus the destructor will assume the operation shall be cancelled and will delete the temporary file. This was a major breakage for saving the database file and the state file. --- src/fs/io/FileOutputStream.cxx | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/fs/io/FileOutputStream.cxx b/src/fs/io/FileOutputStream.cxx index dc4456d1f..0eff8b5f0 100644 --- a/src/fs/io/FileOutputStream.cxx +++ b/src/fs/io/FileOutputStream.cxx @@ -62,6 +62,7 @@ FileOutputStream::Commit(gcc_unused Error &error) assert(IsDefined()); CloseHandle(handle); + handle = INVALID_HANDLE_VALUE; return true; } @@ -71,6 +72,7 @@ FileOutputStream::Cancel() assert(IsDefined()); CloseHandle(handle); + handle = INVALID_HANDLE_VALUE; RemoveFile(path); } -- cgit v1.2.3