From 3de0b8b7f002bdc76e629f89df73523b36a169f5 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 27 Jun 2018 18:08:49 +0200 Subject: Move absolutePath/sanitizePath helpers from CompilerStack to libdevcore --- libdevcore/CommonIO.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'libdevcore/CommonIO.cpp') diff --git a/libdevcore/CommonIO.cpp b/libdevcore/CommonIO.cpp index 0063a8d4..9693d02a 100644 --- a/libdevcore/CommonIO.cpp +++ b/libdevcore/CommonIO.cpp @@ -187,3 +187,23 @@ boost::filesystem::path dev::weaklyCanonicalFilesystemPath(boost::filesystem::pa return head / tail; } } + +string dev::absolutePath(string const& _path, string const& _reference) +{ + boost::filesystem::path p(_path); + // Anything that does not start with `.` is an absolute path. + if (p.begin() == p.end() || (*p.begin() != "." && *p.begin() != "..")) + return _path; + boost::filesystem::path result(_reference); + result.remove_filename(); + for (boost::filesystem::path::iterator it = p.begin(); it != p.end(); ++it) + if (*it == "..") + result = result.parent_path(); + else if (*it != ".") + result /= *it; + return result.generic_string(); +} + +string dev::sanitizePath(string const& _path) { + return boost::filesystem::path(_path).generic_string(); +} -- cgit v1.2.3 From 6c3d12d85bc7977817e8dc1c5bd0af4b29406b58 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 9 Oct 2018 19:06:22 +0100 Subject: Do not require ctype/stdio if not needed --- libdevcore/CommonIO.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'libdevcore/CommonIO.cpp') diff --git a/libdevcore/CommonIO.cpp b/libdevcore/CommonIO.cpp index 9693d02a..2005d087 100644 --- a/libdevcore/CommonIO.cpp +++ b/libdevcore/CommonIO.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #if defined(_WIN32) #include #else -- cgit v1.2.3 From 56bbfce6d36befbe89256035a333d9b47b360e0d Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 4 Oct 2018 14:55:32 +0200 Subject: Fix directory creation. --- libdevcore/CommonIO.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdevcore/CommonIO.cpp') diff --git a/libdevcore/CommonIO.cpp b/libdevcore/CommonIO.cpp index 2005d087..1aa3504c 100644 --- a/libdevcore/CommonIO.cpp +++ b/libdevcore/CommonIO.cpp @@ -94,7 +94,7 @@ void dev::writeFile(std::string const& _file, bytesConstRef _data, bool _writeDe { // create directory if not existent fs::path p(_file); - if (!fs::exists(p.parent_path())) + if (!p.parent_path().empty() && !fs::exists(p.parent_path())) { fs::create_directories(p.parent_path()); try -- cgit v1.2.3 From 0690aae09d1591b65d6808e6c6c547b63ddb3ce9 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 18 Oct 2018 00:48:07 +0200 Subject: Remove mostly unused writeFile implementation. --- libdevcore/CommonIO.cpp | 39 --------------------------------------- 1 file changed, 39 deletions(-) (limited to 'libdevcore/CommonIO.cpp') diff --git a/libdevcore/CommonIO.cpp b/libdevcore/CommonIO.cpp index 1aa3504c..cc730575 100644 --- a/libdevcore/CommonIO.cpp +++ b/libdevcore/CommonIO.cpp @@ -80,45 +80,6 @@ string dev::readStandardInput() return ret; } -void dev::writeFile(std::string const& _file, bytesConstRef _data, bool _writeDeleteRename) -{ - namespace fs = boost::filesystem; - if (_writeDeleteRename) - { - fs::path tempPath = fs::unique_path(_file + "-%%%%%%"); - writeFile(tempPath.string(), _data, false); - // will delete _file if it exists - fs::rename(tempPath, _file); - } - else - { - // create directory if not existent - fs::path p(_file); - if (!p.parent_path().empty() && !fs::exists(p.parent_path())) - { - fs::create_directories(p.parent_path()); - try - { - fs::permissions(p.parent_path(), fs::owner_all); - } - catch (...) - { - } - } - - ofstream s(_file, ios::trunc | ios::binary); - s.write(reinterpret_cast(_data.data()), _data.size()); - assertThrow(s, FileError, "Could not write to file: " + _file); - try - { - fs::permissions(_file, fs::owner_read|fs::owner_write); - } - catch (...) - { - } - } -} - #if defined(_WIN32) class DisableConsoleBuffering { -- cgit v1.2.3