QGeoFileTileCache: handle write errors (better)
The old code (before ac8af1548ede1b69f0c6cfe18840a5303fcb24c3) didn't
check the return values of QFile::open() and write(), causing a cache
miss in the best case or persisting corrupt data (on a short write,
e.g.) in the worst. ac8af1548ede1b69f0c6cfe18840a5303fcb24c3 fixed
that, but only insofar as the handling of errors was concerned. In
particular, a short write would still leave a garbage file around,
albeit not in the in-memory index.
Use QSaveFile and check the return values of open(), write(), and
commit(). Add the file to the in-memory cache structure only if all
that succeeded. The insert() can only fail if cost > maxCost (or on
std::bad_alloc, which we ignore, as usual, in Qt), so do the check
early and not even write the file in that case.
There's stil one problem with the code: while QSaveFile (like QFile
before it) writes through symlinks, the QFile::remove() call used to
evict a file from the cache removes the symlink, and not its
target. This author would prefer to fix that issue by preventing
QSaveFile from following symlinks (which requires new API), rather
than replacing the remove() call with a symlink-following version, but
at the time of writing, there is no concensus among reviewers for this
approch, so leaving that for a follow-up patch.
Amends 5f42e961560a54a2d3978b42478cd90bc8c6927d(!) and the hot-fix
ac8af1548ede1b69f0c6cfe18840a5303fcb24c3.
Pick-to: 6.9 6.8 6.5 5.15
Change-Id: I0f3b25a1c0631cc92165bac556b03c086e03fb1f
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>