Line |
Branch |
Exec |
Source |
1 |
|
|
/** |
2 |
|
|
* This file is part of the CernVM File System. |
3 |
|
|
*/ |
4 |
|
|
|
5 |
|
|
#ifndef CVMFS_SWISSKNIFE_INGESTSQL_H_ |
6 |
|
|
#define CVMFS_SWISSKNIFE_INGESTSQL_H_ |
7 |
|
|
|
8 |
|
|
#include <string> |
9 |
|
|
#include <utility> |
10 |
|
|
#include <map> |
11 |
|
|
#include <vector> |
12 |
|
|
|
13 |
|
|
#include "catalog_mgr_rw.h" |
14 |
|
|
#include "swissknife.h" |
15 |
|
|
|
16 |
|
|
namespace swissknife { |
17 |
|
|
class IngestSQL : public Command { |
18 |
|
|
public: |
19 |
|
✗ |
~IngestSQL() {} |
20 |
|
✗ |
virtual string GetName() const { return "ingestsql"; } |
21 |
|
✗ |
virtual string GetDescription() const { |
22 |
|
✗ |
return "Graft the contents of a SQLite DB to the repository"; |
23 |
|
|
} |
24 |
|
✗ |
virtual ParameterList GetParams() const { |
25 |
|
✗ |
ParameterList r; |
26 |
|
|
|
27 |
|
✗ |
r.push_back(Parameter::Mandatory('D', "input sqlite DB")); |
28 |
|
✗ |
r.push_back(Parameter::Mandatory('N', "fully qualified repository name")); |
29 |
|
✗ |
r.push_back(Parameter::Optional('g', "gateway URL")); |
30 |
|
✗ |
r.push_back(Parameter::Optional('w', "stratum 0 base url")); |
31 |
|
✗ |
r.push_back(Parameter::Optional( |
32 |
|
|
't', "temporary directory (will try TMPDIR if not set)")); |
33 |
|
✗ |
r.push_back(Parameter::Optional('@', "proxy URL")); |
34 |
|
✗ |
r.push_back(Parameter::Optional('k', "public key")); |
35 |
|
✗ |
r.push_back(Parameter::Optional('l', "lease path")); |
36 |
|
✗ |
r.push_back(Parameter::Optional('p', "prefix to add to lease and all graft files")); |
37 |
|
✗ |
r.push_back(Parameter::Optional('q', "number of concurrent write jobs")); |
38 |
|
✗ |
r.push_back(Parameter::Optional('s', "gateway secret")); |
39 |
|
✗ |
r.push_back(Parameter::Optional('3', "s3 config")); |
40 |
|
✗ |
r.push_back(Parameter::Switch( |
41 |
|
|
'a', "Allow additions (default true, false if -d specified)")); |
42 |
|
✗ |
r.push_back(Parameter::Switch('d', "Allow deletions")); |
43 |
|
✗ |
r.push_back(Parameter::Switch('x', "Force deletion of any lease")); |
44 |
|
✗ |
r.push_back(Parameter::Switch('c', "Enable corefile generation (requires ulimit -c >0)")); |
45 |
|
✗ |
r.push_back(Parameter::Optional('n', "create empty database file")); |
46 |
|
✗ |
r.push_back(Parameter::Optional('C', "config prefix, default /etc/cvmfs/gateway-client/")); |
47 |
|
✗ |
r.push_back(Parameter::Optional('B', "mount point to block on pending visibility of update")); |
48 |
|
✗ |
r.push_back(Parameter::Optional('T', "reset TTL in sec")); |
49 |
|
✗ |
r.push_back(Parameter::Switch('z', "Create missing nested catalogs")); |
50 |
|
✗ |
r.push_back(Parameter::Optional('r', "lease retry interval")); |
51 |
|
✗ |
r.push_back(Parameter::Switch('Z', "check and set completed_graft property")); |
52 |
|
✗ |
r.push_back(Parameter::Optional('P', "priority for graft (integer)")); |
53 |
|
✗ |
r.push_back(Parameter::Switch('v', "Enable verbose logging")); |
54 |
|
|
|
55 |
|
✗ |
return r; |
56 |
|
|
} |
57 |
|
|
int Main(const ArgumentList &args); |
58 |
|
|
|
59 |
|
|
struct Directory { |
60 |
|
|
std::string name; |
61 |
|
|
time_t mtime; |
62 |
|
|
mode_t mode; |
63 |
|
|
uid_t owner; |
64 |
|
|
gid_t grp; |
65 |
|
|
int nested; |
66 |
|
|
XattrList xattr; |
67 |
|
|
Directory() {} |
68 |
|
✗ |
Directory(const std::string &name, time_t mtime, mode_t mode, uid_t owner, gid_t grp, int nested) : |
69 |
|
✗ |
name(name), mtime(mtime), mode(mode), owner(owner), grp(grp), nested(nested) |
70 |
|
|
{} |
71 |
|
|
}; |
72 |
|
|
|
73 |
|
|
struct Symlink { |
74 |
|
|
std::string name; |
75 |
|
|
std::string target; |
76 |
|
|
time_t mtime; |
77 |
|
|
uid_t owner; |
78 |
|
|
gid_t grp; |
79 |
|
|
int skip_if_file_or_dir; |
80 |
|
✗ |
Symlink(std::string &&name, std::string &&target, time_t mtime, uid_t owner, gid_t grp, int skip_if_file_or_dir) : |
81 |
|
✗ |
name(std::move(name)), target(std::move(target)), mtime(mtime), owner(owner), grp(grp), skip_if_file_or_dir(skip_if_file_or_dir) |
82 |
|
|
{} |
83 |
|
|
}; |
84 |
|
|
|
85 |
|
|
struct File { |
86 |
|
|
std::string name; |
87 |
|
|
time_t mtime; |
88 |
|
|
size_t size; |
89 |
|
|
uid_t owner; |
90 |
|
|
gid_t grp; |
91 |
|
|
mode_t mode; |
92 |
|
|
int internal; |
93 |
|
|
FileChunkList chunks; |
94 |
|
|
int compressed; |
95 |
|
|
|
96 |
|
✗ |
File(std::string &&name, time_t mtime, size_t size, uid_t owner, gid_t grp, mode_t mode, int internal, int compressed) : |
97 |
|
✗ |
name(std::move(name)), mtime(mtime), size(size), owner(owner), grp(grp), mode(mode), internal(internal), compressed(compressed) |
98 |
|
|
{} |
99 |
|
|
}; |
100 |
|
|
|
101 |
|
|
typedef std::map<std::string, Directory> DirMap; |
102 |
|
|
typedef std::map<std::string, std::vector<File>> FileMap; |
103 |
|
|
typedef std::map<std::string, std::vector<Symlink>> SymlinkMap; |
104 |
|
|
|
105 |
|
|
private: |
106 |
|
|
void process_sqlite(const std::vector<sqlite3*>& dbs, |
107 |
|
|
catalog::WritableCatalogManager &catalog_manager, |
108 |
|
|
bool allow_additions, bool allow_deletions, const std::string &lease_path, const std::string &additional_prefix); |
109 |
|
|
int add_files(catalog::WritableCatalogManager &catalog_manager, const std::vector<File> &files); |
110 |
|
|
int add_symlinks( |
111 |
|
|
catalog::WritableCatalogManager &catalog_manager, const std::vector<Symlink> &symlinks); |
112 |
|
|
int do_additions(const DirMap &all_dirs, const FileMap &all_files, const SymlinkMap &all_symlinks, const std::string &lease_path, |
113 |
|
|
catalog::WritableCatalogManager &catalog_manager); |
114 |
|
|
int do_deletions(sqlite3 *db, |
115 |
|
|
catalog::WritableCatalogManager &catalog_manager, const std::string &lease_path, const std::string &additional_prefix); |
116 |
|
|
void load_dirs(sqlite3 *db, const std::string &lease_path, const std::string &additional_prefix, std::map<std::string, Directory> &all_dirs); |
117 |
|
|
void load_files(sqlite3 *db, const std::string &lease_path, const std::string &additional_prefix, std::map<std::string, std::vector<File>> &all_files); |
118 |
|
|
void load_symlinks(sqlite3 *db, const std::string &lease_path, const std::string &additional_prefix, std::map<std::string, std::vector<Symlink>> &all_symlinks); |
119 |
|
|
}; |
120 |
|
|
} // namespace swissknife |
121 |
|
|
|
122 |
|
|
#endif // CVMFS_SWISSKNIFE_INGEST_H_ |
123 |
|
|
|