From de947250a9009b3f5de8999a54e8e4c986441fd6 Mon Sep 17 00:00:00 2001 From: Lambourl Date: Fri, 5 Sep 2025 11:57:38 +0200 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=94=A7=20add=20from=5Fstring=20overlo?= =?UTF-8?q?ads=20with=20permissions=20support?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added two new from_string overloads to allow writing file contents while setting explicit boost::filesystem::perms - Ensures callers can both write file content and control file permissions in one operation. - Maintains consistency with existing from_string API by providing both error-code and exception-throwing variants. --- pre/file/string.hpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pre/file/string.hpp b/pre/file/string.hpp index c19e65e..05fd7b0 100644 --- a/pre/file/string.hpp +++ b/pre/file/string.hpp @@ -91,4 +91,16 @@ namespace pre::file { } } + inline void from_string(const std::string &path, const std::string &content, std::error_condition &ec,const boost::filesystem::perms& perms) { + from_string(path, content, ec); + boost::filesystem::permissions(path, perms); + } + + inline void from_string(const std::string &path, const std::string &content, const boost::filesystem::perms& perms) { + from_string(path, content); + boost::filesystem::permissions(path, perms); + } + + + } From 5c434e2403aea73710653172b3285ebe823d36d2 Mon Sep 17 00:00:00 2001 From: Lambourl Date: Mon, 8 Sep 2025 16:21:08 +0200 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=94=A7=20handle=20error=20in=20case?= =?UTF-8?q?=20of=20user=20can=20not=20change=20the=20file=20permission?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pre/file/string.hpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pre/file/string.hpp b/pre/file/string.hpp index 05fd7b0..6b7567f 100644 --- a/pre/file/string.hpp +++ b/pre/file/string.hpp @@ -91,14 +91,19 @@ namespace pre::file { } } - inline void from_string(const std::string &path, const std::string &content, std::error_condition &ec,const boost::filesystem::perms& perms) { + inline void from_string(const std::string &path, const std::string &content, std::error_condition &ec,const boost::filesystem::perms& perms, boost::system::error_code& ec_perms) { from_string(path, content, ec); - boost::filesystem::permissions(path, perms); + boost::filesystem::permissions(path, perms, ec_perms); } inline void from_string(const std::string &path, const std::string &content, const boost::filesystem::perms& perms) { + boost::system::error_code ec_perms; from_string(path, content); - boost::filesystem::permissions(path, perms); + boost::filesystem::permissions(path, perms, ec_perms); + + if (ec_perms) { + throw std::runtime_error("Changing permission of file "s + path + " error "s + ec_perms.message()); + } } From 596e1613b2ef065fcf370b69053d13a10706a021 Mon Sep 17 00:00:00 2001 From: Lambourl Date: Thu, 11 Sep 2025 13:36:34 +0200 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=94=A7=20handle=20error=20with=20the?= =?UTF-8?q?=20same=20type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - return earlier in case of write error --- pre/file/string.hpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pre/file/string.hpp b/pre/file/string.hpp index 6b7567f..7400720 100644 --- a/pre/file/string.hpp +++ b/pre/file/string.hpp @@ -91,9 +91,14 @@ namespace pre::file { } } - inline void from_string(const std::string &path, const std::string &content, std::error_condition &ec,const boost::filesystem::perms& perms, boost::system::error_code& ec_perms) { + inline void from_string(const std::string &path, const std::string &content, std::error_condition &ec,const boost::filesystem::perms& perms) { from_string(path, content, ec); + if (ec){return;} + boost::system::error_code ec_perms{}; boost::filesystem::permissions(path, perms, ec_perms); + if(ec_perms){ + ec = std::error_condition{ec_perms.value(), ec_perms.category()}; + } } inline void from_string(const std::string &path, const std::string &content, const boost::filesystem::perms& perms) {