delete will assure file is deleted?

Jeremy Bowers jerf at jerf.org
Tue Apr 26 15:13:20 EDT 2005


On Tue, 26 Apr 2005 03:40:16 -0700, ajikoe at gmail.com wrote:

> Hello Mike,
> I have to know this topic otherwise my program has to check whether the
> file / files are already deleted and this is a little bit messy.

I would be fairly confident in asserting that assuming the file is there,
you have permissions, etc., basically that the call succeeds, that the
file will be gone.

os.remove, as the module name implies, tells the OS to do something. I
would consider an OS that returned from a "remove" call, but still let you
access that file, highly broken. 

You may be concerned that the OS may not write the fact that the file is
deleted to the disk right away. This is very, very possible; OSs have been
doing that for a while. If, for some reason, this is a major concern that
the system might suddenly lose power and the file may not be truly
deleted, you will need to either shut off this feature (it is called
"write-behind caching", and shutting it off, or indeed even having the
feature at all, is OS-dependent), or get a UPS so that the machine has
time to shut down gracefully.

HOWEVER... the only time this is a problem is if you are truly concerned
about the power spontaneously shutting off. The kernel of your operating
system, if indeed it does write-behind caching at all, will make it look
to all programs on the system (not just your own) that the file is
deleted; and thus, in every sense that matters barring spectacular
power failure, it is.

So I say, ever if you've heard of write-behind caching and you are perhaps
worried about it, you do not need to be; it is intended to be fully
transparent to you, and indeed, short of directly asking the OS whether
the feature is on, there should be no practical way of figuring out
whether it is on at all. All it means is significantly better performance
to you programs if they do things like delete a lot of files at once; you
don't need to worry that they might "still be there" even after the
command is done.

This reply somewhat longer than needed for the purposes of education :-)




More information about the Python-list mailing list