mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
FileReader: More accurate description of FileReader::readFile() and its arguments
This commit is contained in:
parent
6a41b417a3
commit
0922d60ba6
@ -42,7 +42,7 @@ void FileReader::setSources(StringMap _sources)
|
|||||||
m_sourceCodes = std::move(_sources);
|
m_sourceCodes = std::move(_sources);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReadCallback::Result FileReader::readFile(string const& _kind, string const& _path)
|
ReadCallback::Result FileReader::readFile(string const& _kind, string const& _sourceUnitName)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -51,11 +51,11 @@ ReadCallback::Result FileReader::readFile(string const& _kind, string const& _pa
|
|||||||
"ReadFile callback used as callback kind " +
|
"ReadFile callback used as callback kind " +
|
||||||
_kind
|
_kind
|
||||||
));
|
));
|
||||||
string validPath = _path;
|
string strippedSourceUnitName = _sourceUnitName;
|
||||||
if (validPath.find("file://") == 0)
|
if (strippedSourceUnitName.find("file://") == 0)
|
||||||
validPath.erase(0, 7);
|
strippedSourceUnitName.erase(0, 7);
|
||||||
|
|
||||||
auto canonicalPath = boost::filesystem::weakly_canonical(m_basePath / validPath);
|
auto canonicalPath = boost::filesystem::weakly_canonical(m_basePath / strippedSourceUnitName);
|
||||||
bool isAllowed = false;
|
bool isAllowed = false;
|
||||||
for (auto const& allowedDir: m_allowedDirectories)
|
for (auto const& allowedDir: m_allowedDirectories)
|
||||||
{
|
{
|
||||||
@ -80,7 +80,7 @@ ReadCallback::Result FileReader::readFile(string const& _kind, string const& _pa
|
|||||||
|
|
||||||
// NOTE: we ignore the FileNotFound exception as we manually check above
|
// NOTE: we ignore the FileNotFound exception as we manually check above
|
||||||
auto contents = readFileAsString(canonicalPath.string());
|
auto contents = readFileAsString(canonicalPath.string());
|
||||||
m_sourceCodes[_path] = contents;
|
m_sourceCodes[_sourceUnitName] = contents;
|
||||||
return ReadCallback::Result{true, contents};
|
return ReadCallback::Result{true, contents};
|
||||||
}
|
}
|
||||||
catch (util::Exception const& _exception)
|
catch (util::Exception const& _exception)
|
||||||
|
@ -62,14 +62,21 @@ public:
|
|||||||
SourceCode const& sourceCode(SourceUnitName const& _sourceUnitName) const { return m_sourceCodes.at(_sourceUnitName); }
|
SourceCode const& sourceCode(SourceUnitName const& _sourceUnitName) const { return m_sourceCodes.at(_sourceUnitName); }
|
||||||
|
|
||||||
/// Resets all sources to the given map of source unit ID to source codes.
|
/// Resets all sources to the given map of source unit ID to source codes.
|
||||||
|
/// Does not enforce @a allowedDirectories().
|
||||||
void setSources(StringMap _sources);
|
void setSources(StringMap _sources);
|
||||||
|
|
||||||
/// Adds the source code for a given source unit ID.
|
/// Adds the source code for a given source unit ID.
|
||||||
|
/// Does not enforce @a allowedDirectories().
|
||||||
void setSource(boost::filesystem::path const& _path, SourceCode _source);
|
void setSource(boost::filesystem::path const& _path, SourceCode _source);
|
||||||
|
|
||||||
/// Reads a given file at @p _path of kind @p _kind from the local filesystem and returns the result.
|
/// Receives a @p _sourceUnitName that refers to a source unit in compiler's virtual filesystem
|
||||||
/// @p _kind must always be passed as "source".
|
/// and attempts to interpret it as a path and read the corresponding file from disk.
|
||||||
frontend::ReadCallback::Result readFile(std::string const& _kind, std::string const& _path);
|
/// The read will only succeed if the canonical path of the file is within one of the @a allowedDirectories().
|
||||||
|
/// @param _kind must be equal to "source". Other values are not supported.
|
||||||
|
/// @return Content of the loaded file or an error message. If the operation succeeds, a copy of
|
||||||
|
/// the content is retained in @a sourceCodes() under the key of @a _sourceUnitName. If the key
|
||||||
|
/// already exists, previous content is discarded.
|
||||||
|
frontend::ReadCallback::Result readFile(std::string const& _kind, std::string const& _sourceUnitName);
|
||||||
|
|
||||||
frontend::ReadCallback::Callback reader()
|
frontend::ReadCallback::Callback reader()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user