mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-02-20 14:57:45 +01:00
feat: wrap writes in a transaction
This commit is contained in:
parent
f027b684ed
commit
c1fd08cc93
1 changed files with 19 additions and 16 deletions
|
|
@ -95,25 +95,28 @@ public class ReliableFileStorage : IServiceType, IDisposable
|
||||||
{
|
{
|
||||||
ArgumentException.ThrowIfNullOrEmpty(path);
|
ArgumentException.ThrowIfNullOrEmpty(path);
|
||||||
|
|
||||||
var normalizedPath = NormalizePath(path);
|
this.db.RunInTransaction(() =>
|
||||||
var file = this.db.Table<DbFile>().FirstOrDefault(f => f.Path == normalizedPath && f.ContainerId == containerId);
|
|
||||||
if (file == null)
|
|
||||||
{
|
{
|
||||||
file = new DbFile
|
var normalizedPath = NormalizePath(path);
|
||||||
|
var file = this.db.Table<DbFile>().FirstOrDefault(f => f.Path == normalizedPath && f.ContainerId == containerId);
|
||||||
|
if (file == null)
|
||||||
{
|
{
|
||||||
ContainerId = containerId,
|
file = new DbFile
|
||||||
Path = normalizedPath,
|
{
|
||||||
Data = bytes,
|
ContainerId = containerId,
|
||||||
};
|
Path = normalizedPath,
|
||||||
this.db.Insert(file);
|
Data = bytes,
|
||||||
}
|
};
|
||||||
else
|
this.db.Insert(file);
|
||||||
{
|
}
|
||||||
file.Data = bytes;
|
else
|
||||||
this.db.Update(file);
|
{
|
||||||
}
|
file.Data = bytes;
|
||||||
|
this.db.Update(file);
|
||||||
|
}
|
||||||
|
|
||||||
Util.WriteAllBytesSafe(path, bytes);
|
Util.WriteAllBytesSafe(path, bytes);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue