Skip to content

Fix NUL characters file corruption after power outrages (1st step solution)#14860

Closed
donho wants to merge 1 commit intonotepad-plus-plus:masterfrom
donho:fix_NUL_char_after_powerOutrages
Closed

Fix NUL characters file corruption after power outrages (1st step solution)#14860
donho wants to merge 1 commit intonotepad-plus-plus:masterfrom
donho:fix_NUL_char_after_powerOutrages

Conversation

@donho
Copy link
Member

@donho donho commented Mar 14, 2024

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:

  1. Begin
  2. Write the file A as A.temp
  3. Replace A by A.temp
  4. 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 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

…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
@donho
Copy link
Member Author

donho commented Mar 14, 2024

@pnedev @xomx
Please review this PR.

::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);
}
Copy link
Member Author

@donho donho Mar 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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?

@pnedev
Copy link
Contributor

pnedev commented Mar 15, 2024

@donho ,
Looks good to me 👍

@xomx
Copy link
Contributor

xomx commented Mar 15, 2024

@donho
I will try to check this tomorrow.

@donho
Copy link
Member Author

donho commented Mar 17, 2024

@xomx
No rush, take your time for reviewing the PR.
I'll merge it into master for v8.6.5 Release Candidate. Even it's merged into master, we are still in RC stage.
So RC2 could be done for the optimisation of the PR if it's necessary.

@donho donho closed this in 590ea74 Mar 17, 2024
@xomx
Copy link
Contributor

xomx commented Mar 17, 2024

@donho
Thanks for the patience, I know that you would like to release the 8.6.5, but unfortunately not enough time at my side just now.
I know about at least one serious problem in the now closed #14858 (will report there), I did not even started checking this one :-(

@donho
Copy link
Member Author

donho commented Mar 17, 2024

Thank you @xomx !

@donho donho deleted the fix_NUL_char_after_powerOutrages branch March 21, 2024 14:37
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.

The NUL file-corruption bug appears to not be completely gone (v7.7.1 reported)

3 participants