Conversation
Copying over an existing file writes to a temporary "tmp_*" path, and only the main file is renamed back once the copy is finalized. Drivers that spread a single dataset over several files (such as the .shx, .dbf and .prj sidecars of an ESRI Shapefile) therefore left those files behind under their temporary name, while the new main file kept being paired with the sidecars of the previous export. Rename them together with the main file.
Maxxen
self-requested a review
September 22, 2026 13:25
Member
|
Thanks! |
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.
Fixes #859.
Problem
Copying over an existing file writes to a
tmp_*path, and only the main file is renamed back once the copy is finalized. Drivers that spread one dataset over several files therefore leave the remaining files behind under their temporary name, while the new main file keeps being paired with the leftovers of the previous export:The re-exported dataset is then read through the sidecars of the previous export. On DuckDB 1.5.5 the one-row export above still returns two rows, and other shapes of the same mismatch fail with
IO Error: Error in fread() reading object ... from .shp file.Fix
The GDAL copy function now records the path the dataset was created at, looks up the files belonging to that dataset while it is still open, and renames the ones still carrying the temporary name alongside the main file. The main file is still renamed by DuckDB itself, and components a driver reports without having created them are skipped, so single-file drivers are unaffected.
Validation
Reproduced on DuckDB 1.5.5 (Windows, x86_64) with the shipped spatial build: before the change the two-step export leaves
tmp_overwrite.dbfandtmp_overwrite.shxbehind andST_Readreturns 2 rows.test/sql/gdal/st_write_overwrite.testasserts both the absence of leftover temporary files and the correct row count.I could not compile the extension locally (no CMake/vcpkg/GDAL toolchain on this machine), so that test has only been run against the unpatched build, where it fails on both assertions; the source change itself has not been compiled here.