Skip to content
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

Fix: Fixed issue where online-only files deleted before confirmation #11335

Merged
merged 2 commits into from
Feb 17, 2023
Merged
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
23 changes: 22 additions & 1 deletion src/Files.App/Helpers/FileOperationsHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ namespace Files.App.Helpers
{
public class FileOperationsHelpers
{
private static readonly Ole32.PROPERTYKEY PKEY_FilePlaceholderStatus = new Ole32.PROPERTYKEY(new Guid("B2F9B9D6-FEC4-4DD5-94D7-8957488C807B"), 2);
private const uint PS_CLOUDFILE_PLACEHOLDER = 8;

private static ProgressHandler? progressHandler; // Warning: must be initialized from a MTA thread

public static Task SetClipboard(string[] filesToCopy, DataPackageOperation operation)
Expand Down Expand Up @@ -119,14 +122,29 @@ public static Task SetClipboard(string[] filesToCopy, DataPackageOperation opera
op.Options |= ShellFileOperations.OperationFlags.RecycleOnDelete;

var shellOperationResult = new ShellOperationResult();
var tryDelete = false;

for (var i = 0; i < fileToDeletePath.Length; i++)
{
if (!SafetyExtensions.IgnoreExceptions(() =>
{
using var shi = new ShellItem(fileToDeletePath[i]);
var file = SafetyExtensions.IgnoreExceptions(() => GetFirstFile(shi)) ?? shi;
op.QueueDeleteOperation(file);
if (file.Properties.GetProperty<uint>(PKEY_FilePlaceholderStatus) == PS_CLOUDFILE_PLACEHOLDER)
{
// Online only files cannot be tried for deletion, so they are treated as to be permanently deleted.
shellOperationResult.Items.Add(new ShellOperationItemResult()
{
Succeeded = false,
Source = fileToDeletePath[i],
HResult = HRESULT.COPYENGINE_E_RECYCLE_BIN_NOT_FOUND
});
}
else
{
op.QueueDeleteOperation(file);
tryDelete = true;
}
}))
{
shellOperationResult.Items.Add(new ShellOperationItemResult()
Expand All @@ -138,6 +156,9 @@ public static Task SetClipboard(string[] filesToCopy, DataPackageOperation opera
}
}

if (!tryDelete)
return (true, shellOperationResult);

var deleteTcs = new TaskCompletionSource<bool>();
op.PreDeleteItem += [DebuggerHidden] (s, e) =>
{
Expand Down