Deleting a file does not mean deleting it

In the past, files accidentally deleted by Windows could be recovered using DiskGenius, because only the index was deleted on the disk, and the actual content would not be deleted until new data was written. This is also reasonable. Disk reading and writing have a lifespan. There is no need to write again to overwrite the data for ordinary deletion.

Recently, I was writing test code on macOS. One of the tests was to simulate the user's space clearing behavior. After deleting the video file, it can be downloaded again. During the test, it was found that after the file was deleted from the disk and it was confirmed that it was deleted from the memory, the data was not downloaded again. After debugging for a long time, I found that the data was read from the disk, but I had obviously deleted the file. (In order to imitate user behavior, I directly called rm to delete it.) Later I learned that even if the file on the disk is closed, as long as the handle is not closed, the data can still be read from the handle .

As long as the handle is held, other processes cannot write data to this file. Therefore, you must remember to close the handle.

Guess you like

Origin blog.csdn.net/ZhaoBuDaoFangXia/article/details/92799480