1 |
|
|
/** |
2 |
|
|
* This file is part of the CernVM File System. |
3 |
|
|
* |
4 |
|
|
* It assists in creating graft files for publishing in CVMFS. |
5 |
|
|
*/ |
6 |
|
|
|
7 |
|
|
#ifndef CVMFS_SWISSKNIFE_GRAFT_H_ |
8 |
|
|
#define CVMFS_SWISSKNIFE_GRAFT_H_ |
9 |
|
|
|
10 |
|
|
#include <string> |
11 |
|
|
#include <vector> |
12 |
|
|
|
13 |
|
|
#include "compression.h" |
14 |
|
|
#include "hash.h" |
15 |
|
|
|
16 |
|
|
#include "swissknife.h" |
17 |
|
|
#include "util/string.h" |
18 |
|
|
|
19 |
|
|
namespace swissknife { |
20 |
|
|
|
21 |
|
|
class CommandGraft : public Command { |
22 |
|
|
public: |
23 |
|
|
static const unsigned kDefaultChunkSize = 24; |
24 |
|
|
|
25 |
|
|
~CommandGraft() { } |
26 |
|
|
virtual std::string GetName() const { return "graft"; } |
27 |
|
|
virtual std::string GetDescription() const { |
28 |
|
|
return "Creates a graft file for publishing in CVMFS."; |
29 |
|
|
} |
30 |
|
|
virtual ParameterList GetParams() const { |
31 |
|
|
ParameterList r; |
32 |
|
|
r.push_back(Parameter::Mandatory('i', "Input file to process " |
33 |
|
|
"('-' for reading from stdin)")); |
34 |
|
|
r.push_back(Parameter::Optional('o', "Output location for graft file")); |
35 |
|
|
r.push_back(Parameter::Switch('v', "Verbose output")); |
36 |
|
|
r.push_back(Parameter::Optional('Z', "Compression algorithm " |
37 |
|
|
"(default: none)")); |
38 |
|
|
r.push_back(Parameter::Optional('c', "Chunk size (in MB; default: " + |
39 |
|
|
StringifyUint(kDefaultChunkSize) + ")")); |
40 |
|
|
r.push_back(Parameter::Optional('a', "hash algorithm (default: SHA-1)")); |
41 |
|
|
r.push_back(Parameter::Switch('b', "Generate bulk hash for chunked file")); |
42 |
|
|
return r; |
43 |
|
|
} |
44 |
|
|
|
45 |
|
|
int Main(const ArgumentList &args); |
46 |
|
|
|
47 |
|
|
private: |
48 |
|
|
int Publish(const std::string &input_file, const std::string &output_file, |
49 |
|
|
bool output_file_is_dir, bool input_file_is_stdin); |
50 |
|
|
int Recurse(const std::string &input_file, const std::string &output_file); |
51 |
|
|
|
52 |
|
|
void FileCallback(const std::string &relative_path, |
53 |
|
|
const std::string &file_name); |
54 |
|
|
bool DirCallback(const std::string &relative_path, |
55 |
|
|
const std::string &dir_name); |
56 |
|
|
|
57 |
|
|
bool ChecksumFdWithChunks(int fd, |
58 |
|
|
zlib::Compressor *compressor, |
59 |
|
|
uint64_t *file_size, |
60 |
|
|
shash::Any *file_hash, |
61 |
|
|
std::vector<uint64_t> *chunk_offsets, |
62 |
|
|
std::vector<shash::Any> *chunk_checksums); |
63 |
|
|
|
64 |
|
|
std::string output_file_; |
65 |
|
|
std::string input_file_; |
66 |
|
|
bool verbose_; |
67 |
|
|
zlib::Algorithms compression_alg_; |
68 |
|
|
shash::Algorithms hash_alg_; |
69 |
|
|
uint64_t chunk_size_; |
70 |
|
|
bool generate_bulk_hash_; |
71 |
|
|
}; |
72 |
|
|
|
73 |
|
|
} // namespace swissknife |
74 |
|
|
|
75 |
|
|
#endif // CVMFS_SWISSKNIFE_GRAFT_H_ |