Skip to content

Commit

Permalink
make it so RestoreFrom returns the actual restored snapshot.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeme committed Nov 30, 2023
1 parent 19617f1 commit 983e3af
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/DotJEM.Json.Index2.Snapshots/IndexSnapshotHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public interface IIndexSnapshotHandler
{
Task<ISnapshot> TakeSnapshotAsync(IJsonIndex index, ISnapshotStorage storage);
Task<bool> RestoreSnapshotAsync(IJsonIndex index, ISnapshot source);
Task<bool> RestoreSnapshotFromAsync(IJsonIndex index, ISnapshotStorage storage);
Task<ISnapshot> RestoreSnapshotFromAsync(IJsonIndex index, ISnapshotStorage storage);
}

public class IndexSnapshotHandler : IIndexSnapshotHandler
Expand Down Expand Up @@ -106,7 +106,7 @@ public async Task<bool> RestoreSnapshotAsync(IJsonIndex index, ISnapshot snapsho
//return true;
}

public async Task<bool> RestoreSnapshotFromAsync(IJsonIndex index, ISnapshotStorage storage)
public async Task<ISnapshot> RestoreSnapshotFromAsync(IJsonIndex index, ISnapshotStorage storage)
{
index.Storage.Delete();
Directory dir = index.Storage.Directory;
Expand All @@ -115,7 +115,7 @@ public async Task<bool> RestoreSnapshotFromAsync(IJsonIndex index, ISnapshotStor
try
{
if(await UnpackSnapshotAsync(index, snapshot, dir))
return true;
return snapshot;
}
catch (Exception e)
{
Expand All @@ -124,7 +124,8 @@ public async Task<bool> RestoreSnapshotFromAsync(IJsonIndex index, ISnapshotStor
index.Storage.Delete();
}
}
return false;

return null;
}

private static async Task<bool> UnpackSnapshotAsync(IJsonIndex index, ISnapshot snapshot, Directory dir)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static async Task<bool> RestoreSnapshotAsync(this IJsonIndex self, ISnaps
return await handler.RestoreSnapshotAsync(self, snapshot);
}

public static async Task<bool> RestoreSnapshotFromAsync(this IJsonIndex self, ISnapshotStorage storage)
public static async Task<ISnapshot> RestoreSnapshotFromAsync(this IJsonIndex self, ISnapshotStorage storage)
{
IIndexSnapshotHandler handler = self.ResolveSnapshotHandler();
return await handler.RestoreSnapshotFromAsync(self, storage);
Expand Down

0 comments on commit 983e3af

Please sign in to comment.