ActivityWatch / aw-core

Core library for ActivityWatch
Mozilla Public License 2.0
48 stars 47 forks source link

fix: Add flush+fsync to write of config files #101

Closed johan-bjareholt closed 3 years ago

johan-bjareholt commented 3 years ago

This is to lower the risk of corrupted config files

Hopefully this should reduce the risk of issues like https://github.com/ActivityWatch/activitywatch/issues/502

The writes are still not completely safe though I think, to do that you would need to temporarily write the file to another file, flush+fsync and then move the file over the old one as renaming a file is atomic. At least that's how it works on Linux, assume it's the same on macOS/Linux. But this was a quick fix and probably good enough.

codecov[bot] commented 3 years ago

Codecov Report

Merging #101 (03c62e3) into master (5864398) will increase coverage by 0.01%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #101      +/-   ##
==========================================
+ Coverage   91.27%   91.28%   +0.01%     
==========================================
  Files          33       33              
  Lines        1558     1560       +2     
  Branches      240      240              
==========================================
+ Hits         1422     1424       +2     
  Misses        105      105              
  Partials       31       31              
Impacted Files Coverage Δ
aw_core/config.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 5864398...03c62e3. Read the comment docs.

ErikBjare commented 3 years ago

@johan-bjareholt Should we add this to the new toml configuration too maybe?