Boost logo

Boost :

From: Mattias Flodin (flodin_at_[hidden])
Date: 2002-08-01 03:23:44


On Thu, Aug 01, 2002 at 08:28:23AM +0100, Keith Burton wrote:
<about what remove() should do when the file no longer exists>
> It should do nothing and return nothing as the operation has succeeded
> in that the post condition is true.

The way I interpret the meaning of exists, in this context, it means "is
reachable". Let's say for instance that exists("/floppy/foo") returns
true because a disk is mounted to the /floppy dir that contains the file
foo. The disk is then unmounted, leaving the /floppy dir empty. Now,
exists("/floppy/foo") will return false, because the file is no longer
reachable. That doesn't mean the file no longer exists, or that it has
been physically deleted.

What I expect of remove() to do, however, is to physically remove the
file. Not to make sure it is no longer reachable. So, although !exists()
can be trivially listed as a post-condition of remove(), it is not the
whole truth. The whole truth is that it is not only unreachable, but
physically deleted.

> ( This being much preferable to an attempt to avoid the exception by
> doing if ( exists( ph ) ) remove( ph ) ; and the post condition not
> being true )

This kind of code is dangerous because the two subexpressions of the
condition are not evaluated in one atomic operation. Perhaps the
documentation should mention this, to prevent people from trying it.
exists() must be true at the point of calling remove(), not 0.5
nanoseconds before.

/Mattias

-- 
Mattias Flodin <flodin_at_[hidden]>  -  http://www.cs.umu.se/~flodin/
Room NADV 102
Department of Computing Science
Umeå University
S-901 87 Umeå, Sweden
--
"There are two ways of constructing a software design; one way is to make it
so simple that there are obviously no deficiencies, and the other way is to
make it so complicated that there are no obvious deficiencies.  The first
method is far more difficult." -- C. A. R. Hoare

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk