From 2dc78ad6a927238271ec16a2a2b949a48b1ac8ee Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Fri, 27 Dec 2024 18:11:21 +0700 Subject: [PATCH] TIL: Truncate doesn't truncate if nothing is written --- src/core/positioning/positioningsource.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/core/positioning/positioningsource.cpp b/src/core/positioning/positioningsource.cpp index 97a21f2903..8179486335 100644 --- a/src/core/positioning/positioningsource.cpp +++ b/src/core/positioning/positioningsource.cpp @@ -152,9 +152,11 @@ void PositioningSource::setBackgroundMode( bool backgroundMode ) if ( mBackgroundMode ) { - QFile file( QStringLiteral( "%1.information" ).arg( backgroundFilePath ) ); - file.open( QFile::Truncate ); - file.close(); + if ( QFile::exists( QStringLiteral( "%1.information" ).arg( backgroundFilePath ) ) ) + { + // Remove previously collected position information + QFile::remove( QStringLiteral( "%1.information" ).arg( backgroundFilePath ) ); + } } emit backgroundModeChanged();