How to safely erase a file / directory in Python?

Is there any module that provides somehow basic “safe” deletion, sth. for example, the Linux utility “erase”, for example

import securitystuff

securitystuff.wipe( filename )

I need to protect the source code of the company, which should not be easily restored.

PS Yes, I know that "wiping" is not ideal, for example. on file system journaling. But the demand for security is not very high.

+3
source share
1 answer

There is no such function in the standard library, and a naive implementation that overwrites each byte of a file with a random byte is not so difficult to do, for example.

 f = open(path, "wb")
 f.write("*"*os.path.getsize(path))
 f.close()
 os.unlink(path)

, http://mail.python.org/pipermail/python-list/2004-September/899488.html, , . , .. ..

, , linux wipe python.

- srm

+3

Source: https://habr.com/ru/post/1750981/


All Articles