Skip to content

fix(core): make a new database file only where nothing is - #4316

Merged
datlechin merged 3 commits into
mainfrom
fix/new-file-create-only-if-missing
Nov 18, 2026
Merged

datlechin merged 3 commits into
mainfrom
fix/new-file-create-only-if-missing

Conversation

@datlechin

Copy link
Copy Markdown
Member

Summary

  • A new SQLite or DuckDB file is made only where nothing is, so a file another program made between the app's check and Connect is never replaced. FileOpenMode::CreateNew reports a file there as the new driver.file_exists (DriverError::FileExists).
  • SQLite makes the empty file with create_new (O_EXCL). DuckDB builds beside the path as before, then hard links it into place, which fails on anything there; a file system without links gets a copy through an exclusive create_new handle.
  • A failed create never removes or writes a file at the path that it did not make.
  • Replacing moved to a new FileOpenMode::Replace (FileEndpoint::replace), same behavior as before.
  • Windows: Connect no longer checks File.Exists before the create. driver.file_exists opens the file as it is, as the form does for a file there when it was named (and as macOS does).
  • Linux: New Database sends Replace only for a file there when the save chooser closed, since the chooser asked about it. A free name sends CreateNew, and a file made there before Connect is kept, with a message. A successful Test of a new file turns the row to open that file, so Connect does not refuse it.
  • macOS: no change. Its drivers create a missing file or open the one there, and never replace.
  • FFI: no shape change, so no bindings change. create already said the path must not exist.
  • Tests that pinned replacing under CreateNew now use FileEndpoint::replace: the SQLite and DuckDB open_semantics tests and the DuckDB instance and create_file tests.

Test plan

  • Core, both drivers: a_file_made_after_the_path_was_checked_is_never_replaced keeps the file and its journal or log, with nothing left beside them. Also a free path, a stale log, a symbolic link at the path, a missing folder, and DuckDB's copy for a file system without links.
  • Core: create_new_keeps_a_database_already_there (SQLite) and a_new_database_keeps_a_database_already_there (DuckDB).
  • FFI: a_new_file_never_replaces_one_made_after_the_path_was_checked (SQLite and DuckDB): connect.driver, driver.file_exists, the path, the bytes kept.
  • Windows interop: AFileMadeAfterThePathWasCheckedIsNeverReplaced (DuckDB and SQLite).
  • Windows UI: AFileMadeAfterTheNewNameWasChosenOpensAsItIs: names a free file, the sample appears there, Connect opens its tables.
  • Linux: a_new_name_replaces_only_a_file_the_chooser_asked_about, a_tested_new_file_is_opened_by_connect, a_file_already_there_names_it_and_says_it_was_kept.

@datlechin
datlechin merged commit a7299b3 into main Nov 18, 2026
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant