aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrian Kummerlaender2016-01-05 21:17:42 +0100
committerAdrian Kummerlaender2016-01-05 21:17:42 +0100
commit1df71e9b78fd516f9902f42db733f0b02808ad50 (patch)
treef6a79cdb5f43ed112a880c47f234203857f6bc40 /src
parent93af7b2094759d1187c5e9ead8eba6cab557ca18 (diff)
downloadInputXSLT-1df71e9b78fd516f9902f42db733f0b02808ad50.tar
InputXSLT-1df71e9b78fd516f9902f42db733f0b02808ad50.tar.gz
InputXSLT-1df71e9b78fd516f9902f42db733f0b02808ad50.tar.bz2
InputXSLT-1df71e9b78fd516f9902f42db733f0b02808ad50.tar.lz
InputXSLT-1df71e9b78fd516f9902f42db733f0b02808ad50.tar.xz
InputXSLT-1df71e9b78fd516f9902f42db733f0b02808ad50.tar.zst
InputXSLT-1df71e9b78fd516f9902f42db733f0b02808ad50.zip
Fix `generate` problem caused by _boost_ update
i.e. the directory tree was not correctly created in all circumstances which led to both the `generate` and `write-file` test cases failing. This was combined with some accumulated changes such as the extraction of process context instantiation.
Diffstat (limited to 'src')
-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() ) {