Skip to content

Commit 491c063

Browse files
Only delete keywords, not entire item
This fixes a bug where removing all tags from a file would also remove it from any collections you'd added it to, and safeguards against similar bugs if Ableton add extra metadata later on. A slightly better approach would be to check if the item only contains 'filePath' before removing the item - I'll try to add that later on.
1 parent 6bb7ad4 commit 491c063

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/Xmp.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ public void AddTags(string file, List<string> tags)
104104
if (existingItem != null)
105105
{
106106
// Add keyword to existing items
107-
var keywordBag = existingItem.Element(Ableton.Keywords).Element(Rdf.Bag);
107+
var keywords = existingItem.Element(Ableton.Keywords);
108+
var keywordBag = keywords.Element(Rdf.Bag);
108109

109110
foreach (string tag in tags)
110111
{
@@ -164,7 +165,8 @@ public void RemoveTags(string file, List<string> tags)
164165

165166
if (item != null)
166167
{
167-
var keywordBag = item.Element(Ableton.Keywords).Element(Rdf.Bag);
168+
var keywords = item.Element(Ableton.Keywords);
169+
var keywordBag = keywords.Element(Rdf.Bag);
168170

169171
var tagsRemoved = new List<string>();
170172
var elementsToRemove = new List<XElement>();
@@ -182,7 +184,7 @@ public void RemoveTags(string file, List<string> tags)
182184
{
183185
if (elementsToRemove.Count == keywordBag.Elements(Rdf.Li).Count())
184186
{
185-
item.Remove();
187+
keywords.Remove();
186188
}
187189
else
188190
{
@@ -218,7 +220,9 @@ public void RemoveTags(string file)
218220

219221
if (item != null)
220222
{
221-
item.Remove();
223+
var keywords = item.Element(Ableton.Keywords);
224+
225+
keywords.Remove();
222226
IsDirty = true;
223227
Console.WriteLine($"Removed all tags from {file}");
224228
}

0 commit comments

Comments
 (0)