| 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('T', "reset TTL in sec")); |
| 53 |
|
✗ |
r.push_back(Parameter::Switch('z', "Create missing nested catalogs")); |
| 54 |
|
✗ |
r.push_back(Parameter::Optional('r', "lease retry interval")); |
| 55 |
|
✗ |
r.push_back( |
| 56 |
|
✗ |
Parameter::Switch('Z', "check and set completed_graft property")); |
| 57 |
|
✗ |
r.push_back(Parameter::Optional('P', "priority for graft (integer)")); |
| 58 |
|
✗ |
r.push_back(Parameter::Switch('v', "Enable verbose logging")); |
| 59 |
|
|
|
| 60 |
|
✗ |
return r; |
| 61 |
|
|
} |
| 62 |
|
|
int Main(const ArgumentList &args); |
| 63 |
|
|
|
| 64 |
|
|
struct Directory { |
| 65 |
|
|
std::string name; |
| 66 |
|
|
time_t mtime; |
| 67 |
|
|
mode_t mode; |
| 68 |
|
|
uid_t owner; |
| 69 |
|
|
gid_t grp; |
| 70 |
|
|
int nested; |
| 71 |
|
|
XattrList xattr; |
| 72 |
|
|
Directory() { } |
| 73 |
|
✗ |
Directory(const std::string &name, time_t mtime, mode_t mode, uid_t owner, |
| 74 |
|
|
gid_t grp, int nested) |
| 75 |
|
✗ |
: name(name) |
| 76 |
|
✗ |
, mtime(mtime) |
| 77 |
|
✗ |
, mode(mode) |
| 78 |
|
✗ |
, owner(owner) |
| 79 |
|
✗ |
, grp(grp) |
| 80 |
|
✗ |
, nested(nested) { } |
| 81 |
|
|
}; |
| 82 |
|
|
|
| 83 |
|
|
struct Symlink { |
| 84 |
|
|
std::string name; |
| 85 |
|
|
std::string target; |
| 86 |
|
|
time_t mtime; |
| 87 |
|
|
uid_t owner; |
| 88 |
|
|
gid_t grp; |
| 89 |
|
|
int skip_if_file_or_dir; |
| 90 |
|
✗ |
Symlink(std::string &&name, std::string &&target, time_t mtime, uid_t owner, |
| 91 |
|
|
gid_t grp, int skip_if_file_or_dir) |
| 92 |
|
✗ |
: name(std::move(name)) |
| 93 |
|
✗ |
, target(std::move(target)) |
| 94 |
|
✗ |
, mtime(mtime) |
| 95 |
|
✗ |
, owner(owner) |
| 96 |
|
✗ |
, grp(grp) |
| 97 |
|
✗ |
, skip_if_file_or_dir(skip_if_file_or_dir) { } |
| 98 |
|
|
}; |
| 99 |
|
|
|
| 100 |
|
|
struct File { |
| 101 |
|
|
std::string name; |
| 102 |
|
|
time_t mtime; |
| 103 |
|
|
size_t size; |
| 104 |
|
|
uid_t owner; |
| 105 |
|
|
gid_t grp; |
| 106 |
|
|
mode_t mode; |
| 107 |
|
|
int internal; |
| 108 |
|
|
FileChunkList chunks; |
| 109 |
|
|
int compressed; |
| 110 |
|
|
|
| 111 |
|
✗ |
File(std::string &&name, time_t mtime, size_t size, uid_t owner, gid_t grp, |
| 112 |
|
|
mode_t mode, int internal, int compressed) |
| 113 |
|
✗ |
: name(std::move(name)) |
| 114 |
|
✗ |
, mtime(mtime) |
| 115 |
|
✗ |
, size(size) |
| 116 |
|
✗ |
, owner(owner) |
| 117 |
|
✗ |
, grp(grp) |
| 118 |
|
✗ |
, mode(mode) |
| 119 |
|
✗ |
, internal(internal) |
| 120 |
|
✗ |
, compressed(compressed) { } |
| 121 |
|
|
}; |
| 122 |
|
|
|
| 123 |
|
|
typedef std::map<std::string, Directory> DirMap; |
| 124 |
|
|
typedef std::map<std::string, std::vector<File> > FileMap; |
| 125 |
|
|
typedef std::map<std::string, std::vector<Symlink> > SymlinkMap; |
| 126 |
|
|
|
| 127 |
|
|
private: |
| 128 |
|
|
void process_sqlite(const std::vector<sqlite3 *> &dbs, |
| 129 |
|
|
catalog::WritableCatalogManager &catalog_manager, |
| 130 |
|
|
bool allow_additions, bool allow_deletions, |
| 131 |
|
|
const std::string &lease_path, |
| 132 |
|
|
const std::string &additional_prefix); |
| 133 |
|
|
int add_files(catalog::WritableCatalogManager &catalog_manager, |
| 134 |
|
|
const std::vector<File> &files); |
| 135 |
|
|
int add_symlinks(catalog::WritableCatalogManager &catalog_manager, |
| 136 |
|
|
const std::vector<Symlink> &symlinks); |
| 137 |
|
|
int do_additions(const DirMap &all_dirs, const FileMap &all_files, |
| 138 |
|
|
const SymlinkMap &all_symlinks, |
| 139 |
|
|
const std::string &lease_path, |
| 140 |
|
|
catalog::WritableCatalogManager &catalog_manager); |
| 141 |
|
|
int do_deletions(sqlite3 *db, |
| 142 |
|
|
catalog::WritableCatalogManager &catalog_manager, |
| 143 |
|
|
const std::string &lease_path, |
| 144 |
|
|
const std::string &additional_prefix); |
| 145 |
|
|
void load_dirs(sqlite3 *db, const std::string &lease_path, |
| 146 |
|
|
const std::string &additional_prefix, |
| 147 |
|
|
std::map<std::string, Directory> &all_dirs); |
| 148 |
|
|
void load_files(sqlite3 *db, const std::string &lease_path, |
| 149 |
|
|
const std::string &additional_prefix, |
| 150 |
|
|
std::map<std::string, std::vector<File> > &all_files); |
| 151 |
|
|
void load_symlinks( |
| 152 |
|
|
sqlite3 *db, const std::string &lease_path, |
| 153 |
|
|
const std::string &additional_prefix, |
| 154 |
|
|
std::map<std::string, std::vector<Symlink> > &all_symlinks); |
| 155 |
|
|
}; |
| 156 |
|
|
} // namespace swissknife |
| 157 |
|
|
|
| 158 |
|
|
#endif // CVMFS_SWISSKNIFE_INGEST_H_ |
| 159 |
|
|
|