Skip to content

Commit 74cbe8f

Browse files
Copilotd2dyno1
andauthored
Fix recycle bin restore CI test failure fallback path
Agent-Logs-Url: https://github.com/securefolderfs-community/SecureFolderFS/sessions/5631e187-dc72-4c6d-a29a-d55b85ab3c13 Co-authored-by: d2dyno1 <53011783+d2dyno1@users.noreply.github.com>
1 parent defcb53 commit 74cbe8f

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

src/Platforms/SecureFolderFS.UI/Storage/RecycleBinFolder.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,29 @@ public async Task RestoreItemsAsync(IEnumerable<IStorableChild> items, IFolderPi
5656
if (_specifics.Options.IsReadOnly)
5757
throw FileSystemExceptions.FileSystemReadOnly;
5858

59-
var allItems = items.Select(x => x is IRecycleBinItem recycleBinItem ? recycleBinItem.AsWrapper<IStorable>().GetWrapperAt(1).Inner : x).Cast<IStorableChild>().ToArray();
60-
switch (allItems.Length)
59+
var allItems = items.ToArray();
60+
var storableItems = allItems.Select(x => x is IRecycleBinItem recycleBinItem ? recycleBinItem.AsWrapper<IStorable>().GetWrapperAt(1).Inner : x).Cast<IStorableChild>().ToArray();
61+
switch (storableItems.Length)
6162
{
6263
case 1:
6364
{
64-
var item = allItems[0];
65+
var item = storableItems[0];
6566
var destinationFolder = await AbstractRecycleBinHelpers.GetDestinationFolderAsync(
6667
item,
6768
_specifics,
6869
StreamSerializer.Instance,
6970
cancellationToken);
7071

72+
if (destinationFolder is null && allItems[0] is IRecycleBinItem recycleBinItem)
73+
{
74+
var originalParentPath = Path.GetDirectoryName(recycleBinItem.Id);
75+
if (!string.IsNullOrWhiteSpace(originalParentPath))
76+
{
77+
destinationFolder = await SafetyHelpers.NoFailureAsync(async () =>
78+
await AbstractPathHelpers.GetCiphertextItemAsync(originalParentPath, _specifics, cancellationToken) as IModifiableFolder);
79+
}
80+
}
81+
7182
// Prompt the user to pick the folder when the default destination couldn't be used
7283
destinationFolder ??= await GetDestinationFolderAsync();
7384
if (destinationFolder is null)
@@ -90,7 +101,7 @@ await AbstractRecycleBinHelpers.RestoreAsync(
90101
if (destinationFolder is null)
91102
throw new InvalidOperationException("The destination folder couldn't be chosen.");
92103

93-
foreach (var item in allItems)
104+
foreach (var item in storableItems)
94105
{
95106
await AbstractRecycleBinHelpers.RestoreAsync(
96107
item,

0 commit comments

Comments
 (0)