Author Topic: Codeblocks overwrote main.cpp file with a blank line.  (Read 4064 times)

Offline Gimbo

  • Single posting newcomer
  • *
  • Posts: 3
Codeblocks overwrote main.cpp file with a blank line.
« 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

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7588
    • My Best Post
Re: Codeblocks overwrote main.cpp file with a blank line.
« Reply #1 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.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline sodev

  • Regular
  • ***
  • Posts: 497
Re: Codeblocks overwrote main.cpp file with a blank line.
« Reply #2 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.

Offline Gimbo

  • Single posting newcomer
  • *
  • Posts: 3
Re: Codeblocks overwrote main.cpp file with a blank line.
« Reply #3 on: October 05, 2019, 12:19:19 am »
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


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.

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1557
Re: Codeblocks overwrote main.cpp file with a blank line.
« Reply #4 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

Offline Gimbo

  • Single posting newcomer
  • *
  • Posts: 3
Re: Codeblocks overwrote main.cpp file with a blank line.
« Reply #5 on: October 05, 2019, 02:56:22 pm »
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

Offline Commaster

  • Almost regular
  • **
  • Posts: 171
Re: Codeblocks overwrote main.cpp file with a blank line.
« Reply #6 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.