Fix NUL characters file corruption after power outrages (1st step solution)#14860
Closed
donho wants to merge 1 commit intonotepad-plus-plus:masterfrom
Closed
Fix NUL characters file corruption after power outrages (1st step solution)#14860donho wants to merge 1 commit intonotepad-plus-plus:masterfrom
donho wants to merge 1 commit intonotepad-plus-plus:masterfrom
Conversation
…ution) ========= Sernario: ========= When a user modifies a file in Notepad++, and the time of periodic backup (defaulted to 7 seconds) is reached, the backup of the modified file is being written. However, if a power outage occurs during this precise moment while the file is being written, file corruption may occur. ======= Remedy: ======= The goal is to maintain a non-corrupted file sample even during power outages. Here are the steps: 0. Begin 1. Write the file A as A.temp 2. Replace A by A.temp 3. End During these steps, the cutoff can happen at any moment, but the user will always have a non-corrupted file sample (either A or A.temp). ===== Note: ===== The solution is only applied to "new #" files, since these files are generally small in length and do not have a second "physical" file existing on the hard drive. ref: notepad-plus-plus#6133 (comment) Fix notepad-plus-plus#6133
Member
Author
donho
commented
Mar 14, 2024
| ::ReplaceFile(fullpath, fullpathTemp.c_str(), nullptr, REPLACEFILE_IGNORE_MERGE_ERRORS | REPLACEFILE_IGNORE_ACL_ERRORS, 0, 0); | ||
| else | ||
| ::MoveFileEx(fullpathTemp.c_str(), fullpath, MOVEFILE_REPLACE_EXISTING); | ||
| } |
Member
Author
There was a problem hiding this comment.
@xomx
The above block can use only ::MoveFileEx(fullpathTemp.c_str(), fullpath, MOVEFILE_REPLACE_EXISTING);.
Is there any advantage to combined with ::ReplaceFile(fullpath, fullpathTemp.c_str(), nullptr, REPLACEFILE_IGNORE_MERGE_ERRORS | REPLACEFILE_IGNORE_ACL_ERRORS, 0, 0); as you suggested?
Contributor
|
@donho , |
Contributor
|
@donho |
Member
Author
|
@xomx |
Contributor
Member
Author
|
Thank you @xomx ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sernario:
When a user modifies a file in Notepad++, and the time of periodic backup (defaulted to 7 seconds) is reached, the backup of the modified file is being written. However, if a power outage occurs during this precise moment while the file is being written, file corruption may occur.
Remedy:
The goal is to maintain a non-corrupted file sample even during power outages. Here are the steps:
During these steps, the cutoff can happen at any moment, but the user will always have a non-corrupted file sample (either A or A.temp).
Note:
The solution is applied only to "new #" files, since these files are generally small in length and do not have a second "physical" file existing on the hard drive.
ref: #6133 (comment)
Fix #6133