Clean temp storage on FileSystemServer init

This commit is contained in:
Alex Barney 2020-01-12 16:14:56 -07:00
parent 5c1a7920d2
commit 5b0c81fcf9
6 changed files with 68 additions and 11 deletions

View file

@ -29,6 +29,13 @@ namespace LibHac.Fs
Time = timer ?? new StopWatchTimeSpanGenerator();
}
internal FileSystemClient(FileSystemServer fsServer, IFileSystemProxy fsProxy, ITimeSpanGenerator timer)
{
FsSrv = fsServer;
FsProxy = fsProxy;
Time = timer ?? new StopWatchTimeSpanGenerator();
}
public bool HasFileSystemServer()
{
return FsSrv != null;

View file

@ -12,10 +12,6 @@ namespace LibHac.FsService
public class FileSystemProxy : IFileSystemProxy
{
private FileSystemProxyCore FsProxyCore { get; }
/// <summary>The client instance to be used for internal operations like save indexer access.</summary>
// ReSharper disable once UnusedAutoPropertyAccessor.Local
private FileSystemClient FsClient { get; }
private FileSystemServer FsServer { get; }
public long CurrentProcess { get; private set; }
@ -25,10 +21,9 @@ namespace LibHac.FsService
public FsPath SaveDataRootPath { get; } = default;
public bool AutoCreateSaveData { get; private set; }
internal FileSystemProxy(FileSystemProxyCore fsProxyCore, FileSystemClient fsClient, FileSystemServer fsServer)
internal FileSystemProxy(FileSystemProxyCore fsProxyCore, FileSystemServer fsServer)
{
FsProxyCore = fsProxyCore;
FsClient = fsClient;
FsServer = fsServer;
CurrentProcess = -1;
@ -1072,6 +1067,32 @@ namespace LibHac.FsService
throw new NotImplementedException();
}
public Result CleanUpTemporaryStorage()
{
Result rc = FsProxyCore.OpenSaveDataDirectory(out IFileSystem saveDirFs, SaveDataSpaceId.Temporary,
string.Empty, false);
if (rc.IsFailure()) return rc;
rc = saveDirFs.CleanDirectoryRecursively("/");
if (rc.IsFailure()) return rc;
SaveDataIndexerReader reader = default;
try
{
rc = FsServer.SaveDataIndexerManager.GetSaveDataIndexer(out reader, SaveDataSpaceId.Temporary);
if (rc.IsFailure()) return rc;
reader.Indexer.Reset();
return Result.Success;
}
finally
{
reader.Dispose();
}
}
public Result SetSdCardAccessibility(bool isAccessible)
{
throw new NotImplementedException();

View file

@ -29,13 +29,15 @@ namespace LibHac.FsService
throw new ArgumentException("DeviceOperator must not be null");
ExternalKeySet externalKeySet = config.ExternalKeySet ?? new ExternalKeySet();
ITimeSpanGenerator timer = config.TimeSpanGenerator ?? new StopWatchTimeSpanGenerator();
Timer = config.TimeSpanGenerator ?? new StopWatchTimeSpanGenerator();
FsProxyCore = new FileSystemProxyCore(config.FsCreators, externalKeySet, config.DeviceOperator);
FsClient = new FileSystemClient(this, timer);
Timer = timer;
var fsProxy = new FileSystemProxy(FsProxyCore, this);
FsClient = new FileSystemClient(this, fsProxy, Timer);
SaveDataIndexerManager = new SaveDataIndexerManager(FsClient, SaveIndexerId);
fsProxy.CleanUpTemporaryStorage();
}
/// <summary>
@ -58,7 +60,7 @@ namespace LibHac.FsService
public IFileSystemProxy CreateFileSystemProxyService()
{
return new FileSystemProxy(FsProxyCore, FsClient, this);
return new FileSystemProxy(FsProxyCore, this);
}
}

View file

@ -5,6 +5,7 @@ namespace LibHac.FsService
public interface ISaveDataIndexer
{
Result Commit();
Result Reset();
Result Add(out ulong saveDataId, ref SaveDataAttribute key);
Result Get(out SaveDataIndexerValue value, ref SaveDataAttribute key);
Result AddSystemSaveData(ref SaveDataAttribute key);

View file

@ -112,6 +112,23 @@ namespace LibHac.FsService
}
}
public Result Reset()
{
lock (Locker)
{
IsKvdbLoaded = false;
Result rc = FsClient.DeleteSaveData(SaveDataId);
if (rc.IsSuccess() || rc == ResultFs.TargetNotFound)
{
Version++;
}
return rc;
}
}
public Result Add(out ulong saveDataId, ref SaveDataAttribute key)
{
saveDataId = default;

View file

@ -18,6 +18,15 @@ namespace LibHac.FsService
return Result.Success;
}
public Result Reset()
{
lock (Locker)
{
IsKeyValueSet = false;
return Result.Success;
}
}
public Result Add(out ulong saveDataId, ref SaveDataAttribute key)
{
lock (Locker)