author | František Kučera <franta-hg@frantovo.cz> |
Mon, 11 Nov 2019 14:42:13 +0100 | |
branch | v_0 |
changeset 28 | 9172bd97ae99 |
parent 27 | 532953173cd5 |
permissions | -rw-r--r-- |
27
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
1 |
/** |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
2 |
* Relational pipes |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
3 |
* Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info) |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
4 |
* |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
5 |
* This program is free software: you can redistribute it and/or modify |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
7 |
* the Free Software Foundation, version 3 of the License. |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
8 |
* |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
13 |
* |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
16 |
*/ |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
17 |
#pragma once |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
18 |
|
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
19 |
#include <vector> |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
20 |
#include <sstream> |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
21 |
#include <fcntl.h> |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
22 |
#include <unistd.h> |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
23 |
#include <sys/wait.h> |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
24 |
#include <ext/stdio_filebuf.h> |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
25 |
|
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
26 |
#include <relpipe/writer/typedefs.h> |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
27 |
#include <relpipe/cli/RelpipeCLIException.h> |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
28 |
|
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
29 |
namespace relpipe { |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
30 |
namespace in { |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
31 |
namespace filesystem { |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
32 |
|
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
33 |
/** |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
34 |
* Simple wrapper for a system process (fork+exec) that captures and returns just the STDOUT. |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
35 |
*/ |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
36 |
class SystemProcess { |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
37 |
private: |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
38 |
/** |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
39 |
* the command + its arguments |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
40 |
*/ |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
41 |
std::vector<std::string> commandLine; |
28
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
42 |
std::vector<std::string> environment; |
27
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
43 |
int nullFile = -1; |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
44 |
|
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
45 |
/** |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
46 |
* TODO: move to a common library (copied from the AWK module) |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
47 |
* @param args |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
48 |
*/ |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
49 |
void execp(const std::vector<std::string>& args) { |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
50 |
const char** a = new const char*[args.size() + 1]; |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
51 |
for (size_t i = 0; i < args.size(); i++) a[i] = args[i].c_str(); |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
52 |
a[args.size()] = nullptr; |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
53 |
|
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
54 |
execvp(a[0], (char*const*) a); |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
55 |
|
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
56 |
delete[] a; |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
57 |
throw relpipe::cli::RelpipeCLIException(L"Unable to do execvp().", relpipe::cli::CLI::EXIT_CODE_UNEXPECTED_ERROR); // TODO: better exception? |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
58 |
} |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
59 |
|
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
60 |
/** |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
61 |
* TODO: move to a common library (copied from the AWK module) |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
62 |
* @param readerFD |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
63 |
* @param writerFD |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
64 |
*/ |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
65 |
void createPipe(int& readerFD, int& writerFD) { |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
66 |
int fds[2]; |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
67 |
int result = pipe(fds); |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
68 |
readerFD = fds[0]; |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
69 |
writerFD = fds[1]; |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
70 |
if (result < 0) throw relpipe::cli::RelpipeCLIException(L"Unable to create a pipe.", relpipe::cli::CLI::EXIT_CODE_UNEXPECTED_ERROR); // TODO: better exception? |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
71 |
} |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
72 |
|
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
73 |
/** |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
74 |
* TODO: move to a common library (copied from the AWK module) |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
75 |
*/ |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
76 |
void redirectFD(int oldfd, int newfd) { |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
77 |
int result = dup2(oldfd, newfd); |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
78 |
if (result < 0) throw relpipe::cli::RelpipeCLIException(L"Unable redirect FD.", relpipe::cli::CLI::EXIT_CODE_UNEXPECTED_ERROR); // TODO: better exception? |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
79 |
} |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
80 |
|
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
81 |
/** |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
82 |
* TODO: move to a common library (copied from the AWK module) |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
83 |
*/ |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
84 |
void closeOrThrow(int fd) { |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
85 |
int error = close(fd); |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
86 |
if (error) throw relpipe::cli::RelpipeCLIException(L"Unable to close FD: " + to_wstring(fd) + L" from PID: " + to_wstring(getpid()), relpipe::cli::CLI::EXIT_CODE_UNEXPECTED_ERROR); // TODO: better exception? |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
87 |
} |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
88 |
|
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
89 |
public: |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
90 |
|
28
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
91 |
SystemProcess(const std::vector<std::string>& commandLine, const std::vector<std::string>& environment = {}) : commandLine(commandLine), environment(environment) { |
27
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
92 |
nullFile = open("/dev/null", O_RDWR); |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
93 |
} |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
94 |
|
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
95 |
virtual ~SystemProcess() { |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
96 |
close(nullFile); |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
97 |
} |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
98 |
|
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
99 |
std::string execute() { |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
100 |
|
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
101 |
std::stringstream result; |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
102 |
|
28
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
103 |
// FIXME: different kinds of exception or return the exit code (now it enters infinite loop if the execp() fails) |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
104 |
// TODO: rename (not specific to hash) |
27
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
105 |
int hashReaderFD; |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
106 |
int hashWriterFD; |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
107 |
createPipe(hashReaderFD, hashWriterFD); |
28
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
108 |
|
27
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
109 |
__pid_t hashPid = fork(); |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
110 |
|
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
111 |
if (hashPid < 0) { |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
112 |
throw relpipe::cli::RelpipeCLIException(L"Unable to fork the hash process.", relpipe::cli::CLI::EXIT_CODE_UNEXPECTED_ERROR); // TODO: better exception? |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
113 |
} else if (hashPid == 0) { |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
114 |
// Child process |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
115 |
closeOrThrow(hashReaderFD); |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
116 |
redirectFD(nullFile, STDIN_FILENO); |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
117 |
redirectFD(nullFile, STDERR_FILENO); |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
118 |
redirectFD(hashWriterFD, STDOUT_FILENO); |
28
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
119 |
for (int i = 0; i < environment.size();) { |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
120 |
std::string name = environment[i++]; |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
121 |
std::string value = environment[i++]; |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
122 |
setenv(name.c_str(), value.c_str(), true); |
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
123 |
} |
27
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
124 |
execp(commandLine); |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
125 |
} else { |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
126 |
// Parent process |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
127 |
closeOrThrow(hashWriterFD); |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
128 |
|
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
129 |
__gnu_cxx::stdio_filebuf<char> hashReaderBuffer(hashReaderFD, std::ios::in); |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
130 |
std::istream hashReader(&hashReaderBuffer); |
28
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
131 |
|
27
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
132 |
for (char ch; hashReader.read(&ch, 1).good();) result.put(ch); |
28
9172bd97ae99
custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
133 |
|
27
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
134 |
int waitError; |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
135 |
__pid_t waitPID = wait(&waitError); |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
136 |
if (waitError) throw relpipe::cli::RelpipeCLIException(L"The child process returned an error exit code.", relpipe::cli::CLI::EXIT_CODE_UNEXPECTED_ERROR); // TODO: better exception? |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
137 |
} |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
138 |
|
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
139 |
return result.str(); |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
140 |
} |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
141 |
}; |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
142 |
|
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
143 |
} |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
144 |
} |
532953173cd5
file hash: md5, sha1, sha256, sha512
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
145 |
} |