Skip to content

Fix: Fixed issue where some file operations would fail #15139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Files.App/Data/Items/ListedItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public string[] FileTags
{
Debug.Assert(value != null);
var dbInstance = FileTagsHelper.GetDbInstance();
dbInstance.SetTags(ItemPath, FileFRN, value);
dbInstance.SetTags(ItemPath, FileFRN, value ?? []);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already asserted value is not null. I think we can keep here as it was.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that for Debug condition?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug.Assert is ignored in the release build, so I'm not sure if value is not null here.

HasTags = !FileTags.IsEmpty();
FileTagsHelper.WriteFileTag(ItemPath, value);
OnPropertyChanged(nameof(FileTagsUI));
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Data/Models/ItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ await dispatcherQueue.EnqueueOrInvokeAsync(async () =>
private static void SetFileTag(ListedItem item)
{
var dbInstance = FileTagsHelper.GetDbInstance();
dbInstance.SetTags(item.ItemPath, item.FileFRN, item.FileTags);
dbInstance.SetTags(item.ItemPath, item.FileFRN, item.FileTags ?? []);
}

// This works for recycle bin as well as GetFileFromPathAsync/GetFolderFromPathAsync work
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ async Task PerformNavigationAsync(string payload, string selectItem = null)
.OnSuccess(item => FileTagsHelper.GetFileFRN(item));
if (fileFRN is not null)
{
var tagUid = tag is not null ? new[] { tag.Uid } : null;
var tagUid = tag is not null ? new[] { tag.Uid } : [];
var dbInstance = FileTagsHelper.GetDbInstance();
dbInstance.SetTags(file, fileFRN, tagUid);
FileTagsHelper.WriteFileTag(file, tagUid);
Expand Down
6 changes: 3 additions & 3 deletions src/Files.App/Utils/FileTags/FileTagsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static void UpdateTagsDb()
}
else
{
dbInstance.SetTags(null, file.Frn, null);
dbInstance.SetTags(null, file.Frn, []);
}
}
else
Expand All @@ -94,12 +94,12 @@ public static void UpdateTagsDb()
dbInstance.SetTags(file.FilePath, frn, tag);
}, App.Logger))
{
dbInstance.SetTags(file.FilePath, null, null);
dbInstance.SetTags(file.FilePath, null, []);
}
}
else
{
dbInstance.SetTags(file.FilePath, null, null);
dbInstance.SetTags(file.FilePath, null, []);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ private static void UpdateFileTagsDb(ShellFileOperations2.ShellFileOpEventArgs e
};
if (destination is null)
{
dbInstance.SetTags(sourcePath, null, null); // remove tag from deleted files
dbInstance.SetTags(sourcePath, null, []); // remove tag from deleted files
}
else
{
Expand All @@ -864,7 +864,7 @@ private static void UpdateFileTagsDb(ShellFileOperations2.ShellFileOpEventArgs e
{
var tag = dbInstance.GetTags(sourcePath, null);

dbInstance.SetTags(destination, FileTagsHelper.GetFileFRN(destination), tag); // copy tag to new files
dbInstance.SetTags(destination, FileTagsHelper.GetFileFRN(destination), tag ?? []); // copy tag to new files
using var si = new ShellItem(destination);
if (si.IsFolder) // File tag is not copied automatically for folders
{
Expand All @@ -882,7 +882,7 @@ private static void UpdateFileTagsDb(ShellFileOperations2.ShellFileOpEventArgs e
var tags = dbInstance.GetAllUnderPath(sourcePath).ToList();
if (destination is null) // remove tag for items contained in the folder
{
tags.ForEach(t => dbInstance.SetTags(t.FilePath, null, null));
tags.ForEach(t => dbInstance.SetTags(t.FilePath, null, []));
}
else
{
Expand All @@ -893,7 +893,7 @@ private static void UpdateFileTagsDb(ShellFileOperations2.ShellFileOpEventArgs e
SafetyExtensions.IgnoreExceptions(() =>
{
var subPath = t.FilePath.Replace(sourcePath, destination, StringComparison.Ordinal);
dbInstance.SetTags(subPath, FileTagsHelper.GetFileFRN(subPath), t.Tags);
dbInstance.SetTags(subPath, FileTagsHelper.GetFileFRN(subPath), t.Tags ?? []);
}, App.Logger);
});
}
Expand Down