1 |
|
|
/** |
2 |
|
|
* This file is part of the CernVM File System. |
3 |
|
|
*/ |
4 |
|
|
|
5 |
|
|
#ifndef CVMFS_RECEIVER_PAYLOAD_PROCESSOR_H_ |
6 |
|
|
#define CVMFS_RECEIVER_PAYLOAD_PROCESSOR_H_ |
7 |
|
|
|
8 |
|
|
#include <stdint.h> |
9 |
|
|
#include <map> |
10 |
|
|
#include <string> |
11 |
|
|
#include <vector> |
12 |
|
|
|
13 |
|
|
#include "pack.h" |
14 |
|
|
#include "upload.h" |
15 |
|
|
#include "util/raii_temp_dir.h" |
16 |
|
|
|
17 |
|
|
namespace receiver { |
18 |
|
|
|
19 |
|
|
struct FileInfo { |
20 |
|
|
FileInfo(); |
21 |
|
|
explicit FileInfo(const ObjectPackBuild::Event& event); |
22 |
|
|
FileInfo(const FileInfo& other); |
23 |
|
|
FileInfo& operator=(const FileInfo& other); |
24 |
|
|
|
25 |
|
|
std::string temp_path; |
26 |
|
|
size_t total_size; |
27 |
|
|
size_t current_size; |
28 |
|
|
shash::ContextPtr hash_context; |
29 |
|
|
std::vector<unsigned char> hash_buffer; |
30 |
|
|
bool skip; |
31 |
|
|
}; |
32 |
|
|
|
33 |
|
|
/** |
34 |
|
|
* This class is used in the `cvmfs_receiver` tool, on repository gateway |
35 |
|
|
* machines. The receiver::Reactor class, implementing the event loop of the |
36 |
|
|
* `cvmfs_receiver` tool, dispatches the handling of the kSubmitPayload events |
37 |
|
|
* to this class. |
38 |
|
|
* |
39 |
|
|
* Its responsibility is reading the payload - containing a serialized |
40 |
|
|
* ObjectPack - from a file descriptor, and unpacking it into the repository. |
41 |
|
|
*/ |
42 |
|
|
class PayloadProcessor { |
43 |
|
|
public: |
44 |
|
|
enum Result { kSuccess, kPathViolation, kSpoolerError, kOtherError }; |
45 |
|
|
|
46 |
|
|
PayloadProcessor(); |
47 |
|
|
virtual ~PayloadProcessor(); |
48 |
|
|
|
49 |
|
|
Result Process(int fdin, const std::string& header_digest, |
50 |
|
|
const std::string& path, uint64_t header_size); |
51 |
|
|
|
52 |
|
|
virtual void ConsumerEventCallback(const ObjectPackBuild::Event& event); |
53 |
|
|
|
54 |
|
|
int GetNumErrors() const { return num_errors_; } |
55 |
|
|
|
56 |
|
|
protected: |
57 |
|
|
// NOTE: These methods are made virtual such that they can be mocked for |
58 |
|
|
// the purpose of unit testing |
59 |
|
|
virtual Result Initialize(); |
60 |
|
|
virtual Result Finalize(); |
61 |
|
|
virtual void Upload(const std::string& source, |
62 |
|
|
const std::string& dest); |
63 |
|
|
virtual bool WriteFile(int fd, const void* const buf, size_t buf_size); |
64 |
|
|
|
65 |
|
|
private: |
66 |
|
|
typedef std::map<shash::Any, FileInfo>::iterator FileIterator; |
67 |
|
|
std::map<shash::Any, FileInfo> pending_files_; |
68 |
|
|
std::string current_repo_; |
69 |
|
|
UniquePtr<upload::Spooler> spooler_; |
70 |
|
|
UniquePtr<RaiiTempDir> temp_dir_; |
71 |
|
|
int num_errors_; |
72 |
|
|
}; |
73 |
|
|
|
74 |
|
|
} // namespace receiver |
75 |
|
|
|
76 |
|
|
#endif // CVMFS_RECEIVER_PAYLOAD_PROCESSOR_H_ |