File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55#include < memory>
66#include < algorithm>
77
8+ // Define the custom deleter
9+ struct PcloseDeleter {
10+ void operator ()(FILE* f) const {
11+ if (f) pclose (f);
12+ }
13+ };
14+
815std::string get_md5sum (const std::string& filename)
916{
17+ // Check if md5sum is available on the system
18+ if (std::system (" which md5sum > /dev/null 2>&1" ) != 0 ) {
19+ throw std::runtime_error (" md5sum command not found. Please ensure it is installed and in your PATH." );
20+ }
21+
1022 // Command to execute: md5sum <filename>
1123 std::string command = " md5sum " + filename;
1224 std::array<char , 128 > buffer;
1325 std::string result = " " ;
1426
1527 // Use popen to execute the command and read its output
1628 // "r" mode opens the pipe for reading
17- std::unique_ptr<FILE, decltype (&pclose)>
18- pipe (popen (command.c_str (), " r" ), pclose);
29+ std::unique_ptr<FILE, PcloseDeleter> pipe (popen (command.c_str (), " r" ));
1930 if (!pipe) {
2031 throw std::runtime_error (" popen() failed!" );
2132 }
You can’t perform that action at this time.
0 commit comments