CernVM-FS  2.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
swissknife_scrub.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_SWISSKNIFE_SCRUB_H_
6 #define CVMFS_SWISSKNIFE_SCRUB_H_
7 
8 #include "swissknife.h"
9 
10 #include <cassert>
11 #include <string>
12 
13 #include "crypto/hash.h"
14 #include "ingestion/pipeline.h"
15 
16 namespace swissknife {
17 
18 class CommandScrub : public Command {
19  public:
20  CommandScrub();
21  ~CommandScrub();
22  virtual std::string GetName() const { return "scrub"; }
23  virtual std::string GetDescription() const {
24  return "CernVM File System repository file storage checker. Finds silent "
25  "disk corruptions by recomputing all file content checksums in the "
26  "backend file storage.";
27  }
28  virtual ParameterList GetParams() const;
29  int Main(const ArgumentList &args);
30 
31 
32  protected:
33  struct Alerts {
34  enum Type {
42  kNumberOfErrorTypes // This should _always_ stay the last entry!
43  };
44 
45  static const char* ToString(const Type t);
46  };
47 
48  void FileCallback(const std::string &relative_path,
49  const std::string &file_name);
50  void DirCallback(const std::string &relative_path,
51  const std::string &dir_name);
52  void SymlinkCallback(const std::string &relative_path,
53  const std::string &symlink_name);
54 
55  void OnFileHashed(const ScrubbingResult &scrubbing_result);
56 
57  void PrintAlert(const Alerts::Type type,
58  const std::string &path,
59  const std::string &affected_hash = "") const;
60  void ShowAlertsHelpMessage() const;
61 
62  private:
63  std::string CheckPathAndExtractHash(const std::string &relative_path,
64  const std::string &file_name,
65  const std::string &full_path) const;
66  bool CheckHashString(const std::string &hash_string,
67  const std::string &full_path) const;
68 
69  std::string MakeFullPath(const std::string &relative_path,
70  const std::string &file_name) const;
71  std::string MakeRelativePath(const std::string &full_path);
72 
74  std::string repo_path_;
76 
77  mutable unsigned int alerts_;
78  mutable pthread_mutex_t alerts_mutex_;
79 };
80 
81 } // namespace swissknife
82 
83 #endif // CVMFS_SWISSKNIFE_SCRUB_H_
void FileCallback(const std::string &relative_path, const std::string &file_name)
void DirCallback(const std::string &relative_path, const std::string &dir_name)
virtual std::string GetName() const
std::vector< Parameter > ParameterList
Definition: swissknife.h:71
virtual ParameterList GetParams() const
void OnFileHashed(const ScrubbingResult &scrubbing_result)
bool CheckHashString(const std::string &hash_string, const std::string &full_path) const
void SymlinkCallback(const std::string &relative_path, const std::string &symlink_name)
std::string MakeFullPath(const std::string &relative_path, const std::string &file_name) const
void PrintAlert(const Alerts::Type type, const std::string &path, const std::string &affected_hash="") const
std::string MakeRelativePath(const std::string &full_path)
ScrubbingPipeline pipeline_scrubbing_
virtual std::string GetDescription() const
pthread_mutex_t alerts_mutex_
std::string CheckPathAndExtractHash(const std::string &relative_path, const std::string &file_name, const std::string &full_path) const
std::map< char, SharedPtr< std::string > > ArgumentList
Definition: swissknife.h:72
static const char * ToString(const Type t)
int Main(const ArgumentList &args)
void ShowAlertsHelpMessage() const