Skip to content

Take the name of a file that is not there yet - #13

Open
rodgco wants to merge 2 commits into
omacom-io:masterfrom
rodgco:fix/open-missing-file
Open

Take the name of a file that is not there yet#13
rodgco wants to merge 2 commits into
omacom-io:masterfrom
rodgco:fix/open-missing-file

Conversation

@rodgco

@rodgco rodgco commented Aug 16, 2026

Copy link
Copy Markdown

Fixes #6. The analysis and the shape of this fix are @Vyrnexis's, from the issue.

Backend::open only reads. A path with nothing behind it fails the ReadOnly open, reports "Could not open", and returns before setFileUrl, so the document ends up with no name at all — and Backend::save falls back to saveAsDialog(). Starting a file the way every editor is asked to start one, omawrite new_document.md, therefore met the portal's Save As dialog asking for a name that had already been given on the command line.

open now claims the URL for a blank document when the path is not there yet, so the first save lands where the writer said it should. A path that exists but cannot be read — a directory, a file without read permission — is still an error, and still leaves the document it could not replace alone.

The status line says New file new_document.md, and nothing is written until the writer saves.

Test

startsANewFileFromAPathThatIsNotThereYet drives the real Main.qml document:

  • opening a path that is not there names the document, leaves it blank and unmodified, and writes nothing to disk;
  • typing and saving lands on that path with no Save As dialog requested (QSignalSpy on saveDialogRequested stays at 0);
  • a file that is there still opens and reads;
  • a path that cannot be read still reports Could not open, keeping the previous document and its URL.

The test fails on master (fileUrl comes back invalid) and passes with the fix. Full suite in build-tests: 13 passed, 0 failed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TyQRJCyR76uk7XaNAB8jMC

rodgco and others added 2 commits August 16, 2026 11:32
Backend::open only reads: a path with nothing behind it fails the
ReadOnly open, reports "Could not open", and returns before setFileUrl,
so the document keeps no name at all. Opening a file that has yet to be
written -- `omawrite new_document.md`, the way every editor is asked to
start one -- therefore left Ctrl+S with nothing to save to, and the
portal's Save As dialog asked for a name the writer had already given.

Claim the URL for a blank document when the path is not there, and let
the first save land on it. A path that exists but cannot be read is
still an error, as it should be: this is only about the file that is
not there yet.

Fixes omacom-io#6

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TyQRJCyR76uk7XaNAB8jMC
Taking any absent path meant a name under a directory that is not there was accepted too, and the failure moved from the open to the first save: `omawrite ~/notes/2026/draft.md` with no `2026/` directory opened a document titled `draft.md`, and Ctrl+S then answered with `Could not save draft.md.` in the footer and no dialog, because the URL was valid enough to skip the Save As fallback that used to catch this. Same for a name in a directory the writer cannot write, and for a trailing-slash path, which is a directory name that `fileName()` reports as `Untitled.md`.

Claim the name only where the file could actually be created. Everything else keeps master's answer: `Could not open`, and the first save still offers somewhere to put the text.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed against master and ran the suite on a disposable VM: 13 passed, 0 failed, before and after the commit below.

Pushed 770f714 to this branch. The early return took any absent path, including one under a directory that is not there, or one the writer cannot write into — and that moves the failure from the open to the first save, where there is no longer a Save As fallback to land in. omawrite ~/notes/2026/draft.md with no 2026/ directory opens a document titled draft.md, and Ctrl+S answers with Could not save draft.md. in the footer and no dialog, because the URL is now valid enough to skip saveAsDialog(). A trailing-slash path is the same case and shows as Untitled.md, since fileName() is empty for it. The commit claims the name only where the file could actually be created, leaves everything else on master's Could not open, and adds one assertion to your test — which fails without the guard.

Two things I did not change, for the maintainer to decide:

  • Nothing watches the path between open and the first save: watchCurrentFile() can only watch a file that already exists, and no directory is watched. If another process creates that file in the meantime — a git pull, a sync client — saveTo() replaces it via QSaveFile::commit() with no external-change dialog, because m_hasKnownFileContents is false and no watcher event was ever possible. On master that case went through the Save As dialog, which asks before overwriting. Narrow, but it is a guard this removes rather than one that was never there.
  • reloadFromDisk() calls open(m_fileUrl), so if the file vanishes between the "File changed" dialog opening and the Reload click, Reload now blanks the document and clears recovery instead of reporting Could not open and leaving it alone. The dialog disables Reload when it already knows the file was deleted, so only that race reaches it.

Worth knowing before merge: #9 rewrites the same function. It routes every write of m_lastKnownFileContents/m_hasKnownFileContents through a new setKnownFileContents() that also maintains m_lastKnownFileText, the baseline its editorTextChanged compares against to clear the modified flag. This block sets those two members by hand and never touches m_lastKnownFileText, so whichever lands second, the new-file path has to call setKnownFileContents(QByteArray(), false). Left as is: open an existing file, then open a name that is not there, and the baseline stays the old file's text — typing exactly that text into the blank document clears modified, deletes the recovery snapshot, and closing the window never asks.

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.

Bug: Opening a non-existent file from terminal forces "Save As" dialog on first save

2 participants