Skip to content

Commit fd3685e

Browse files
authored
Fix crash when deleting files (#8438)
1 parent 576501f commit fd3685e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/Files/Filesystem/FilesystemOperations/ShellFilesystemOperations.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public async Task<IStorageHistory> DeleteItemsAsync(IList<IStorageItemWithPath>
224224
return await filesystemOperations.DeleteItemsAsync(source, progress, errorCode, permanently, cancellationToken);
225225
}
226226

227-
var deleleFilePaths = source.Select(s => s.Path);
227+
var deleleFilePaths = source.Select(s => s.Path).Distinct();
228228
var deleteFromRecycleBin = source.Any() ? recycleBinHelpers.IsPathUnderRecycleBin(source.ElementAt(0).Path) : false;
229229
permanently |= deleteFromRecycleBin;
230230

@@ -273,7 +273,7 @@ public async Task<IStorageHistory> DeleteItemsAsync(IList<IStorageItemWithPath>
273273
var recycledSources = deleteResult.Items.Where(x => x.Succeeded && x.Destination != null && x.Source != x.Destination);
274274
if (recycledSources.Any())
275275
{
276-
var sourceMatch = await recycledSources.Select(x => source.SingleOrDefault(s => s.Path == x.Source)).Where(x => x != null).ToListAsync();
276+
var sourceMatch = await recycledSources.Select(x => source.DistinctBy(x => x.Path).SingleOrDefault(s => s.Path == x.Source)).Where(x => x != null).ToListAsync();
277277
return new StorageHistory(FileOperationType.Recycle,
278278
sourceMatch,
279279
await recycledSources.Zip(sourceMatch, (rSrc, oSrc) => new { rSrc, oSrc })
@@ -287,7 +287,7 @@ public async Task<IStorageHistory> DeleteItemsAsync(IList<IStorageItemWithPath>
287287
var failedSources = deleteResult.Items
288288
.Where(x => !x.Succeeded && x.HResult != HResult.COPYENGINE_E_USER_CANCELLED && x.HResult != HResult.COPYENGINE_E_RECYCLE_BIN_NOT_FOUND);
289289
return await filesystemOperations.DeleteItemsAsync(
290-
await failedSources.Select(x => source.SingleOrDefault(s => s.Path == x.Source)).Where(x => x != null).ToListAsync(), progress, errorCode, permanently, cancellationToken);
290+
await failedSources.Select(x => source.DistinctBy(x => x.Path).SingleOrDefault(s => s.Path == x.Source)).Where(x => x != null).ToListAsync(), progress, errorCode, permanently, cancellationToken);
291291
}
292292
}
293293

0 commit comments

Comments
 (0)