helix-editor / helix

A post-modern modal text editor.
https://helix-editor.com
Mozilla Public License 2.0
32.93k stars 2.43k forks source link

'file modified by an external process' message with double :w :w on big files #11167

Open noktoborus opened 2 months ago

noktoborus commented 2 months ago

Summary

I think problem here:

    pub fn save<P: Into<PathBuf>>(
        &mut self,
        doc_id: DocumentId,
        path: Option<P>,
        force: bool,
    ) -> anyhow::Result<()> {
        // convert a channel of futures to pipe into main queue one by one
        // via stream.then() ? then push into main future

        let path = path.map(|path| path.into());
        let doc = doc_mut!(self, &doc_id);
        let doc_save_future = doc.save(path, force)?;

        // <...>

        use futures_util::stream;

        self.saves
            .get(&doc_id)
            .ok_or_else(|| anyhow::format_err!("saves are closed for this document!"))?
            .send(stream::once(Box::pin(future)))
            .map_err(|err| anyhow!("failed to send save event: {}", err))?;

        self.write_count += 1;

        Ok(())
    }

All write operations are queued without verification, and when the next record is queued, a copy of the metadata contains outdated, not up-to-date information. In fact, I think it would be logical to interrupt the current write operation to the file and start a new one with the following `:w'. In addition, it would be nice to report in the status bar that recording has started (and is continuing), instead of silence.

What can be done?

Reproduction Steps

  1. open really big file (~1gb) or use slow disk
  2. type :w
  3. without waiting for the 'written' message type :w again

result: file written once, message 'file modified by an external process' is displayed

expectations: All changes between the first :w and the second :w are written.

Helix log

No response

Platform

Linux

Terminal Emulator

Alacritty

Installation Method

source

Helix Version

helix 24.3 (8123d818)

wasade commented 1 week ago

I think I'm getting this as well. First write to a (small, 2.5kb file) on a NFS mount works. Subsequent writes yield "file modified by an external process". No other helix processes are running on the system or against the NFS mount.