Opened 6 years ago

Last modified 5 years ago

#1582 new change

DefaultFileSystem should implement atomic write operations

Reported by: trev Assignee: Mailkov
Priority: P3 Milestone:
Module: Libadblockplus Keywords:
Cc: fhd, eric@…, mapx Blocked By:
Blocking: Platform: Unknown
Ready: yes Confidential: no
Tester: Verified working: no
Review URL(s):

Description (last modified by trev)


Currently, DefaultFileSystem::Write() uses the trivial approach to write files. There are no guarantees that the file will be written completely, so if the program crashes while writing the file will be corrupted. Also, a hard reboot while the file is still in disk cache can lead to data corruption.

What to change

Make sure that the file is either written completely or stays unchanged. This can be done by using the approach currently implemented in Firefox:

  • Open temporary file. We simply add suffix .tmp to the file name, this ensures that the temp file is on the volume as the final file and that we don't create tons of temp files if we cannot clean up for some reason.
  • Write data to temporary file.
  • Flush data to disk.
  • Close temporary file.
  • Rename temporary file to have its final file name (replace existing file if necessary).
  • If any one of these steps causes an error - remove temporary file.

Change History (5)

comment:1 Changed 6 years ago by trev

  • Description modified (diff)

comment:2 Changed 6 years ago by mapx

  • Cc mapx added

comment:3 Changed 5 years ago by Mailkov

I'd like to work on this ...

Please, can you assign it to me?

comment:4 Changed 5 years ago by sergz

  • Owner set to Mailkov
Note: See TracTickets for help on using tickets.