-3

Consider the following sequence of actions:

  • I instruct a program to open a file,
  • (I modify the file in the program, and save it to the file. )
  • I mv the file elsewhere. For example, the file was originally dir1/dir2/dir3/all.pdf, and then I ran mv dir1/dir2/dir3 dir1/; rmdir dir1/dir2. Now the file is dir1/dir3/all.pdf.
  • I modify the file in the program
  • I instruct the program to save the modified to the new location of the file, via "save as ...".

Is whether "save as ..." with file moving succeeds or fails up to the program? For example,

While another program moves files, what does a program need to do to save changes to the files successfully (either to the new location or the original one)?

Does the OS or filesystem not be able to warn or prevent such cases from happening?

What can we do to avoid or reduce the likelihood of data loss, in such cases, regardless of which program, OS or filesystem?

Thanks.

Tim
  • 101,790

1 Answers1

2

Can a program native to Linux fail "save as ..." and lose the file, or fail "save as..." and keep the file intact, or succeed in "save as ..."?

In GNU/Linux, if a file is open by any program, it will be loaded into memory. If you moved or even delete the file in the disk, it will still be in memory. When you save it again, it would be saved from memory to disk again. Some programs would even notify you about the deleting and prompt you to save as or ignore, e.g. kate. Other operating systems or emulation software vary in this behavior.

To get more technical knowledge on how this works in GNU/Linux read this

Munzir Taha
  • 1,490
  • Thanks. I got notifications in my case. PDFXCView in wine notified me that it can't save to the original location. So I tried save as .... to the new location. It also notified me it can't save as ... to the new location, and furthermore surprisingly make the file at the new location disappear. – Tim Jan 27 '20 at 13:29
  • @StackExchangeforAll: wine and windows has completely different behavior due to a limitation in their architecture, but who cares ;) – Munzir Taha Jan 27 '20 at 13:31
  • Do you mean the cause of my file loss is wine not the application PDFXCView? – Tim Jan 27 '20 at 13:33
  • @StackExchangeforAll: It could be both. I don't use wine or any Windows software but you can answer this question yourself by trying libreoffice e.g. If it faces the same problem, then the limitation is in Wine/Windows. BTW, when I say limitation, it's my view point. They may argue it's by design so you don't need to ask your question – Munzir Taha Jan 27 '20 at 17:10