Skip to content

Commit aaeb7b0

Browse files
authored
Fix: Fixed issue where online-only files deleted before confirmation (#11335)
1 parent 607eb50 commit aaeb7b0

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/Files.App/Helpers/FileOperationsHelpers.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ namespace Files.App.Helpers
2626
{
2727
public class FileOperationsHelpers
2828
{
29+
private static readonly Ole32.PROPERTYKEY PKEY_FilePlaceholderStatus = new Ole32.PROPERTYKEY(new Guid("B2F9B9D6-FEC4-4DD5-94D7-8957488C807B"), 2);
30+
private const uint PS_CLOUDFILE_PLACEHOLDER = 8;
31+
2932
private static ProgressHandler? progressHandler; // Warning: must be initialized from a MTA thread
3033

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

121124
var shellOperationResult = new ShellOperationResult();
125+
var tryDelete = false;
122126

123127
for (var i = 0; i < fileToDeletePath.Length; i++)
124128
{
125129
if (!SafetyExtensions.IgnoreExceptions(() =>
126130
{
127131
using var shi = new ShellItem(fileToDeletePath[i]);
128132
var file = SafetyExtensions.IgnoreExceptions(() => GetFirstFile(shi)) ?? shi;
129-
op.QueueDeleteOperation(file);
133+
if (file.Properties.GetProperty<uint>(PKEY_FilePlaceholderStatus) == PS_CLOUDFILE_PLACEHOLDER)
134+
{
135+
// Online only files cannot be tried for deletion, so they are treated as to be permanently deleted.
136+
shellOperationResult.Items.Add(new ShellOperationItemResult()
137+
{
138+
Succeeded = false,
139+
Source = fileToDeletePath[i],
140+
HResult = HRESULT.COPYENGINE_E_RECYCLE_BIN_NOT_FOUND
141+
});
142+
}
143+
else
144+
{
145+
op.QueueDeleteOperation(file);
146+
tryDelete = true;
147+
}
130148
}))
131149
{
132150
shellOperationResult.Items.Add(new ShellOperationItemResult()
@@ -138,6 +156,9 @@ public static Task SetClipboard(string[] filesToCopy, DataPackageOperation opera
138156
}
139157
}
140158

159+
if (!tryDelete)
160+
return (true, shellOperationResult);
161+
141162
var deleteTcs = new TaskCompletionSource<bool>();
142163
op.PreDeleteItem += [DebuggerHidden] (s, e) =>
143164
{

0 commit comments

Comments
 (0)