-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] File zeroed on save if you quit too quickly #58
Comments
At the moment, I am considering possible solutions to the Colour Panic bug, see #42, and came across the I found this implementation working identically compared to the current one: pub fn strip_trailing_whitespace(text: Rope) -> Rope {
text.lines()
.map(|x| x.to_string().trim_end().to_string() + "\n")
.collect()
} Does this version raise the performance when changing the implementation in |
Despite that my suggestion adds another newline to end of the buffer, how does it perform in contrast to the original implementation regarding your example on your machine? |
In my opinion, there are two major starting points to solve this issue:
Implementing just one of them leaves the other one open and, thus, makes it source for further bugs. The complete solution should consist of an implementation of both features. Regarding the waiting mechanism, we would need to signal the end of the saving operation to the key input handler. The first question to answer is how the writing operation's ending can be queried without interrupting it. Freezing the editor as long as the file is written is surely not the most preferable option but in the end, it would be an emergency solution. When taking a look at the implementation of the whitespace cropping function, it looks for me as if the an implementation using iterators would be more efficient since at the moment, the required values are queried whenever they are needed which seems to cause this implementation taking much time. The iterator approach would just go over the whole text once without needing to lookup neighboured data multiple times since it is implicit. Unfortunately, the collectors are not very flexible which may cause unnecessary type conversions. Any ideas? |
I've opened PR #60 to add a configuration parameter to disable removing trailing white space on save. My thought process on this is that it is expensive and might not be the right for all users in all cases. As mentioned in the PR, my changes also move the call to remove trailing white space from between when the file is truncated and when it is written to before it is truncated which doesn't fix the issue with the user being able to close the application while the file is still being written but it should greatly reduce the chances of triggering it in most cases. In addition, I agree with the need to implement both a mechanism to wait for saving to finish and to optimize the white space trimming code. I did so prototyping on disallowing exiting while a file is being saved (why "dirty buffers exist really) and it looks fairly straight forward. Buffers track their modify status so anything that isn't
To do this properly, I think we would need a new variant of PromptAction which displays a message such as "Unsaved buffer exist, quit anyway? yes/no" and allows the user to enter yes/no or y/n. The user's input would then control whether the original request to quit is completed utilizing the callback mechanism. Optimizing |
How about making the waiting for the saving to finish an option for the configuration file, as well? |
@kevinmatthes the big issue with the above PoC and why I mention that it shouldn't be committed it is that it stops the user from being able to exit without saving even in cases where they don't want to persist the changes made, for example when using zee to temporarily write something up that will be copied to another application. I think adding a option to the configuration for this would be short lived since it would go away if/when interactive messages are added to zee. |
When testing zee's performance when working with large files I came across an issue where a file's content can be partially of completely lost on save if you quit the application before the save operation has completed.
Steps to reproduce:
Digging into the code, it appears the following potential issues exist which together allow for zeroing the file:
File::create()
strip_trailing_whitespace()
slows down the save operation enough that it actually takes 5-10 seconds to write out a 953M fileMy testing was done using a build of zee from the master branch on macOS 12.4 (arm64).
The text was updated successfully, but these errors were encountered: