Subject: [Boost-bugs] [Boost C++ Libraries] #1972: boost::filesystem::remove() throws on self referenced symlinks
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2008-05-30 12:23:52
#1972: boost::filesystem::remove() throws on self referenced symlinks
-----------------------------+----------------------------------------------
Reporter: dizzy_at_[hidden] | Owner: bemandawes
Type: Bugs | Status: new
Milestone: Boost 1.36.0 | Component: filesystem
Version: Boost 1.35.0 | Severity: Problem
Keywords: |
-----------------------------+----------------------------------------------
If one creates a symlink like this "ln -s sym sym" (to itself symlink),
bfs::exists("sym") will throw because the documentation defines it to do
so
(and I have nothing against it doing so, although in my programs because
of
this I am forced to just use "lstat()" and I can't replace using "lstat()"
to
check if something exists with bfs::exists).
However, I do think that bfs::remove("sym") throwing for the same reason
(because it calls upon bfs::exists()) is the wrong thing to do. The source
around bfs::remove() implementation even try to solve the issue of
"dangling
symlinks" as they call it by having an exception in case bfs::exists
returns
false and the target path points to a dangling symlink and still tries to
remove it. Unfortunetly, exists will throw in my example of a symlink (not
even dangling technically speaking :) ) even tho a remove on that kind of
symlink should work just fine (it does work in shell or just doing
std::remove()).
If boost::exists is going to be left in place to throw for those "valid"
symlinks (because exists is suposed to try to dereference symlinks and
dereferencing such a recursive symlink is always an error) then the only
solution I see is to not use exists at all. Because I also found that
remove and remove_all are fairly inefficient regarding repetitive calls fo
stat/lstat on the same path I've created the attached patch that fixes the
reported problem and would be more efficient "system call" wise.
I am using Linux and ext3 filesystem tho in theory it should perform the
same on any symlink supporting platform (since symlinks are just
containers of strings as defined by POSIX and if you try to dereference a
self referencing symlink you should always get an error different than
ENOENT and others for which exists() does not throw).
--
Ticket URL: <http://svn.boost.org/trac/boost/ticket/1972>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:57 UTC