From 22d7bfb41054c6860febf7c4c5cdcfb770349ef4 Mon Sep 17 00:00:00 2001 From: Mario Steele Date: Sat, 2 Aug 2025 13:31:39 -0500 Subject: [PATCH] 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. --- FreeTubeSyncer/REST/Syncer.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/FreeTubeSyncer/REST/Syncer.cs b/FreeTubeSyncer/REST/Syncer.cs index 0726331..d80a2cb 100644 --- a/FreeTubeSyncer/REST/Syncer.cs +++ b/FreeTubeSyncer/REST/Syncer.cs @@ -213,13 +213,17 @@ public class Syncer : 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);