GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/swissknife_ingestsql.h
Date: 2026-11-08 02:41:18
Exec Total Coverage
Lines: 0 58 0.0%
Branches: 0 0 -%

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 <map>
9 #include <string>
10 #include <utility>
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(
37 ✗ Parameter::Optional('p', "prefix to add to lease and all graft files"));
38 ✗ r.push_back(Parameter::Optional('q', "number of concurrent write jobs"));
39 ✗ r.push_back(Parameter::Optional('s', "gateway secret"));
40 ✗ r.push_back(Parameter::Optional('3', "s3 config"));
41 ✗ r.push_back(Parameter::Switch(
42 'a', "Allow additions (default true, false if -d specified)"));
43 ✗ r.push_back(Parameter::Switch('d', "Allow deletions"));
44 ✗ r.push_back(Parameter::Switch('x', "Force deletion of any lease"));
45 ✗ r.push_back(Parameter::Switch(
46 'c', "Enable corefile generation (requires ulimit -c >0)"));
47 ✗ r.push_back(Parameter::Optional('n', "create empty database file"));
48 ✗ r.push_back(Parameter::Optional(
49 'C', "config prefix, default /etc/cvmfs/gateway-client/"));
50 ✗ r.push_back(Parameter::Optional(
51 'B', "mount point to block on pending visibility of update"));
52 ✗ r.push_back(Parameter::Optional(
53 'W', "Timeout, in seconds, for waiting on "
54 "pending visibility of update (default: if "
55 "-B given, wait infinitely; if no -B, immediate exit)"));
56 ✗ r.push_back(Parameter::Optional('T', "reset TTL in sec"));
57 ✗ r.push_back(Parameter::Switch('z', "Create missing nested catalogs"));
58 ✗ r.push_back(Parameter::Optional('r', "lease retry interval"));
59 ✗ r.push_back(
60 ✗ Parameter::Switch('Z', "check and set completed_graft property"));
61 ✗ r.push_back(Parameter::Optional('P', "priority for graft (integer)"));
62 ✗ r.push_back(Parameter::Switch('v', "Enable verbose logging"));
63
64 ✗ return r;
65 }
66 int Main(const ArgumentList &args);
67
68 struct Directory {
69 std::string name;
70 time_t mtime;
71 mode_t mode;
72 uid_t owner;
73 gid_t grp;
74 int nested;
75 XattrList xattr;
76 Directory() { }
77 ✗ Directory(const std::string &name, time_t mtime, mode_t mode, uid_t owner,
78 gid_t grp, int nested)
79 ✗ : name(name)
80 ✗ , mtime(mtime)
81 ✗ , mode(mode)
82 ✗ , owner(owner)
83 ✗ , grp(grp)
84 ✗ , nested(nested) { }
85 };
86
87 struct Symlink {
88 std::string name;
89 std::string target;
90 time_t mtime;
91 uid_t owner;
92 gid_t grp;
93 int skip_if_file_or_dir;
94 ✗ Symlink(std::string &&name, std::string &&target, time_t mtime, uid_t owner,
95 gid_t grp, int skip_if_file_or_dir)
96 ✗ : name(std::move(name))
97 ✗ , target(std::move(target))
98 ✗ , mtime(mtime)
99 ✗ , owner(owner)
100 ✗ , grp(grp)
101 ✗ , skip_if_file_or_dir(skip_if_file_or_dir) { }
102 };
103
104 struct File {
105 std::string name;
106 time_t mtime;
107 size_t size;
108 uid_t owner;
109 gid_t grp;
110 mode_t mode;
111 int internal;
112 FileChunkList chunks;
113 int compressed;
114
115 ✗ File(std::string &&name, time_t mtime, size_t size, uid_t owner, gid_t grp,
116 mode_t mode, int internal, int compressed)
117 ✗ : name(std::move(name))
118 ✗ , mtime(mtime)
119 ✗ , size(size)
120 ✗ , owner(owner)
121 ✗ , grp(grp)
122 ✗ , mode(mode)
123 ✗ , internal(internal)
124 ✗ , compressed(compressed) { }
125 };
126
127 typedef std::map<std::string, Directory> DirMap;
128 typedef std::map<std::string, std::vector<File> > FileMap;
129 typedef std::map<std::string, std::vector<Symlink> > SymlinkMap;
130
131 private:
132 void process_sqlite(const std::vector<sqlite3 *> &dbs,
133 catalog::WritableCatalogManager &catalog_manager,
134 bool allow_additions, bool allow_deletions,
135 const std::string &lease_path,
136 const std::string &additional_prefix);
137 int add_files(catalog::WritableCatalogManager &catalog_manager,
138 const std::vector<File> &files);
139 int add_symlinks(catalog::WritableCatalogManager &catalog_manager,
140 const std::vector<Symlink> &symlinks);
141 int do_additions(const DirMap &all_dirs, const FileMap &all_files,
142 const SymlinkMap &all_symlinks,
143 const std::string &lease_path,
144 catalog::WritableCatalogManager &catalog_manager);
145 int do_deletions(sqlite3 *db,
146 catalog::WritableCatalogManager &catalog_manager,
147 const std::string &lease_path,
148 const std::string &additional_prefix);
149 void load_dirs(sqlite3 *db, const std::string &lease_path,
150 const std::string &additional_prefix,
151 std::map<std::string, Directory> &all_dirs);
152 void load_files(sqlite3 *db, const std::string &lease_path,
153 const std::string &additional_prefix,
154 std::map<std::string, std::vector<File> > &all_files);
155 void load_symlinks(
156 sqlite3 *db, const std::string &lease_path,
157 const std::string &additional_prefix,
158 std::map<std::string, std::vector<Symlink> > &all_symlinks);
159 };
160 } // namespace swissknife
161
162 #endif // CVMFS_SWISSKNIFE_INGEST_H_
163