News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

Codeblocks overwrote main.cpp file with a blank line.

Started by Gimbo, October 04, 2019, 10:29:54 PM

Previous topic - Next topic

Gimbo

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

stahta01

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.
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

sodev

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.

Gimbo

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.

Miguel Gimenez

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

Gimbo

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

Commaster

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.