Fix GeoPackage writer silently appending data when target file is in use - #1511
Open
adamnadolny-wizipisi wants to merge 1 commit into
Open
Conversation
stempler
reviewed
Jun 22, 2026
stempler
left a comment
Member
There was a problem hiding this comment.
Thanks a lot for the contribution. Looks good to me so far, now waiting for the workflow runs.
Please make sure to modify the commit message to follow conventional commits (fix: commit)
adamnadolny-wizipisi
force-pushed
the
fix/geopackage-writer-overwrite-1201
branch
2 times, most recently
from
June 23, 2026 07:19
a4a7437 to
02ef5cc
Compare
…use (halestudio#1201) When the 'overwriteTargetFile' option is enabled and the target .gpkg file cannot be deleted (e.g. it is locked by QGIS or another process on Windows), File.delete() returns false without throwing an exception. The writer then proceeds to open the existing file and appends data instead of overwriting it. Fix: check the return value of File.delete() and throw IOException if deletion fails, so the caller receives a proper error report instead of silently corrupted output. Adds regression test testOverwriteFailsWhenFileInUse() that simulates a locked file by holding an open RandomAccessFile handle during the second write attempt. The test is skipped on non-Windows platforms where open handles do not prevent file deletion. Fixes halestudio#1201 Signed-off-by: The Wroclaw Institute of Spatial Information and Artificial Intelligence (WIZIPISI - Wrocławski Instytut Zastosowań Informacji Przestrzennej i Sztucznej Inteligencji) <adam.nadolny@wizipisi.ai>
adamnadolny-wizipisi
force-pushed
the
fix/geopackage-writer-overwrite-1201
branch
from
June 23, 2026 08:59
02ef5cc to
d8563ad
Compare
|
This pull request has been automatically marked as stale because it has not had activity in the last 60 days. It will be closed in two weeks if no further activity occurs. Thank you for your contributions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1201
When the Overwrite target file if it exists option is enabled but the target .gpkg file cannot be deleted (e.g. it is locked by QGIS or another process on Windows), File.delete() returns False silently. The writer then opens the existing file and appends data instead of overwriting it — resulting in duplicated records with no error reported to the user.
Root cause
In GeopackageInstanceWriter.java (around line 202), the return value of File.delete() was not checked:
java // before fix file.delete(); // silently returns false if file is lockedFix
Check the return value and throw IOException if deletion fails:
java if (!file.delete()) { throw new IOException("Cannot overwrite existing GeoPackage file (file may be in use): " + file.getAbsolutePath()); }The exception is caught by the surrounding ry/catch in execute(), which marks the report as failed and records the error — so the user sees a clear error message instead of silently corrupted output.
Test
Added estOverwriteFailsWhenFileInUse() to GeopackageInstanceWriterTest:
Submitted by: The Wroclaw Institute of Spatial Information and Artificial Intelligence
(WIZIPISI — Wrocławski Instytut Zastosowań Informacji Przestrzennej i Sztucznej Inteligencji)