Branch data Line data Source code
1 : : // ***************************************************************************** 2 : : /*! 3 : : \file src/Base/ProcessControl.cpp 4 : : \copyright 2012-2015 J. Bakosi, 5 : : 2016-2018 Los Alamos National Security, LLC., 6 : : 2019-2021 Triad National Security, LLC. 7 : : All rights reserved. See the LICENSE file for details. 8 : : \brief POSIX process control wrapper definitions 9 : : \details POSIX process control wrapper definitions. 10 : : */ 11 : : // ***************************************************************************** 12 : : 13 : : #include <string> 14 : : #include <vector> 15 : : #include <istream> 16 : : #include <type_traits> 17 : : 18 : : #include "NoWarning/pstream.hpp" 19 : : 20 : : #include "ProcessControl.hpp" 21 : : #include "Exception.hpp" 22 : : 23 : : namespace tk { 24 : : 25 : : // ***************************************************************************** 26 : : // Remove file from file system 27 : : //! \param[in] file File name to delete (shell wildcards NOT expanded) 28 : : //! \details Since we use pstream's basic_ipstream constructor with signature 29 : : //! ( const std::string & file, const argv_type & argv, pmode mode = pstdout ) 30 : : //! and the file argument doesn't contain a slash, the actions of the shell 31 : : //! are duplicated in searching for an executable in PATH. The shell will not 32 : : //! interpret the other arguments, so wildcard expansion will not take place. 33 : : // ***************************************************************************** 34 [ + - ]: 5 : void rm( const std::string& file ) { 35 : 5 : std::vector< std::string > argv; 36 [ + - ]: 5 : argv.push_back( "rm" ); 37 [ + - ]: 5 : argv.push_back( file ); 38 [ + - ][ + - ]: 15 : redi::ipstream in( "rm", argv, redi::pstreambuf::pstderr ); 39 : : std::string e; 40 : : std::string error; 41 [ + - ][ + + ]: 7 : while ( std::getline( in, e ) ) error += e + '\n'; [ + - ][ - + ] 42 [ + + ][ + - ]: 6 : if (!error.empty()) Throw( std::move(error) ); [ + - ][ - + ] [ - - ] 43 : 4 : } 44 : : 45 : : } // tk::