CernVM-FS  2.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
swissknife_graft.h
Go to the documentation of this file.
1 
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 
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: " +
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_;
69  uint64_t chunk_size_;
71 };
72 
73 } // namespace swissknife
74 
75 #endif // CVMFS_SWISSKNIFE_GRAFT_H_
static Parameter Optional(const char key, const std::string &desc)
Definition: swissknife.h:41
int Main(const ArgumentList &args)
static const unsigned kDefaultChunkSize
static Parameter Switch(const char key, const std::string &desc)
Definition: swissknife.h:44
virtual std::string GetName() const
std::vector< Parameter > ParameterList
Definition: swissknife.h:71
int Publish(const std::string &input_file, const std::string &output_file, bool output_file_is_dir, bool input_file_is_stdin)
std::string StringifyUint(const uint64_t value)
Definition: string.cc:84
virtual std::string GetDescription() const
bool DirCallback(const std::string &relative_path, const std::string &dir_name)
Algorithms
Definition: hash.h:39
Algorithms
Definition: compression.h:44
static Parameter Mandatory(const char key, const std::string &desc)
Definition: swissknife.h:38
void FileCallback(const std::string &relative_path, const std::string &file_name)
zlib::Algorithms compression_alg_
shash::Algorithms hash_alg_
int Recurse(const std::string &input_file, const std::string &output_file)
std::map< char, SharedPtr< std::string > > ArgumentList
Definition: swissknife.h:72
virtual ParameterList GetParams() const
bool ChecksumFdWithChunks(int fd, zlib::Compressor *compressor, uint64_t *file_size, shash::Any *file_hash, std::vector< uint64_t > *chunk_offsets, std::vector< shash::Any > *chunk_checksums)