Boost logo

Boost Users :

From: Beman Dawes (bdawes_at_[hidden])
Date: 2003-12-12 12:21:11


At 09:03 AM 12/12/2003, Peter Dimov wrote:
>Beman Dawes wrote:
>> It would have to be:
>>
>> int processFile(const fs::path& fileName)
>> {
>> fs::path copyFileName(fileName.string() + ".bak", fs::native);
>> fs::copy_file(fileName, copyFileName);
>> }
>
>I don't see why. string() returns a path "formatted according to the
rules
>of the generic path string grammar", i.e. '/' separator. Aren't native
>paths allowed to use a ':' separator with '/' being a legitimate part
>of the name, for instance?

Yep. My mistake. See below.

>Why does the original
>
> fs::path copyFileName(fileName.string() + ".bak");
>
>throw? I see nothing that could cause fileName.string() + ".bak" to fail
>validation. Am I missing something, or is this a bug?

(What follows is based on current CVS version)

It throws because the name_check was set to portable_name, and that doesn't
allow ':' as a character.

Because the function's fileName argument is already a path, it is known to
have already been check by an appropriate name checker. Furthermore, if
appending ".bak" to copyFileName invalidates it, that will be detected
right away by the copy_file call. So not checking at all might be
appropriate:

   void processFile(const fs::path& fileName)
   {
       fs::path copyFileName(fileName.string() + ".bak", fs::no_check);
       fs::copy_file(fileName, copyFileName);
   }

But Michele Galante's original suggestion is perhaps better:

   int processFile(const fs::path& fileName)
   {
       fs::path copyFileName(fileName.native_file_string() + ".bak",
                             fs::native);
       fs::copy_file(fileName, copyFileName);
   }

--Beman


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net