aboutsummaryrefslogtreecommitdiff
path: root/src/function
diff options
context:
space:
mode:
Diffstat (limited to 'src/function')
-rw-r--r--src/function/external_command.cc41
-rw-r--r--src/function/generate.cc2
-rw-r--r--src/function/read_directory.cc6
-rw-r--r--src/function/read_file.cc12
-rw-r--r--src/function/write_file.cc4
5 files changed, 33 insertions, 32 deletions
diff --git a/src/function/external_command.cc b/src/function/external_command.cc
index 606ff8f..dda403e 100644
--- a/src/function/external_command.cc
+++ b/src/function/external_command.cc
@@ -16,12 +16,6 @@ namespace {
using InputXSLT::XercesStringGuard;
-inline std::string wrapOutput(const std::string& rawOutput) {
- return std::string(
- "<inputxslt_wrapper>" + rawOutput + "</inputxslt_wrapper>"
- );
-}
-
inline bool isWrappedOutput(const XMLCh* nodeName) {
return xercesc::XMLString::equals(
nodeName,
@@ -42,7 +36,7 @@ std::unique_ptr<std::stringstream> readOutput(
);
} else {
return std::make_unique<std::stringstream>(
- wrapOutput(rawOutput)
+ "<inputxslt_wrapper>" + rawOutput + "</inputxslt_wrapper>"
);
}
}
@@ -67,6 +61,20 @@ boost::optional<xercesc::DOMNode*> importDocumentElement(
}
}
+boost::process::context createContext(
+ const InputXSLT::FilesystemContext& fsContext) {
+ boost::process::context context;
+
+ context.environment = boost::process::self::get_environment();
+ context.stdout_behavior = boost::process::capture_stream();
+ context.stdin_behavior = boost::process::capture_stream();
+ context.work_directory = boost::filesystem::canonical(
+ fsContext.getBase().parent_path()
+ ).string();
+
+ return context;
+}
+
}
namespace InputXSLT {
@@ -76,21 +84,13 @@ DomDocumentCache::document_ptr FunctionExternalCommand::constructDocument(
std::string command,
boost::optional<std::string> input
) const {
- DomDocumentCache::document_ptr domDocument(
+ DomDocumentCache::document_ptr domDocument{
DomDocumentCache::createDocument("content")
- );
-
- boost::process::context context;
- context.environment = boost::process::self::get_environment();
- context.stdout_behavior = boost::process::capture_stream();
- context.stdin_behavior = boost::process::capture_stream();
- context.work_directory = boost::filesystem::canonical(
- fsContext.getBase().parent_path()
- ).string();
+ };
- boost::process::child commandProcess(
- boost::process::launch_shell(command, context)
- );
+ boost::process::child commandProcess{
+ boost::process::launch_shell(command, createContext(fsContext))
+ };
if ( input ) {
boost::process::postream& inputStream = commandProcess.get_stdin();
@@ -140,7 +140,6 @@ DomDocumentCache::document_ptr FunctionExternalCommand::constructDocument(
result.setAttribute("result", "error");
}
-
return domDocument;
}
diff --git a/src/function/generate.cc b/src/function/generate.cc
index b93c2f1..5cd5781 100644
--- a/src/function/generate.cc
+++ b/src/function/generate.cc
@@ -33,7 +33,7 @@ DomDocumentCache::document_ptr FunctionGenerate::constructDocument(
result.setAttribute("path", (*targetPath).string());
boost::filesystem::create_directories(
- (*targetPath).parent_path()
+ boost::filesystem::absolute(*targetPath).parent_path()
);
boost::filesystem::ofstream file(*targetPath);
diff --git a/src/function/read_directory.cc b/src/function/read_directory.cc
index d630e5d..9dfc211 100644
--- a/src/function/read_directory.cc
+++ b/src/function/read_directory.cc
@@ -9,11 +9,11 @@ DomDocumentCache::document_ptr FunctionReadDirectory::constructDocument(
const FilesystemContext&,
boost::filesystem::path directoryPath
) const {
- DomDocumentCache::document_ptr domDocument(
+ DomDocumentCache::document_ptr domDocument{
DomDocumentCache::createDocument("content")
- );
+ };
- ResultNodeFacade result(domDocument.get(), "directory");
+ ResultNodeFacade result{domDocument.get(), "directory"};
result.setAttribute("path", directoryPath.string());
if ( boost::filesystem::is_directory(directoryPath) ) {
diff --git a/src/function/read_file.cc b/src/function/read_file.cc
index 8216034..96fa0ff 100644
--- a/src/function/read_file.cc
+++ b/src/function/read_file.cc
@@ -12,17 +12,17 @@
namespace {
inline bool isXmlFile(const boost::filesystem::path& filePath) {
- return filePath.extension() == ".xml" ||
- filePath.extension() == ".xsl";
+ return filePath.extension() == ".xml"
+ || filePath.extension() == ".xsl";
}
boost::optional<xercesc::DOMNode*> readXmlFile(
const boost::filesystem::path& filePath,
xercesc::DOMDocument* const domDocument
) {
- const xercesc::LocalFileInputSource file(
+ const xercesc::LocalFileInputSource file{
*InputXSLT::XercesStringGuard<XMLCh>(filePath.string())
- );
+ };
xercesc::XercesDOMParser parser;
parser.setDoNamespaces(true);
@@ -79,8 +79,8 @@ DomDocumentCache::document_ptr FunctionReadFile::constructDocument(
if ( auto importedNode = readXmlFile(
filePath,
- domDocument.get())
- ) {
+ domDocument.get()
+ ) ) {
result.setContent(*importedNode);
result.setAttribute("result", "success");
diff --git a/src/function/write_file.cc b/src/function/write_file.cc
index db9eea5..c402d84 100644
--- a/src/function/write_file.cc
+++ b/src/function/write_file.cc
@@ -24,7 +24,9 @@ bool serializeNodeToFile(
if ( contentType != xalan::XalanNode::DOCUMENT_NODE &&
contentType != xalan::XalanNode::ATTRIBUTE_NODE ) {
- boost::filesystem::create_directories(filePath.parent_path());
+ boost::filesystem::create_directories(
+ boost::filesystem::absolute(filePath).parent_path()
+ );
boost::filesystem::ofstream file(filePath);
if ( file.is_open() ) {