Skip to content

Commit 9dc7bc2

Browse files
committed
Switch to utf8 filesystem handling using boost::nowide.
1 parent 9251440 commit 9dc7bc2

8 files changed

Lines changed: 17 additions & 7 deletions

File tree

src/bazel/test/test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ int main(int argc, char *argv[])
99
return 1;
1010

1111
std::string f, s;
12-
std::ifstream ifile(argv[1]);
12+
std::ifstream ifile(argv[1]);
1313
while (std::getline(ifile, s))
1414
f += s + "\n";
1515

src/client/fix_imports.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <printers/cmake.h>
2424

2525
#include <boost/algorithm/string.hpp>
26+
#include <boost/nowide/fstream.hpp>
2627

2728
#include <deque>
2829
#include <iostream>
@@ -58,7 +59,7 @@ void fix_imports(const String &target, const path &aliases_file, const path &old
5859

5960
if (!new_file.parent_path().empty())
6061
fs::create_directories(new_file.parent_path());
61-
std::ofstream ofile(new_file.string());
62+
boost::nowide::ofstream ofile(new_file.string());
6263
if (!ofile)
6364
throw std::runtime_error("Cannot open the output file for writing");
6465

src/client/main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ void command_init(const Strings &args);
6565
int main(int argc, char *argv[])
6666
try
6767
{
68+
// library initializations
69+
setup_utf8_filesystem();
70+
71+
//
6872
Strings args;
6973
for (auto i = 0; i < argc; i++)
7074
args.push_back(argv[i]);

src/common/database.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
#include <boost/algorithm/string.hpp>
3636
#include <boost/date_time/posix_time/posix_time.hpp>
37+
#include <boost/nowide/fstream.hpp>
3738
#include <sqlite3.h>
3839

3940
#include <primitives/log.h>
@@ -1009,7 +1010,7 @@ void PackagesDatabase::load(bool drop)
10091010
throw std::runtime_error(sqlite3_errmsg(mdb));
10101011

10111012
auto fn = db_repo_dir / (td.name + ".csv");
1012-
std::ifstream ifile(fn.string());
1013+
boost::nowide::ifstream ifile(fn.string());
10131014
if (!ifile)
10141015
throw std::runtime_error("Cannot open file " + fn.string() + " for reading");
10151016

src/common/package.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
#include "lock.h"
2424

2525
#include <boost/algorithm/string.hpp>
26+
#include <boost/nowide/fstream.hpp>
2627

27-
#include <iostream>
2828
#include <regex>
2929

3030
#include <primitives/log.h>
@@ -57,7 +57,7 @@ path Package::getStampFilename() const
5757
String Package::getStampHash() const
5858
{
5959
String hash;
60-
std::ifstream ifile(getStampFilename().string());
60+
boost::nowide::ifstream ifile(getStampFilename().string());
6161
if (ifile)
6262
ifile >> hash;
6363
return hash;

src/common/project.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <exceptions.h>
2727

2828
#include <boost/algorithm/string.hpp>
29+
#include <boost/nowide/fstream.hpp>
2930

3031
#include <primitives/command.h>
3132
#include <primitives/pack.h>
@@ -189,7 +190,7 @@ void check_file_types(const Files &files)
189190
throw std::runtime_error("Project sources did not pass file checks:\n" + errors);
190191

191192
auto fn = get_temp_filename();
192-
std::ofstream o(fn.string(), std::ios::binary | std::ios::out);
193+
boost::nowide::ofstream o(fn.string(), std::ios::binary | std::ios::out);
193194
if (!o)
194195
throw std::runtime_error("Cannot open file for writing: " + fn.string());
195196
for (auto &file : files)

src/common/settings.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "stamp.h"
2727

2828
#include <boost/algorithm/string.hpp>
29+
#include <boost/nowide/fstream.hpp>
2930

3031
#include <primitives/hasher.h>
3132
#include <primitives/templates.h>
@@ -504,7 +505,7 @@ void Settings::clear_local_settings()
504505

505506
void Settings::save(const path &p) const
506507
{
507-
std::ofstream o(p.string());
508+
boost::nowide::ofstream o(p.string());
508509
if (!o)
509510
throw std::runtime_error("Cannot open file: " + p.string());
510511
yaml root;

src/support/filesystem.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
#include <primitives/filesystem.h>
2020

21+
#include <unordered_map>
22+
2123
#define STAMPS_DIR "stamps"
2224
#define STORAGE_DIR "storage"
2325
#define CPPAN_FILENAME "cppan.yml"

0 commit comments

Comments
 (0)