Boost logo

Boost :

From: Rob Stewart (stewart_at_[hidden])
Date: 2005-03-31 13:06:26

From: Beman Dawes <bdawes_at_[hidden]>
> Because is_accessible() is an attempt to deal with certain problems of
> exists(), let's go back to the original problem with exists(). Some errors
> clearly indicate the path is not present, so exists() needs to return
> false. On POSIX, those would be:
> [ENOENT] A component of path does not name an existing file or
> path is an empty string.
> [ENOTDIR] A component of the path prefix is not a directory.


> One POSIX error would indicate the path does exist:
> [EOVERFLOW] The file size in bytes or the number of blocks
> allocated to the file or the file serial number cannot be
> represented correctly in the structure pointed to by buf.


> But with the following errors I can't see any way to know if the path
> actually exists or not:
> [EACCES] Search permission is denied for a component of the path prefix.

Peter's query is key here: what does it mean for exist() to
return true or false? You could say that returning false here is
appropriate because, as far as the current user is concerned, the
file doesn't exist.

> [EIO] An error occurred while reading from the file system.

Is this a permanent failure? If so, it is reasonable to return
false: at this time, the file doesn't exist, even if the
intention is that it does. If it is a temporary failure, then a
retry might succeed in finding the real answer. In that case, it
is appropriate that the caller know that a retry is in order.

> [ELOOP] A loop exists in symbolic links encountered during resolution
> of the path argument.

While that is an error condition, it doesn't prevent declaring
that the file, as given by the supplied pathname, doesn't exist.

> [ENAMETOOLONG] The length of the path argument exceeds {PATH_MAX} or
> a pathname component is longer than {NAME_MAX}.

The pathname clearly doesn't exist because it is invalid.
Whether the file the caller is interested in actually exists is a
separate question. You can only answer whether the supplied
pathname refers to an existing file.

If the caller wants to know whether a pathname is valid and names
an existing file, isn't that a different question (or set of

> If you agree with that analysis, then it looks like exists() should be
> changed to throw on those last four errors. is_accessible() would have a

I disagree. All the caller wants to know is whether the supplied
pathname refers to an existing file.

> role in that it would return false on those same four errors because
> regardless of whether or not the path exists, it clearly isn't accessible.

Accessibility involves ACLs and permissions as well as
existence. It is a more restrictive query, at least in my mind.

Rob Stewart                           stewart_at_[hidden]
Software Engineer           
Susquehanna International Group, LLP  using std::disclaimer;

Boost list run by bdawes at, gregod at, cpdaniel at, john at