From 1df71e9b78fd516f9902f42db733f0b02808ad50 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Tue, 5 Jan 2016 21:17:42 +0100 Subject: 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. --- src/function/external_command.cc | 41 ++++++++++++++++++++-------------------- src/function/generate.cc | 2 +- src/function/read_directory.cc | 6 +++--- src/function/read_file.cc | 12 ++++++------ src/function/write_file.cc | 4 +++- 5 files changed, 33 insertions(+), 32 deletions(-) (limited to 'src') 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( - "" + rawOutput + "" - ); -} - inline bool isWrappedOutput(const XMLCh* nodeName) { return xercesc::XMLString::equals( nodeName, @@ -42,7 +36,7 @@ std::unique_ptr readOutput( ); } else { return std::make_unique( - wrapOutput(rawOutput) + "" + rawOutput + "" ); } } @@ -67,6 +61,20 @@ boost::optional 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 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 readXmlFile( const boost::filesystem::path& filePath, xercesc::DOMDocument* const domDocument ) { - const xercesc::LocalFileInputSource file( + const xercesc::LocalFileInputSource file{ *InputXSLT::XercesStringGuard(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() ) { -- cgit v1.2.3