clang format 120 length

This commit is contained in:
2023-08-06 19:42:03 +02:00
parent 3ef8c796a4
commit 802c2d70e0
60 changed files with 427 additions and 528 deletions

View File

@@ -13,11 +13,11 @@
#include "Object.h"
#include "Serialize.h"
FileRepository::FileRepository(Config config) : Repository(std::move(config)), root(std::filesystem::path(this->config.getStr("repo"))), writeCacheMax(config.getInt("repo-target") * 1024 * 1024) {}
FileRepository::FileRepository(Config config)
: Repository(std::move(config)), root(std::filesystem::path(this->config.getStr("repo"))),
writeCacheMax(config.getInt("repo-target") * 1024 * 1024) {}
bool FileRepository::exists() {
return std::filesystem::is_directory(root) && std::filesystem::exists(root / "info");
}
bool FileRepository::exists() { return std::filesystem::is_directory(root) && std::filesystem::exists(root / "info"); }
bool FileRepository::flush() {
flushWriteCache(std::unique_lock(writeCacheLock));
@@ -31,14 +31,20 @@ bool FileRepository::open() {
std::swap(config, readConf);
config.merge(readConf);
if (config.getStr("compression") != "none") filters.addFilter(FilterFactory::makeFilter(config.getStr("compression"), config));
if (config.getStr("encryption") != "none") filters.addFilter(FilterFactory::makeFilter(config.getStr("encryption"), config));
if (config.getStr("compression") != "none")
filters.addFilter(FilterFactory::makeFilter(config.getStr("compression"), config));
if (config.getStr("encryption") != "none")
filters.addFilter(FilterFactory::makeFilter(config.getStr("encryption"), config));
filters.addFilter(FilterFactory::makeFilter("crc", config));
ready = true;
try {
std::tie(maxFileId, offsetIndex) = Serialize::deserialize<std::pair<decltype(maxFileId), decltype(offsetIndex)>>(filters.filterRead(readFile(root / "offsets")));
std::tie(keyIndex, largestUnusedId) = Serialize::deserialize<std::pair<decltype(keyIndex), decltype(largestUnusedId)>>(filters.filterRead(readFile(root / "index")));
std::tie(maxFileId, offsetIndex) =
Serialize::deserialize<std::pair<decltype(maxFileId), decltype(offsetIndex)>>(
filters.filterRead(readFile(root / "offsets")));
std::tie(keyIndex, largestUnusedId) =
Serialize::deserialize<std::pair<decltype(keyIndex), decltype(largestUnusedId)>>(
filters.filterRead(readFile(root / "index")));
} catch (const std::exception &e) {
ready = false;
throw;
@@ -56,8 +62,10 @@ bool FileRepository::init() {
writeFile(root / "info", CheckFilter::filterWriteStatic(Serialize::serialize(config)));
if (config.getStr("compression") != "none") filters.addFilter(FilterFactory::makeFilter(config.getStr("compression"), config));
if (config.getStr("encryption") != "none") filters.addFilter(FilterFactory::makeFilter(config.getStr("encryption"), config));
if (config.getStr("compression") != "none")
filters.addFilter(FilterFactory::makeFilter(config.getStr("compression"), config));
if (config.getStr("encryption") != "none")
filters.addFilter(FilterFactory::makeFilter(config.getStr("encryption"), config));
filters.addFilter(FilterFactory::makeFilter("crc", config));
ready = true;
@@ -78,8 +86,7 @@ std::vector<char> FileRepository::getObject(Object::idType id) const {
if (!ready) throw Exception("Tried working with uninitialized repo!");
std::unique_lock lock(repoLock);
if (offsetIndex.count(id) == 0)
throw Exception("Object with id " + std::to_string(id) + " doesn't exist!");
if (offsetIndex.count(id) == 0) throw Exception("Object with id " + std::to_string(id) + " doesn't exist!");
auto entry = offsetIndex.at(id);
lock.unlock();
@@ -95,9 +102,7 @@ bool FileRepository::writeObject(const Object &obj) {
writeCache[obj.id] = std::move(tmp);
// If we have reached the target file size, flush the cache
if (writeCacheSize >= writeCacheMax) {
flushWriteCache(std::move(lockW));
}
if (writeCacheSize >= writeCacheMax) { flushWriteCache(std::move(lockW)); }
}
return true;
}
@@ -149,17 +154,19 @@ bool FileRepository::deleteObject(const Object &obj) {
throw Exception("Deletion not implemented!");
}
std::vector<char> FileRepository::readFile(const std::filesystem::path &file, unsigned long long offset, unsigned long long size) const {
if (size > absoluteMaxFileLimit) throw Exception("Tried to read " + std::to_string(size) +
" bytes from " + file.u8string() +
" which is more than absoluteMaxFileLimit");
std::vector<char> FileRepository::readFile(const std::filesystem::path &file, unsigned long long offset,
unsigned long long size) const {
if (size > absoluteMaxFileLimit)
throw Exception("Tried to read " + std::to_string(size) + " bytes from " + file.u8string() +
" which is more than absoluteMaxFileLimit");
std::ifstream ifstream(file, std::ios::binary | std::ios::in);
if (!ifstream.is_open()) throw Exception("Can't open file " + file.u8string() + " for reading!");
std::vector<char> buf(size);
if (ifstream.rdbuf()->pubseekpos(offset) == std::streampos(std::streamoff(-1))) throw Exception("Unexpected end of file " + file.u8string());
if (ifstream.rdbuf()->pubseekpos(offset) == std::streampos(std::streamoff(-1)))
throw Exception("Unexpected end of file " + file.u8string());
if (ifstream.rdbuf()->sgetn(buf.data(), size) != size) throw Exception("Unexpected end of file " + file.u8string());
return buf;
@@ -195,8 +202,7 @@ std::vector<std::pair<std::string, Object::idType>> FileRepository::getObjects(O
std::lock_guard lock(repoLock);
std::vector<std::pair<std::string, Object::idType>> out;
if (keyIndex.count(type) == 0) return {};
for (auto const &i: keyIndex.at(type))
out.emplace_back(i);
for (auto const &i: keyIndex.at(type)) out.emplace_back(i);
return out;
}
@@ -211,11 +217,11 @@ Object::idType FileRepository::getId() {
return largestUnusedId++;
}
FileRepository::OffsetEntry::OffsetEntry(std::vector<char, std::allocator<char>>::const_iterator &in, const std::vector<char, std::allocator<char>>::const_iterator &end)
FileRepository::OffsetEntry::OffsetEntry(std::vector<char, std::allocator<char>>::const_iterator &in,
const std::vector<char, std::allocator<char>>::const_iterator &end)
: fileId(Serialize::deserialize<decltype(fileId)>(in, end)),
offset(Serialize::deserialize<decltype(offset)>(in, end)),
length(Serialize::deserialize<decltype(length)>(in, end)) {
}
length(Serialize::deserialize<decltype(length)>(in, end)) {}
void FileRepository::OffsetEntry::serialize(std::vector<char> &out) const {
Serialize::serialize(fileId, out);
@@ -223,5 +229,6 @@ void FileRepository::OffsetEntry::serialize(std::vector<char> &out) const {
Serialize::serialize(length, out);
}
FileRepository::OffsetEntry::OffsetEntry(unsigned long long int fileId, unsigned long long int offset, unsigned long long int length)
FileRepository::OffsetEntry::OffsetEntry(unsigned long long int fileId, unsigned long long int offset,
unsigned long long int length)
: fileId(fileId), offset(offset), length(length) {}

View File

@@ -9,9 +9,7 @@
Object::Object(idType id, ObjectType type) : id(id), type(type) {}
Object::Object(std::vector<char>::const_iterator &in, const std::vector<char>::const_iterator &end)
: id(Serialize::deserialize<idType>(in, end)),
type(Serialize::deserialize<ObjectType>(in, end)) {
}
: id(Serialize::deserialize<idType>(in, end)), type(Serialize::deserialize<ObjectType>(in, end)) {}
void Object::serialize(std::vector<char> &out) const {
Serialize::serialize(id, out);

View File

@@ -7,6 +7,4 @@ Repository::~Repository() = default;
Repository::Repository(Config config) : config(std::move(config)) {}
const Config &Repository::getConfig() const {
return config;
}
const Config &Repository::getConfig() const { return config; }

View File

@@ -11,8 +11,7 @@ Archive::Archive(Object::idType id, std::string name, unsigned long long mtime,
: Object(id, ObjectType::Archive), name(name), mtime(mtime), files(files) {}
Archive::Archive(std::vector<char>::const_iterator &in, const std::vector<char>::const_iterator &end)
: Object(in, end),
name(Serialize::deserialize<std::string>(in, end)),
: Object(in, end), name(Serialize::deserialize<std::string>(in, end)),
mtime(Serialize::deserialize<unsigned long long>(in, end)),
files(Serialize::deserialize<std::remove_const<decltype(files)>::type>(in, end)) {
if (type != ObjectType::Archive) throw Exception("Type mismatch for Archive!");
@@ -28,6 +27,4 @@ void Archive::serialize(std::vector<char> &out) const {
Serialize::serialize(files.size(), out);
}
std::string Archive::getKey() const {
return name;
}
std::string Archive::getKey() const { return name; }

View File

@@ -7,11 +7,11 @@
#include "Exception.h"
#include "Serialize.h"
Chunk::Chunk(idType id, std::string SHA, std::vector<char> data) : Object(id, ObjectType::Chunk), data(std::move(data)), SHA(std::move(SHA)), length(this->data.size()) {}
Chunk::Chunk(idType id, std::string SHA, std::vector<char> data)
: Object(id, ObjectType::Chunk), data(std::move(data)), SHA(std::move(SHA)), length(this->data.size()) {}
Chunk::Chunk(std::vector<char>::const_iterator &in, const std::vector<char>::const_iterator &end)
: Object(in, end),
SHA(Serialize::deserialize<std::remove_const<decltype(SHA)>::type>(in, end)),
: Object(in, end), SHA(Serialize::deserialize<std::remove_const<decltype(SHA)>::type>(in, end)),
data(Serialize::deserialize<std::remove_const<decltype(data)>::type>(in, end)),
length(Serialize::deserialize<std::remove_const<decltype(length)>::type>(in, end)) {
if (type != ObjectType::Chunk) throw Exception("Type mismatch for Chunk!");
@@ -25,6 +25,4 @@ void Chunk::serialize(std::vector<char> &out) const {
Serialize::serialize(length, out);
}
std::string Chunk::getKey() const {
return SHA;
}
std::string Chunk::getKey() const { return SHA; }

View File

@@ -11,12 +11,13 @@
#include "Exception.h"
#include "Serialize.h"
File::File(Object::idType id, std::string name, unsigned long long bytes, unsigned long long mtime, std::string SHA, std::map<size_t, idType> chunks, Type fileType)
: Object(id, ObjectType::File), name(name), bytes(bytes), mtime(mtime), SHA(SHA), fileType(fileType), chunks(std::move(chunks)) {}
File::File(Object::idType id, std::string name, unsigned long long bytes, unsigned long long mtime, std::string SHA,
std::map<size_t, idType> chunks, Type fileType)
: Object(id, ObjectType::File), name(name), bytes(bytes), mtime(mtime), SHA(SHA), fileType(fileType),
chunks(std::move(chunks)) {}
File::File(std::vector<char>::const_iterator &in, const std::vector<char>::const_iterator &end)
: Object(in, end),
name(Serialize::deserialize<std::string>(in, end)),
: Object(in, end), name(Serialize::deserialize<std::string>(in, end)),
bytes(Serialize::deserialize<unsigned long long>(in, end)),
mtime(Serialize::deserialize<unsigned long long>(in, end)),
SHA(Serialize::deserialize<std::remove_const<decltype(SHA)>::type>(in, end)),
@@ -35,9 +36,7 @@ void File::serialize(std::vector<char> &out) const {
Serialize::serialize(chunks, out);
}
std::string File::getKey() const {
return name;
}
std::string File::getKey() const { return name; }
File::Type File::getFileType(const std::filesystem::path &p) {
if (std::filesystem::is_symlink(p)) return Type::Symlink;
@@ -49,9 +48,7 @@ File::Type File::getFileType(const std::filesystem::path &p) {
std::vector<char> File::getFileContents(const std::filesystem::path &p) {
auto type = getFileType(p);
if (type == Type::Normal) throw Exception(p.u8string() + " is a normal file!");
if (type == Type::Directory) {
return {};
}
if (type == Type::Directory) { return {}; }
if (type == Type::Symlink) {
auto target = std::filesystem::read_symlink(p).u8string();
std::vector<char> target_null_term = {target.begin(), target.end()};
@@ -64,7 +61,9 @@ std::vector<char> File::getFileContents(const std::filesystem::path &p) {
unsigned long long File::getFileMtime(const std::filesystem::path &p) {
auto type = getFileType(p);
if (type == Type::Normal || type == Type::Directory)
return static_cast<const unsigned long long int>(std::chrono::duration_cast<std::chrono::seconds>(std::filesystem::last_write_time(p).time_since_epoch()).count());
return static_cast<const unsigned long long int>(
std::chrono::duration_cast<std::chrono::seconds>(std::filesystem::last_write_time(p).time_since_epoch())
.count());
else if (type == Type::Symlink) {
auto path = p.u8string();
struct stat sb;

View File

@@ -6,13 +6,12 @@
#include "Serialize.h"
FileBuffer::FileBuffer(const Repository *repo, Object::idType fileId) : repo(repo), file(Serialize::deserialize<File>(repo->getObject(fileId))), chunksQueue() {
FileBuffer::FileBuffer(const Repository *repo, Object::idType fileId)
: repo(repo), file(Serialize::deserialize<File>(repo->getObject(fileId))), chunksQueue() {
for (auto const &id: file.chunks) chunksQueue.emplace(id.second);
};
int FileBuffer::sync() {
return 0;
}
int FileBuffer::sync() { return 0; }
std::streamsize FileBuffer::xsgetn(char *s, std::streamsize countr) {
if (underflow() == std::char_traits<char>::eof()) return 0;
@@ -28,8 +27,7 @@ std::streamsize FileBuffer::xsgetn(char *s, std::streamsize countr) {
int FileBuffer::uflow() {
auto out = underflow();
if (out != traits_type::eof())
curGetBufPos++;
if (out != traits_type::eof()) curGetBufPos++;
return out;
}
@@ -44,8 +42,7 @@ int FileBuffer::underflow() {
}
}
if (!getBuf.empty())
return traits_type::to_int_type(getBuf[curGetBufPos]);
if (!getBuf.empty()) return traits_type::to_int_type(getBuf[curGetBufPos]);
else
return traits_type::eof();
}