Opened 10 years ago

Last modified 6 years ago

#7258 reopened Bugs

boost::filesystem::create_directories(const &path) returns false if the path contains a slash at the end of the string

Reported by: francis.thibault@… Owned by: Beman Dawes
Milestone: To Be Determined Component: filesystem
Version: Boost 1.59.0 Severity: Problem
Keywords: create_directories() Cc: francis.thibault@…

Description

for example, if we want to create that following directory: path="C:/users/test/"

the function create_directories(path) returns false even if the directory is created and exists.

However, if we remove the slash at the end of the string path="C:/users/test", the function returns true.

Is it the normal behavior of that function?

Thanks.

Change History (12)

comment:1 by anonymous, 10 years ago

I have same issue!

comment:2 by randydu@…, 10 years ago

It also happens on Mac.

The problem is:

path dir("foo/"); dir.parent_path() ==> "foo"; (not "")

hence when create_directories() is called, according to the current implementation (operations.cpp), the parent_path is created ("foo") first, then create_directory("foo/") is called and returns FALSE with an error (BOOST_ERROR_ALREADY_EXISTS).

If the trailing slash is removed:

path dir("foo"); dir.parent_path() ==> ""; (now empty: "")

then everything works perfectly.

So the bug fix is creating a public wrapper of create_directories() to remove trailing slash of input parameter before calling internal create_directories().

Thanks, Randy

comment:3 by anonymous, 9 years ago

I have the same issue!! =)

comment:4 by anonymous, 9 years ago

Version: Boost 1.52.0Boost 1.55.0

comment:5 by gilaldpellaeon@…, 8 years ago

Version: Boost 1.55.0Boost 1.57.0

I have the same issue with Boost 1.57.0 (linux).

comment:6 by hadatko, 8 years ago

Still problem 1.55.1 you can make this useful with this if(!boost::filesystem::is_directory(dir)) {

boost::filesystem::create_directories(dir); if(!boost::filesystem::is_directory(dir)) {

error code

}

}

comment:7 by Beman Dawes, 7 years ago

Resolution: fixed
Status: newclosed

Fixed. Also fixed related issues if path contains dot or dot-dot elements, and added test cases to the test suite.

The fixes have been applied to the develop branch and will be merged to master once sufficient regression tests have cycled.

Thanks,

--Beman

comment:8 by anonymous, 7 years ago

Resolution: fixed
Status: closedreopened
Version: Boost 1.57.0Boost 1.59.0

Hi,

I'm running Boost 1.59 and have found the exact same problem. The bug ISN'T fixed!

Thanks !


# g++ --version

g++ (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 5.2.0 Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

g++.exe -Wall -fexceptions -g -march=corei7 -std=c++0x -g -IC:\boost_1_59_0 -c C:\temp\c++\main.cpp -o obj\Debug\main.o g++.exe -LC:\boost_1_59_0\stage\lib -o bin\Debug\_recolle_futures.exe obj\Debug\main.o C:\boost_1_59_0\stage\lib\libboost_system-mgw52-mt-1_59.a C:\boost_1_59_0\stage\lib\libboost_filesystem-mgw52-mt-1_59.a C:\boost_1_59_0\stage\lib\libboost_regex-mgw52-mt-1_59.a C:\boost_1_59_0\stage\lib\libboost_program_options-mgw52-mt-1_59.a C:\boost_1_59_0\stage\lib\libboost_date_time-mgw52-mt-1_59.a C:\boost_1_59_0\stage\lib\libboost_iostreams-mgw52-mt-1_59.a

comment:9 by anonymous, 7 years ago

By the way, I forgot to mention that I'm running Windows 8.1 pro

comment:10 by Beman Dawes, 7 years ago

Milestone: To Be DeterminedBoost 1.60.0

It is fixed in the develop branch for Boost 1.60. Did you test against 1.59 or against the current develop branch of the filesystem repo at https://github.com/boostorg/filesystem?

If it is still failing for you on the current develop branch, please submit a small program that isolates the problem.

Thanks,

--Beman

comment:11 by Smithd407, 6 years ago

Component: filesystemxpressive
Milestone: Boost 1.60.0Website 1.X
Severity: ProblemNot Applicable
Type: BugsLibrary Submissions
Version: Boost 1.59.0Boost.Build-M3

Thanksamundo for the post.Really thank you! Awesome. ekegdddkdcadbkgf

comment:12 by Kohei Takahashi, 6 years ago

Component: xpressivefilesystem
Milestone: Website 1.XTo Be Determined
Severity: Not ApplicableProblem
Type: Library SubmissionsBugs
Version: Boost.Build-M3Boost 1.59.0

I couldn't undo milestone to 1.60 due to closed.

Note: See TracTickets for help on using tickets.