Possible Fix

Needs testing.  Switched to using a Temporary file to write out the
freetube database format, removing the old database, then copying over
the new one, instead of writing directly to it, in hope of fixing the
sporadic corruption of the database files.
This commit is contained in:
Mario Steele 2025-08-02 13:31:39 -05:00
parent 65b026edc4
commit 22d7bfb410

View file

@ -213,13 +213,17 @@ public class Syncer<T> : ISyncer where T : class, IDataModel, new()
foreach (var entry in _entries)
json.Add(entry.JsonData());
_watcher.Locked = true;
using (var fh = File.OpenWrite(_dbPath))
var tmpfile = Path.GetTempFileName();
using (var fh = File.OpenWrite(tmpfile))
{
foreach (var line in json)
fh.Write(Encoding.UTF8.GetBytes(line + "\n"));
fh.Flush();
}
File.Delete(_dbPath);
File.Move(tmpfile, _dbPath);
Task.Delay(100).Wait();
_watcher.Locked = false;
Log.Information("Updated {DbName}, completed in {TimeSpan}", _dbName, DateTime.Now - start);