Skip to content

Commit 0a23784

Browse files
authored
Merge pull request #668 from evoskuil/master
Fix win32 file path handling.
2 parents 1d9628f + eb678b2 commit 0a23784

26 files changed

+64
-394
lines changed

include/bitcoin/database/boost.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,11 @@ inline file_handle_t open_existing_file(
4848
const std::filesystem::path& file) NOEXCEPT
4949
{
5050
constexpr auto mode = interprocess::read_write;
51-
#if defined(HAVE_MSC)
52-
const auto filename = system::to_extended_path(file);
53-
#else
54-
const auto filename = file;
55-
#endif
51+
const auto filename = system::extended_path(file);
5652

5753
// Does not throw (unannotated).
5854
BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
59-
return ipcdetail::open_existing_file(file.string().c_str(), mode);
55+
return ipcdetail::open_existing_file(filename.c_str(), mode);
6056
BC_POP_WARNING()
6157
}
6258

include/bitcoin/database/tables/names.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ namespace libbitcoin {
2626
namespace database {
2727
namespace schema {
2828

29+
/// These should be ASCII only.
30+
2931
namespace dir
3032
{
3133
constexpr auto heads = "heads";

src/file/utilities.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,18 @@ BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
4444

4545
inline path trim(const path& value) NOEXCEPT
4646
{
47+
static const string_list trims{ "/", "\\", "\x20" };
48+
4749
// Trailing slash may cause successful create_directories returning false.
48-
return system::trim_right_copy(value.string(), { "/", "\\", "\x20" });
50+
return to_path(trim_right_copy(from_path(value), trims));
4951
}
5052

5153
// We don't use ec because it gets set (not found) when false, but no way to
5254
// differentiate from false with failure code (and never a code on success).
5355
bool is_directory(const path& directory) NOEXCEPT
5456
{
5557
code ec{ system::error::errorno_t::no_error };
56-
return std::filesystem::is_directory(system::to_extended_path(directory), ec);
58+
return std::filesystem::is_directory(system::extended_path(directory), ec);
5759
}
5860

5961
bool clear_directory(const path& directory) NOEXCEPT
@@ -64,7 +66,7 @@ bool clear_directory(const path& directory) NOEXCEPT
6466
code clear_directory_ex(const path& directory) NOEXCEPT
6567
{
6668
code ec{ system::error::errorno_t::no_error };
67-
const auto path = system::to_extended_path(directory);
69+
const auto path = system::extended_path(directory);
6870
std::filesystem::remove_all(path, ec);
6971
if (ec) return ec;
7072
std::filesystem::create_directories(path, ec);
@@ -79,7 +81,7 @@ bool create_directory(const path& directory) NOEXCEPT
7981
code create_directory_ex(const path& directory) NOEXCEPT
8082
{
8183
code ec{ system::error::errorno_t::no_error };
82-
const auto path = system::to_extended_path(trim(directory));
84+
const auto path = system::extended_path(trim(directory));
8385
const auto created = std::filesystem::create_directories(path, ec);
8486
if (ec || created) return ec;
8587
return system::error::errorno_t::is_a_directory;
@@ -182,7 +184,7 @@ bool remove(const path& name) NOEXCEPT
182184
code remove_ex(const path& name) NOEXCEPT
183185
{
184186
code ec{ system::error::errorno_t::no_error };
185-
std::filesystem::remove(system::to_extended_path(name), ec);
187+
std::filesystem::remove(system::extended_path(name), ec);
186188
return ec;
187189
}
188190

@@ -196,8 +198,8 @@ bool rename(const path& from, const path& to) NOEXCEPT
196198
code rename_ex(const path& from, const path& to) NOEXCEPT
197199
{
198200
code ec{ system::error::errorno_t::no_error };
199-
std::filesystem::rename(system::to_extended_path(from),
200-
system::to_extended_path(to), ec);
201+
std::filesystem::rename(system::extended_path(from),
202+
system::extended_path(to), ec);
201203

202204
return ec;
203205
}
@@ -212,8 +214,8 @@ bool copy(const path& from, const path& to) NOEXCEPT
212214
code copy_ex(const path& from, const path& to) NOEXCEPT
213215
{
214216
code ec{ system::error::errorno_t::no_error };
215-
std::filesystem::copy_file(system::to_extended_path(from),
216-
system::to_extended_path(to), ec);
217+
std::filesystem::copy_file(system::extended_path(from),
218+
system::extended_path(to), ec);
217219

218220
return ec;
219221
}
@@ -234,8 +236,8 @@ code copy_directory_ex(const path& from, const path& to) NOEXCEPT
234236
return system::error::errorno_t::not_a_directory;
235237

236238
code ec{ system::error::errorno_t::no_error };
237-
std::filesystem::copy(system::to_extended_path(from),
238-
system::to_extended_path(to), ec);
239+
std::filesystem::copy(system::extended_path(from),
240+
system::extended_path(to), ec);
239241

240242
return ec;
241243
}
@@ -250,7 +252,7 @@ code copy_directory_ex(const path& from, const path& to) NOEXCEPT
250252

251253
int open(const path& filename, bool MSC_OR_NOAPPLE(random)) NOEXCEPT
252254
{
253-
const auto path = system::to_extended_path(filename);
255+
const auto path = system::extended_path(filename);
254256
int file_descriptor{};
255257

256258
#if defined(HAVE_MSC)
@@ -371,7 +373,7 @@ code size_ex(size_t& out, const std::filesystem::path& filename) NOEXCEPT
371373
{
372374
code ec{ system::error::errorno_t::no_error };
373375
const auto size = std::filesystem::file_size(
374-
to_extended_path(filename), ec);
376+
system::extended_path(filename), ec);
375377

376378
if (ec) return ec;
377379
if (is_limited<size_t>(size))
@@ -389,7 +391,8 @@ bool space(size_t& out, const path& filename) NOEXCEPT
389391
code space_ex(size_t& out, const path& filename) NOEXCEPT
390392
{
391393
code ec{ system::error::errorno_t::no_error };
392-
const auto space = std::filesystem::space(to_extended_path(filename), ec);
394+
const auto space = std::filesystem::space(
395+
system::extended_path(filename), ec);
393396
if (ec) return ec;
394397
if (is_limited<size_t>(space.available))
395398
return system::error::errorno_t::value_too_large;

src/locks/file_lock.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ bool file_lock::destroy() NOEXCEPT
5757
// remove returns false if file did not exist though error_code is false if
5858
// file did not exist. use of error_code overload also precludes exception.
5959
std::error_code ec;
60-
std::filesystem::remove(system::to_extended_path(file_), ec);
60+
std::filesystem::remove(system::extended_path(file_), ec);
6161
return !ec;
6262
}
6363

test/file/rotator.cpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,7 @@
1818
*/
1919
#include "../test.hpp"
2020

21-
struct rotator_setup_fixture
22-
{
23-
DELETE_COPY_MOVE(rotator_setup_fixture);
24-
BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
25-
26-
rotator_setup_fixture() NOEXCEPT
27-
{
28-
BOOST_REQUIRE(test::clear(test::directory));
29-
}
30-
31-
~rotator_setup_fixture() NOEXCEPT
32-
{
33-
BOOST_REQUIRE(test::clear(test::directory));
34-
}
35-
36-
BC_POP_WARNING()
37-
};
38-
39-
BOOST_FIXTURE_TEST_SUITE(rotator_tests, rotator_setup_fixture)
21+
BOOST_FIXTURE_TEST_SUITE(rotator_tests, test::directory_setup_fixture)
4022

4123
// ostream instance.
4224
using rotate = file::stream::out::rotator;

test/file/utilities.cpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,7 @@
1818
*/
1919
#include "../test.hpp"
2020

21-
struct file_utilities_setup_fixture
22-
{
23-
DELETE_COPY_MOVE(file_utilities_setup_fixture);
24-
BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
25-
26-
file_utilities_setup_fixture() NOEXCEPT
27-
{
28-
BOOST_REQUIRE(test::clear(test::directory));
29-
}
30-
31-
~file_utilities_setup_fixture() NOEXCEPT
32-
{
33-
BOOST_REQUIRE(test::clear(test::directory));
34-
}
35-
36-
BC_POP_WARNING()
37-
};
38-
39-
BOOST_FIXTURE_TEST_SUITE(file_utilities_tests, file_utilities_setup_fixture)
21+
BOOST_FIXTURE_TEST_SUITE(file_utilities_tests, test::directory_setup_fixture)
4022

4123
using namespace system;
4224
static_assert(file::invalid == -1);

test/locks/file_lock.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,7 @@
1818
*/
1919
#include "../test.hpp"
2020

21-
struct file_lock_setup_fixture
22-
{
23-
file_lock_setup_fixture() noexcept
24-
{
25-
BOOST_REQUIRE(test::clear(test::directory));
26-
}
27-
28-
~file_lock_setup_fixture() noexcept
29-
{
30-
BOOST_REQUIRE(test::clear(test::directory));
31-
}
32-
};
33-
34-
BOOST_FIXTURE_TEST_SUITE(file_lock_tests, file_lock_setup_fixture)
21+
BOOST_FIXTURE_TEST_SUITE(file_lock_tests, test::directory_setup_fixture)
3522

3623
class access final
3724
: public file_lock

test/locks/flush_lock.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,7 @@
1818
*/
1919
#include "../test.hpp"
2020

21-
struct flush_lock_setup_fixture
22-
{
23-
flush_lock_setup_fixture() noexcept
24-
{
25-
BOOST_REQUIRE(test::clear(test::directory));
26-
}
27-
28-
~flush_lock_setup_fixture() noexcept
29-
{
30-
BOOST_REQUIRE(test::clear(test::directory));
31-
}
32-
};
33-
34-
BOOST_FIXTURE_TEST_SUITE(flush_lock_tests, flush_lock_setup_fixture)
21+
BOOST_FIXTURE_TEST_SUITE(flush_lock_tests, test::directory_setup_fixture)
3522

3623
BOOST_AUTO_TEST_CASE(flush_lock__construct__file__expected)
3724
{

test/locks/interprocess_lock.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,7 @@
1818
*/
1919
#include "../test.hpp"
2020

21-
struct interprocess_lock_setup_fixture
22-
{
23-
interprocess_lock_setup_fixture() noexcept
24-
{
25-
BOOST_REQUIRE(test::clear(test::directory));
26-
}
27-
28-
~interprocess_lock_setup_fixture() noexcept
29-
{
30-
BOOST_REQUIRE(test::clear(test::directory));
31-
}
32-
};
33-
34-
BOOST_FIXTURE_TEST_SUITE(interprocess_lock_tests, interprocess_lock_setup_fixture)
21+
BOOST_FIXTURE_TEST_SUITE(interprocess_lock_tests, test::directory_setup_fixture)
3522

3623
BOOST_AUTO_TEST_CASE(interprocess_lock__construct__file__expected)
3724
{

test/memory/map.cpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,7 @@
2222
// error::load_failure, error::flush_failure, error::unload_failure codes, but
2323
// don't want to make this class virtual.
2424

25-
struct map_setup_fixture
26-
{
27-
DELETE_COPY_MOVE(map_setup_fixture);
28-
BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
29-
30-
map_setup_fixture() NOEXCEPT
31-
{
32-
BOOST_REQUIRE(test::clear(test::directory));
33-
}
34-
35-
~map_setup_fixture() NOEXCEPT
36-
{
37-
BOOST_REQUIRE(test::clear(test::directory));
38-
}
39-
40-
BC_POP_WARNING()
41-
};
42-
43-
BOOST_FIXTURE_TEST_SUITE(map_tests, map_setup_fixture)
25+
BOOST_FIXTURE_TEST_SUITE(map_tests, test::directory_setup_fixture)
4426

4527
BOOST_AUTO_TEST_CASE(map__file__always__expected)
4628
{

0 commit comments

Comments
 (0)