Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-21739

QSettings IniFormat writes are not atomic



    • Bug
    • Resolution: Done
    • P2: Important
    • 5.4.0
    • 4.7.4
    • Core: I/O
    • None
    • Linux with Qt 4.5.3
    • I0844a5e96c8bc1e1222a3dac6cc48170ca77fe1b


      Everytime QSettings syncs to disk using the IniFormat (which can be frequent), it resizes the current file to 0 and rewrites it from scratch. This approach can cause problems. First of all, if the application is killed before it can write the new file, all original settings will be lost. Secondly, modern file systems like ext4 have a cache and changes to the file might be incomplete if the machine loses power. Finally, if there is not enough space on disk to rewrite the original settings, the file is unfortunately wipe out again. This is why other programs like "vi" will create a swap file and atomically replace files.

      The reason we are reporting this is that we encountered a rare bug in our application where we lose all original settings in the .conf files and we strongly suspect this is the reason. I created a patch against qt 4.5.3 that you will found attached to this bug report. The drawback of this patch is that you need enough space on disk to write the swap file but this is preferable to the risk on losing important settings in the original configuration file.

      Thank you.
      Gabi Julien


        Issue Links

          For Gerrit Dashboard: QTBUG-21739
          # Subject Branch Project Status CR V



              ogoffart Olivier Goffart (Woboq GmbH)
              gabij Gabi Julien
              12 Vote for this issue
              19 Start watching this issue



                Gerrit Reviews

                  There are no open Gerrit changes