CernVM-FS  2.13.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 <cassert>
9 #include <string>
10 
11 #include "crypto/hash.h"
12 #include "ingestion/pipeline.h"
13 #include "swissknife.h"
14 
15 namespace swissknife {
16 
17 class CommandScrub : public Command {
18  public:
19  CommandScrub();
20  ~CommandScrub();
21  virtual std::string GetName() const { return "scrub"; }
22  virtual std::string GetDescription() const {
23  return "CernVM File System repository file storage checker. Finds silent "
24  "disk corruptions by recomputing all file content checksums in the "
25  "backend file storage.";
26  }
27  virtual ParameterList GetParams() const;
28  int Main(const ArgumentList &args);
29 
30 
31  protected:
32  struct Alerts {
33  enum Type {
41  kNumberOfErrorTypes // This should _always_ stay the last entry!
42  };
43 
44  static const char *ToString(const Type t);
45  };
46 
47  void FileCallback(const std::string &relative_path,
48  const std::string &file_name);
49  void DirCallback(const std::string &relative_path,
50  const std::string &dir_name);
51  void SymlinkCallback(const std::string &relative_path,
52  const std::string &symlink_name);
53 
54  void OnFileHashed(const ScrubbingResult &scrubbing_result);
55 
56  void PrintAlert(const Alerts::Type type,
57  const std::string &path,
58  const std::string &affected_hash = "") const;
59  void ShowAlertsHelpMessage() const;
60 
61  private:
62  std::string CheckPathAndExtractHash(const std::string &relative_path,
63  const std::string &file_name,
64  const std::string &full_path) const;
65  bool CheckHashString(const std::string &hash_string,
66  const std::string &full_path) const;
67 
68  std::string MakeFullPath(const std::string &relative_path,
69  const std::string &file_name) const;
70  std::string MakeRelativePath(const std::string &full_path);
71 
73  std::string repo_path_;
75 
76  mutable unsigned int alerts_;
77  mutable pthread_mutex_t alerts_mutex_;
78 };
79 
80 } // namespace swissknife
81 
82 #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