Opened 17 years ago

Closed 17 years ago

Last modified 17 years ago

#412 closed Bugs (Out of Date)

remove_all problems on dangling symlinks

Reported by: cxdunn Owned by: beman_dawes
Milestone: Component: filesystem
Version: None Severity:
Keywords: Cc:

Description

remove_all() fails on dangling symlinks, and throws
exception when they are in subdirs.
<pre>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/exception.hpp>

#include <iostream>                        // for std::cout
using namespace std;
namespace fs = boost::filesystem;

int main(){
  system("rm -rf foo1 foo2 foo3");
  system("ln -s nowhere foo1");
  system("mkdir foo2; touch foo2/blank; echo apple >
foo2/apple");
  system("mkdir foo3; ln -s nowhere foo3/dangle");
  try {
    fs::remove_all("foo1"); //fine, but no deletion
    fs::remove_all("foo2"); //fine
    fs::remove_all("foo3"); //error
  } catch (fs::filesystem_error const& exc){
    cerr <<"ERROR:" <<exc.what() <<endl;
  }
  cerr << fs::exists("foo1") << "," <<
fs::symbolic_link_exists("foo1") <<endl;
  cerr << fs::exists("foo2") << "," <<
fs::symbolic_link_exists("foo3") <<endl;
  cerr << fs::exists("foo3") << "," <<
fs::symbolic_link_exists("foo2") <<endl;
  return 0;
}
</pre>
Result:
<pre>
ERROR:boost::filesystem::remove: "foo3": Directory not
empty
0,1
0,0
1,0
</pre>

Also note that the post-condition is violated for foo1.

Change History (4)

comment:1 by beman_dawes, 17 years ago

Logged In: YES 
user_id=51042

What version of Boost?

What compiler and operating system? What version of each?

comment:2 by cxdunn, 17 years ago

Logged In: YES 
user_id=1267419

1.31.0
gcc (g++3.3)
Red Hat Linux 7.3
Pentium 4

comment:3 by beman_dawes, 17 years ago

Status: assignedclosed
Logged In: YES 
user_id=51042

That was a known bug in Boost 1.31. You need to upgrade to
1.32 or later. 1.33 is very close to release, and fixes a
number of additional Boost.Filesystem problems, do you might
to get that when it it is released.

As a result of your bug report, I did upgrade the
operations_test regression test to probe symlink remove()
failures.

Cheers,

--Beman

comment:4 by cxdunn, 17 years ago

Logged In: YES 
user_id=1267419

Yes, this is fixed in boost-1.32. Verified.
Note: See TracTickets for help on using tickets.