mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-01-03 06:13:40 +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);
|
||||
|
||||
var normalizedPath = NormalizePath(path);
|
||||
var file = this.db.Table<DbFile>().FirstOrDefault(f => f.Path == normalizedPath && f.ContainerId == containerId);
|
||||
if (file == null)
|
||||
this.db.RunInTransaction(() =>
|
||||
{
|
||||
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,
|
||||
Path = normalizedPath,
|
||||
Data = bytes,
|
||||
};
|
||||
this.db.Insert(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
file.Data = bytes;
|
||||
this.db.Update(file);
|
||||
}
|
||||
file = new DbFile
|
||||
{
|
||||
ContainerId = containerId,
|
||||
Path = normalizedPath,
|
||||
Data = bytes,
|
||||
};
|
||||
this.db.Insert(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
file.Data = bytes;
|
||||
this.db.Update(file);
|
||||
}
|
||||
|
||||
Util.WriteAllBytesSafe(path, bytes);
|
||||
Util.WriteAllBytesSafe(path, bytes);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue