| Line |
Branch |
Exec |
Source |
| 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/compression.h" |
| 14 |
|
|
#include "crypto/hash.h" |
| 15 |
|
|
#include "swissknife.h" |
| 16 |
|
|
#include "util/string.h" |
| 17 |
|
|
|
| 18 |
|
|
namespace swissknife { |
| 19 |
|
|
|
| 20 |
|
|
class CommandGraft : public Command { |
| 21 |
|
|
public: |
| 22 |
|
|
static const unsigned kDefaultChunkSize = 24; |
| 23 |
|
|
|
| 24 |
|
✗ |
~CommandGraft() { } |
| 25 |
|
✗ |
virtual std::string GetName() const { return "graft"; } |
| 26 |
|
✗ |
virtual std::string GetDescription() const { |
| 27 |
|
✗ |
return "Creates a graft file for publishing in CVMFS."; |
| 28 |
|
|
} |
| 29 |
|
✗ |
virtual ParameterList GetParams() const { |
| 30 |
|
✗ |
ParameterList r; |
| 31 |
|
✗ |
r.push_back(Parameter::Mandatory('i', "Input file to process " |
| 32 |
|
|
"('-' for reading from stdin)")); |
| 33 |
|
✗ |
r.push_back(Parameter::Optional('o', "Output location for graft file")); |
| 34 |
|
✗ |
r.push_back(Parameter::Switch('v', "Verbose output")); |
| 35 |
|
✗ |
r.push_back(Parameter::Optional('Z', "Compression algorithm " |
| 36 |
|
|
"(default: none)")); |
| 37 |
|
✗ |
r.push_back(Parameter::Optional( |
| 38 |
|
✗ |
'c', "Chunk size (in MB; default: " + StringifyUint(kDefaultChunkSize) |
| 39 |
|
✗ |
+ ")")); |
| 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_ |
| 76 |
|
|
|