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:
parent
65b026edc4
commit
22d7bfb410
1 changed files with 5 additions and 1 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue