Skip to content

io/fileview: handle commit failure and preserve state on failed writes - #1585

Open
leierx wants to merge 1 commit into
quickshell-mirror:masterfrom
leierx:fix/fileview-write-failure
Open

leierx wants to merge 1 commit into
quickshell-mirror:masterfrom
leierx:fix/fileview-write-failure

Conversation

@leierx

@leierx leierx commented Dec 2, 2026

Copy link
Copy Markdown

Describe your changes

Fixes several bugs around FileView write failures and retries:

  1. FileViewWriter::write warns when QSaveFile::commit() fails (Write of ... failed: Atomic commit failed.) but does not set state.error = FileViewError::Unknown, so saved() is emitted instead of saveFailed(). Since QFileDevice::write() buffers up to 16 KiB in user space, small writes to a full disk only fail in commit() (or flush() when atomicWrites is false).
  2. Unlike FileViewReader, FileViewWriter populates state.data before running. On a failed write, updateState() copies that unwritten state.data into this->state.data and emits dataChanged() / textChanged(). Because setText() and setData() skip writes matching writeCmpData(), retrying setText() / setData() / writeAdapter() with the same content after saveFailed() is a no-op.
  3. FileViewWriter::write sets state.exists = info.exists() before creating the file and never updates it on success, leaving loaded false after writing a new file.
  4. cancelAsync() calls tryCancel() before checking liveReader() vs liveWriter(); an in-flight writer waited on by waitForJob() skips write() with state.error == Success and emits saved(). operationFinished() and waitForJob() also clear liveOperation after emitting, so a retry started from onSaveFailed re-enters waitForJob() on the finished writer and then has its new liveOperation overwritten with nullptr.

Details and descisions

  • Set state.error = FileViewError::Unknown and return when commit() (or file->flush() for non-atomic writes) fails, and set state.exists = true at the end of a successful write.
  • Pass isWrite to updateState(). On a failed write, keep this->state.data and this->mPrepared unchanged (or clear this->state.data if pathChanged and it was non-empty), and only return &this->state.data from writeCmpData() when this->mPrepared && this->state.error == FileViewError::Success.
  • Only call tryCancel() for liveReader() in cancelAsync(), and clear this->liveOperation before updateState() and signal emission in operationFinished() and waitForJob().
  • Added unit tests in src/io/test/fileview.cpp covering QSaveFile::commit() failure (RLIMIT_FSIZE = 0), back-to-back writes on a read-only directory, and retrying setText() from onSaveFailed; fails before, passes after.

Open concerns

None.

Participation

Found while testing full-disk and read-only state handling in my shell.

Set state.error = FileViewError::Unknown when QSaveFile::commit() or
QFile::flush() fails in FileViewWriter::write, and mark state.exists =
true once a write succeeds so creating a new file updates loaded.

In FileView::updateState, do not overwrite state.data, set mPrepared, or
emit dataChanged/textChanged when a write fails unless an old path's
non-empty data is being cleared. Only compare against state.data in
writeCmpData() when mPrepared is true and state.error is Success.

Clear liveOperation before updateState() and completion signals in
operationFinished() and waitForJob(), and only call tryCancel() on
liveReader() in cancelAsync() so waiting on an in-flight writer does not
abort it and report Success.
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