readFileAsString(): Accept path as boost::filesystem::path instead of string

This commit is contained in:
Kamil Śliwak
2021-08-17 12:58:33 +02:00
parent 790d08f24b
commit cb1a0f08ca
9 changed files with 25 additions and 27 deletions
+5 -6
View File
@@ -421,7 +421,7 @@ bool SourceUpgrade::readInputFiles()
if (m_args.count(g_argInputFile))
for (string path: m_args[g_argInputFile].as<vector<string>>())
{
auto infile = boost::filesystem::path(path);
boost::filesystem::path infile = path;
if (!boost::filesystem::exists(infile))
{
if (!ignoreMissing)
@@ -448,8 +448,7 @@ bool SourceUpgrade::readInputFiles()
continue;
}
m_sourceCodes[infile.generic_string()] = readFileAsString(infile.string());
path = boost::filesystem::canonical(infile).string();
m_sourceCodes[infile.generic_string()] = readFileAsString(infile);
}
if (m_sourceCodes.size() == 0)
@@ -484,8 +483,8 @@ ReadCallback::Callback SourceUpgrade::fileReader()
{
try
{
auto path = boost::filesystem::path(_path);
auto canonicalPath = boost::filesystem::weakly_canonical(path);
boost::filesystem::path path = _path;
boost::filesystem::path canonicalPath = boost::filesystem::weakly_canonical(path);
bool isAllowed = false;
for (auto const& allowedDir: m_allowedDirectories)
{
@@ -508,7 +507,7 @@ ReadCallback::Callback SourceUpgrade::fileReader()
if (!boost::filesystem::is_regular_file(canonicalPath))
return ReadCallback::Result{false, "Not a valid file."};
auto contents = readFileAsString(canonicalPath.string());
string contents = readFileAsString(canonicalPath);
m_sourceCodes[path.generic_string()] = contents;
return ReadCallback::Result{true, contents};
}
+3 -5
View File
@@ -35,8 +35,6 @@
#include <libsolutil/CommonData.h>
#include <libsolutil/CommonIO.h>
#include <boost/filesystem.hpp>
#include <iostream>
using namespace std;
@@ -405,12 +403,12 @@ vector<Program> ProgramFactory::build(Options const& _options)
return inputPrograms;
}
CharStream ProgramFactory::loadSource(string const& _sourcePath)
CharStream ProgramFactory::loadSource(boost::filesystem::path const& _sourcePath)
{
assertThrow(boost::filesystem::exists(_sourcePath), MissingFile, "Source file does not exist: " + _sourcePath);
assertThrow(boost::filesystem::exists(_sourcePath), MissingFile, "Source file does not exist: " + _sourcePath.string());
string sourceCode = readFileAsString(_sourcePath);
return CharStream(sourceCode, _sourcePath);
return CharStream(sourceCode, _sourcePath.string());
}
void Phaser::main(int _argc, char** _argv)
+2 -1
View File
@@ -25,6 +25,7 @@
#include <tools/yulPhaser/AlgorithmRunner.h>
#include <tools/yulPhaser/GeneticAlgorithms.h>
#include <boost/filesystem.hpp>
#include <boost/program_options.hpp>
#include <cstddef>
@@ -242,7 +243,7 @@ public:
static std::vector<Program> build(Options const& _options);
private:
static langutil::CharStream loadSource(std::string const& _sourcePath);
static langutil::CharStream loadSource(boost::filesystem::path const& _sourcePath);
};
/**