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

QSettings IniFormat writes are not atomic

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Done
    • Affects Version/s: 4.7.4
    • Fix Version/s: 5.4.0
    • Component/s: Core: I/O
    • Labels:
      None
    • Environment:
      Linux with Qt 4.5.3
    • Commits:
      I0844a5e96c8bc1e1222a3dac6cc48170ca77fe1b

      Description

      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

        Attachments

          Issue Links

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

            Activity

              People

              • Assignee:
                ogoffart Olivier Goffart (Woboq GmbH)
                Reporter:
                gabij Gabi Julien
              • Votes:
                12 Vote for this issue
                Watchers:
                19 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes