Boost logo

Boost :

From: Erkki Seppala (flux-boost_at_[hidden])
Date: 2003-07-23 10:21:44


Hi,

I recently submitted a bug regarding handling certain letters in unix,
and got a response from Vladimir Prus pointing out the need of using
boost::filesystem::native-argument to b::f::path constructor.

It seemed to help a bit, but.. Let me demonstrate:

Source-code of a utility to remove those files from directory2 that
exist in directory1. It fails if any filename in directory1 contains a
':' (and I expect it'll fail with numerous other characters too):

--8<--

#include <iostream>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/exception.hpp>
#include <cassert>

namespace fs = boost::filesystem;

// usage: ./baz base1 base2
// utility to destroy those files from directory base2 that exist in
// directory base1

int
main(int argc, char** argv)
{
  assert(argc == 3);

  try {
    fs::path base(argv[1], fs::native);
    fs::path base2(argv[2], fs::native);
    fs::directory_iterator end;
    for (fs::directory_iterator it(base);
         it != end;
         ++it) {
      std::cout << "Removing " << it->leaf() << std::endl;
      fs::remove(*it);
      fs::remove(base2 / it->leaf());
    }
  } catch (fs::filesystem_error& e) {
    std::cout << e.what() << std::endl;
  }
}

--8<--

testing: mkdir foo bar; touch foo/a foo/: bar/a bar/: bar/c; ./baz foo bar

As this behavior (handling certain characters differently on systems
that can handle them) seems to be a designed feature, I must raise my
concern that I really don't want to see a generation of unix-programs
that fail to handle some files I have in my hd. The program above
would seem to me to be perfectly portable even if had the ability to
handle all kinds of characters in filenames. (I wouldn't want to
resort to using some depreciated native-interfaces to accomplish that
either.)

And answering to Vladimir Prus on the bug report: I would hate to see
a program that was not able to create, manipulate and unlink certain
files, just for the sake that some other platforms have problems with
those characters. Handling files called ' ', '"*?' isn't a problem for
me. I have almost a 1000 files with character : (perl manual-pages)
and some with letters < and >.. (think message-id's)

(Btw, why is this a library-issue at all anyway? I'm sure the
operating system is more than pleased to tell the program that the
filename is invalid.)

-- 
  _____________________________________________________________________
     / __// /__ ____  __               http://www.modeemi.fi/~flux/\   \
    / /_ / // // /\ \/ /                                            \  /
   /_/  /_/ \___/ /_/\_\@modeemi.fi                                  \/

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