Code::Blocks Forums

User forums => Help => Topic started by: Gimbo on October 04, 2019, 10:29:54 PM

Title: Codeblocks overwrote main.cpp file with a blank line.
Post by: Gimbo on October 04, 2019, 10:29:54 PM
Hello everybody, i was working on a project and it was almost finished, but suddently laptop battery died and my laptop was brutally shutted down.
After i restarted the pc i noticed that my main.cpp was overwritten with a blank line. Is there any way to recover the old version of my main.cpp?

Please help me, this is very frustrating
Title: Re: Codeblocks overwrote main.cpp file with a blank line.
Post by: stahta01 on October 04, 2019, 11:15:11 PM
Code::Blocks normally copies the file before overwriting it.
Look for a file using an text editor with about the same name; but, with another extension.
Inside the same folder would be where I suggest looking.
Others might have more detail information.

Tim S.
Title: Re: Codeblocks overwrote main.cpp file with a blank line.
Post by: sodev on October 04, 2019, 11:19:34 PM
Did you ever save the file? Because if not nothing got overwritten but the file was empty all the time and there is nothing to restore.
Title: Re: Codeblocks overwrote main.cpp file with a blank line.
Post by: Gimbo on October 05, 2019, 12:19:19 AM
Quote from: stahta01 on October 04, 2019, 11:15:11 PM
Code::Blocks normally copies the file before overwriting it.
Look for a file using an text editor with about the same name; but, with another extension.
Inside the same folder would be where I suggest looking.
Others might have more detail information.

Tim S.

In the project folder i get only main.o and main.cpp files


Quote from: sodev on October 04, 2019, 11:19:34 PM
Did you ever save the file? Because if not nothing got overwritten but the file was empty all the time and there is nothing to restore.
Yes, I was working on this project since few day.
Title: Re: Codeblocks overwrote main.cpp file with a blank line.
Post by: Miguel Gimenez on October 05, 2019, 10:57:30 AM
C::B first saves the file (p.e. Test.cpp) in the same folder with the name ending in ".temp". If Test.cpp.temp saves OK then C:B try renaming it as Test.cpp, removing the previous file if it existed. If this operation fails, the Test.cpp.temp file is renamed as Test.cpp.save-failed.

If there is neither a .temp file nor a .save-failed file then I suspect a filesystem failure.

Reference: src\sdk\filemanager.cpp -> FileManager::Save() method
Title: Re: Codeblocks overwrote main.cpp file with a blank line.
Post by: Gimbo on October 05, 2019, 02:56:22 PM
Quote from: Miguel Gimenez on October 05, 2019, 10:57:30 AM
C::B first saves the file (p.e. Test.cpp) in the same folder with the name ending in ".temp". If Test.cpp.temp saves OK then C:B try renaming it as Test.cpp, removing the previous file if it existed. If this operation fails, the Test.cpp.temp file is renamed as Test.cpp.save-failed.

If there is neither a .temp file nor a .save-failed file then I suspect a filesystem failure.

Reference: src\sdk\filemanager.cpp -> FileManager::Save() method
unfortunately there is not .temp file
Title: Re: Codeblocks overwrote main.cpp file with a blank line.
Post by: Commaster on October 06, 2019, 08:24:49 AM
I suspect this is related to configured write caching for the drive. You might want to disable write caching for the drive you are working on, this might reduce the I/O bandwidth but will protect the data in case of such power outages.

P.S. Code::Blocks moved the old file to .temp, created the new .cpp file and the OS reported that as a success even though it was still pending in the write cache.