Skip to content

Commit

Permalink
replace "zlib" namespace with "zip". this generic namespace accounts …
Browse files Browse the repository at this point in the history
…for support of different compression algorithms
  • Loading branch information
HereThereBeDragons committed Nov 12, 2024
1 parent f1326c0 commit 8f69ffe
Show file tree
Hide file tree
Showing 98 changed files with 535 additions and 536 deletions.
8 changes: 4 additions & 4 deletions cvmfs/cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const uint64_t CacheManager::kSizeUnknown = uint64_t(-1);


CacheManager::CacheManager() : quota_mgr_(new NoopQuotaManager()) {
compress_ = zlib::Compressor::Construct(zlib::kZlibDefault);
compress_ = zip::Compressor::Construct(zip::kZlibDefault);
}

CacheManager::~CacheManager() {
Expand All @@ -49,11 +49,11 @@ int CacheManager::ChecksumFd(int fd, shash::Any *id) {
return check_read;
}

zlib::InputCache input(this, fd, 4096);
zip::InputCache input(this, fd, 4096);
cvmfs::NullSink out_null;
const zlib::StreamStates retval = compress_->Compress(&input, &out_null, id);
const zip::StreamStates retval = compress_->Compress(&input, &out_null, id);

if (retval != zlib::kStreamEnd) {
if (retval != zip::kStreamEnd) {
return -EINVAL;
}

Expand Down
6 changes: 3 additions & 3 deletions cvmfs/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class CacheManager : SingleCopy {
struct Label {
Label() : flags(0)
, size(kSizeUnknown)
, zip_algorithm(zlib::kZlibDefault)
, zip_algorithm(zip::kZlibDefault)
, range_offset(-1)
{}

Expand Down Expand Up @@ -123,7 +123,7 @@ class CacheManager : SingleCopy {

int flags;
uint64_t size; ///< unzipped size, if known
zlib::Algorithms zip_algorithm;
zip::Algorithms zip_algorithm;
off_t range_offset;
/**
* The logical path on the mountpoint connected to the object. For meta-
Expand Down Expand Up @@ -233,7 +233,7 @@ class CacheManager : SingleCopy {
* Never NULL but defaults to NoopQuotaManager.
*/
QuotaManager *quota_mgr_;
UniquePtr<zlib::Compressor> compress_;
UniquePtr<zip::Compressor> compress_;

private:
static const unsigned kStateVersion = 0;
Expand Down
8 changes: 4 additions & 4 deletions cvmfs/cache_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,12 @@ int PosixCacheManager::CommitTxn(void *txn) {
transaction->id.ToString().c_str(),
transaction->expected_size, transaction->size);

const UniquePtr<zlib::Compressor>
copy(zlib::Compressor::Construct(zlib::kNoCompression));
zlib::InputPath in_path(transaction->tmp_path);
const UniquePtr<zip::Compressor>
copy(zip::Compressor::Construct(zip::kNoCompression));
zip::InputPath in_path(transaction->tmp_path);
cvmfs::PathSink
out_path(cache_path_ + "/quarantaine/" + transaction->id.ToString());
if (copy->Compress(&in_path, &out_path) != zlib::kStreamEnd) {
if (copy->Compress(&in_path, &out_path) != zip::kStreamEnd) {
LogCvmfs(kLogCache, kLogDebug | kLogSyslogErr,
"copying file %s to %s failed",
in_path.path().c_str(), out_path.path().c_str());
Expand Down
2 changes: 1 addition & 1 deletion cvmfs/cache_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ int64_t StreamingCacheManager::Stream(
} else {
url = "/data/" + info.object_id.MakePath();
}
bool is_zipped = info.label.zip_algorithm == zlib::kZlibDefault;
bool is_zipped = info.label.zip_algorithm == zip::kZlibDefault;

download::JobInfo download_job(&url, is_zipped, true /* probe_hosts */,
&info.object_id, &sink);
Expand Down
2 changes: 1 addition & 1 deletion cvmfs/catalog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ bool Catalog::AllChunksBegin() {
}


bool Catalog::AllChunksNext(shash::Any *hash, zlib::Algorithms *compression_alg)
bool Catalog::AllChunksNext(shash::Any *hash, zip::Algorithms *compression_alg)
{
return sql_all_chunks_->Next(hash, compression_alg);
}
Expand Down
2 changes: 1 addition & 1 deletion cvmfs/catalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class Catalog : SingleCopy {
return ListingMd5PathStat(NormalizePath(path), listing);
}
bool AllChunksBegin();
bool AllChunksNext(shash::Any *hash, zlib::Algorithms *compression_alg);
bool AllChunksNext(shash::Any *hash, zip::Algorithms *compression_alg);
bool AllChunksEnd();

inline bool ListPathChunks(const PathString &path,
Expand Down
8 changes: 4 additions & 4 deletions cvmfs/catalog_balancer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ CatalogBalancer<CatalogMgrT>::MakeEmptyDirectoryEntryBase(
shash::Algorithms algorithm = catalog_mgr_->spooler_->GetHashAlgorithm();
shash::Any file_hash(algorithm);

UniquePtr<zlib::Compressor>
compressor(zlib::Compressor::Construct(zlib::kZlibDefault));
UniquePtr<zip::Compressor>
compressor(zip::Compressor::Construct(zip::kZlibDefault));

zlib::InputMem in(NULL, 0);
zip::InputMem in(NULL, 0);
cvmfs::MemSink empty_compressed(0);
assert(compressor->Compress(&in, &empty_compressed) == zlib::kStreamEnd);
assert(compressor->Compress(&in, &empty_compressed) == zip::kStreamEnd);

shash::HashMem(empty_compressed.data(), empty_compressed.pos(), &file_hash);

Expand Down
6 changes: 3 additions & 3 deletions cvmfs/catalog_mgr_ro.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ SimpleCatalogManager::SimpleCatalogManager(
"Failure during creation of local cache directory for server. "
"Local cache directory: %s", dir_cache_.c_str());
}
copy_ = zlib::Decompressor::Construct(zlib::kNoCompression);
copy_ = zip::Decompressor::Construct(zip::kNoCompression);

} else {
copy_to_tmp_dir_ = false;
Expand All @@ -68,11 +68,11 @@ std::string SimpleCatalogManager::CopyCatalogToTempFile(
cache_path.c_str());
}

zlib::InputPath in_path(cache_path);
zip::InputPath in_path(cache_path);
cvmfs::FileSink out_file(fcatalog, true);

const bool retval = (copy_->DecompressStream(&in_path, &out_file)
== zlib::kStreamEnd);
== zip::kStreamEnd);
if (!retval) {
unlink(tmp_path.c_str());
PANIC(kLogStderr, "failed to read %s", cache_path.c_str());
Expand Down
2 changes: 1 addition & 1 deletion cvmfs/catalog_mgr_ro.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class SimpleCatalogManager : public AbstractCatalogManager<Catalog> {
// cache directory:
// for writeable catalogs a copy
// must be created in dir_temp_
UniquePtr<zlib::Decompressor> copy_;
UniquePtr<zip::Decompressor> copy_;

private:
std::string CopyCatalogToTempFile(const std::string &cache_path);
Expand Down
20 changes: 10 additions & 10 deletions cvmfs/catalog_mgr_rw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ manifest::Manifest *WritableCatalogManager::CreateRepository(
string file_path_compressed = file_path + ".compressed";
shash::Any hash_catalog(hash_algorithm, shash::kSuffixCatalog);

const UniquePtr<zlib::Compressor>
compress(zlib::Compressor::Construct(zlib::kZlibDefault));
zlib::InputPath in_path(file_path);
const UniquePtr<zip::Compressor>
compress(zip::Compressor::Construct(zip::kZlibDefault));
zip::InputPath in_path(file_path);
cvmfs::PathSink out_path(file_path_compressed);
const zlib::StreamStates retval = compress->Compress(&in_path, &out_path,
const zip::StreamStates retval = compress->Compress(&in_path, &out_path,
&hash_catalog);
if (retval != zlib::kStreamEnd) {
if (retval != zip::kStreamEnd) {
LogCvmfs(kLogCatalog, kLogStderr, "compression of catalog '%s' failed",
file_path.c_str());
unlink(file_path.c_str());
Expand Down Expand Up @@ -1260,7 +1260,7 @@ bool WritableCatalogManager::CopyCatalogToLocalCache(
tmp_catalog_path.c_str());
}

zlib::InputPath in_path(result.local_path.c_str());
zip::InputPath in_path(result.local_path.c_str());
cvmfs::FileSink out_file(fcatalog, true);
copy_->DecompressStream(&in_path, &out_file);

Expand Down Expand Up @@ -1477,18 +1477,18 @@ WritableCatalogManager::SnapshotCatalogsSerialized(
WritableCatalogList::const_iterator i = catalogs_to_snapshot.begin();
const WritableCatalogList::const_iterator iend = catalogs_to_snapshot.end();

const UniquePtr<zlib::Compressor>
compress(zlib::Compressor::Construct(zlib::kZlibDefault));
const UniquePtr<zip::Compressor>
compress(zip::Compressor::Construct(zip::kZlibDefault));
for (; i != iend; ++i) {
FinalizeCatalog(*i, stop_for_tweaks);

// Compress and upload catalog
shash::Any hash_catalog(spooler_->GetHashAlgorithm(),
shash::kSuffixCatalog);
zlib::InputPath input((*i)->database_path());
zip::InputPath input((*i)->database_path());
cvmfs::NullSink out_null;
if (compress->Compress(&input, &out_null, &hash_catalog)
!= zlib::kStreamEnd) {
!= zip::kStreamEnd) {
PANIC(kLogStderr, "could not compress catalog %s",
(*i)->mountpoint().ToString().c_str());
}
Expand Down
8 changes: 4 additions & 4 deletions cvmfs/catalog_sql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -489,13 +489,13 @@ shash::Algorithms SqlDirent::RetrieveHashAlgorithm(const unsigned flags) const {
}


zlib::Algorithms SqlDirent::RetrieveCompressionAlgorithm(const unsigned flags)
zip::Algorithms SqlDirent::RetrieveCompressionAlgorithm(const unsigned flags)
const
{
// 3 bits, so use 7 (111) to only pull out the flags we want
unsigned in_flags =
((7 << kFlagPosCompression) & flags) >> kFlagPosCompression;
return static_cast<zlib::Algorithms>(in_flags);
return static_cast<zip::Algorithms>(in_flags);
}


Expand Down Expand Up @@ -1409,14 +1409,14 @@ bool SqlAllChunks::Open() {
}


bool SqlAllChunks::Next(shash::Any *hash, zlib::Algorithms *compression_alg) {
bool SqlAllChunks::Next(shash::Any *hash, zip::Algorithms *compression_alg) {
if (!FetchRow()) {
return false;
}

*hash = RetrieveHashBlob(0, static_cast<shash::Algorithms>(RetrieveInt(2)),
static_cast<shash::Suffix>(RetrieveInt(1)));
*compression_alg = static_cast<zlib::Algorithms>(RetrieveInt(3));
*compression_alg = static_cast<zip::Algorithms>(RetrieveInt(3));
return true;
}

Expand Down
6 changes: 3 additions & 3 deletions cvmfs/catalog_sql.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class SqlDirent : public SqlCatalog {
// hashes
static const int kFlagPosHash = 8;
// Compression methods, 3 bits starting at 2^11
// Corresponds to zlib::Algorithms
// Corresponds to zip::Algorithms
static const int kFlagPosCompression = 11;
/**
* A transition point to a root catalog (instead of a nested catalog). Used
Expand Down Expand Up @@ -226,7 +226,7 @@ class SqlDirent : public SqlCatalog {
unsigned CreateDatabaseFlags(const DirectoryEntry &entry) const;
void StoreHashAlgorithm(const shash::Algorithms algo, unsigned *flags) const;
shash::Algorithms RetrieveHashAlgorithm(const unsigned flags) const;
zlib::Algorithms RetrieveCompressionAlgorithm(const unsigned flags) const;
zip::Algorithms RetrieveCompressionAlgorithm(const unsigned flags) const;

/**
* The hardlink information (hardlink group ID and linkcount) is saved in one
Expand Down Expand Up @@ -579,7 +579,7 @@ class SqlAllChunks : public SqlCatalog {
public:
explicit SqlAllChunks(const CatalogDatabase &database);
bool Open();
bool Next(shash::Any *hash, zlib::Algorithms *compression_alg);
bool Next(shash::Any *hash, zip::Algorithms *compression_alg);
bool Close();
};

Expand Down
6 changes: 3 additions & 3 deletions cvmfs/catalog_virtual.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ void VirtualCatalog::CreateNestedCatalogMarker() {
shash::Algorithms algorithm = catalog_mgr_->spooler_->GetHashAlgorithm();
shash::Any file_hash(algorithm);

zlib::InputMem in(NULL, 0);
zip::InputMem in(NULL, 0);
cvmfs::MemSink empty_compressed(0);
assert(compressor->Compress(&in, &empty_compressed) == zlib::kStreamEnd);
assert(compressor->Compress(&in, &empty_compressed) == zip::kStreamEnd);
shash::HashMem(empty_compressed.data(), empty_compressed.pos(), &file_hash);

entry_marker.name_ = NameString(".cvmfscatalog");
Expand Down Expand Up @@ -337,7 +337,7 @@ VirtualCatalog::VirtualCatalog(manifest::Manifest *m,
SyncParameters *p)
: catalog_mgr_(c)
, assistant_(d, m, p->stratum0, p->dir_temp) {
compressor = zlib::Compressor::Construct(zlib::kZlibDefault);
compressor = zip::Compressor::Construct(zip::kZlibDefault);
}

} // namespace catalog
2 changes: 1 addition & 1 deletion cvmfs/catalog_virtual.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class VirtualCatalog {

private:
static const char *kSnapshotDirectory;
UniquePtr<zlib::Compressor> compressor;
UniquePtr<zip::Compressor> compressor;

struct TagId {
TagId() { }
Expand Down
4 changes: 2 additions & 2 deletions cvmfs/compat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void Migrate(ChunkTables *old_tables, ::ChunkTables *new_tables) {
}
delete old_list;
::FileChunkReflist new_reflist(new_list, old_reflist->path,
zlib::kZlibDefault, false);
zip::kZlibDefault, false);
new_tables->inode2chunks.Insert(inode, new_reflist);
}
}
Expand Down Expand Up @@ -249,7 +249,7 @@ void Migrate(ChunkTables *old_tables, ::ChunkTables *new_tables) {
}
delete old_list;
::FileChunkReflist new_reflist(new_list, old_reflist->path,
zlib::kZlibDefault, false);
zip::kZlibDefault, false);
new_tables->inode2chunks.Insert(inode, new_reflist);
}
}
Expand Down
2 changes: 1 addition & 1 deletion cvmfs/compression/compressor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "util/posix.h"
#include "util/smalloc.h"

namespace zlib {
namespace zip {

void Compressor::RegisterPlugins() {
RegisterPlugin<ZlibCompressor>();
Expand Down
2 changes: 1 addition & 1 deletion cvmfs/compression/compressor.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct Any;
class ContextPtr;
}

namespace zlib {
namespace zip {

/**
* Abstract Compression class which is inherited by implementations of
Expand Down
8 changes: 4 additions & 4 deletions cvmfs/compression/compressor_echo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@

#include "crypto/hash.h"

namespace zlib {
namespace zip {

EchoCompressor::EchoCompressor(const zlib::Algorithms &alg) : Compressor(alg) {
EchoCompressor::EchoCompressor(const zip::Algorithms &alg) : Compressor(alg) {
is_healthy_ = true;
output_full_ = false;
}


bool EchoCompressor::WillHandle(const zlib::Algorithms &alg) {
bool EchoCompressor::WillHandle(const zip::Algorithms &alg) {
return alg == kNoCompression;
}


Compressor* EchoCompressor::Clone() {
return new EchoCompressor(zlib::kNoCompression);
return new EchoCompressor(zip::kNoCompression);
}

StreamStates EchoCompressor::CompressStream(InputAbstract *input,
Expand Down
4 changes: 2 additions & 2 deletions cvmfs/compression/compressor_echo.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <string>
#include "compressor.h"

namespace zlib {
namespace zip {

/**
* EchoCompressor is a compressor that just plainly copies data (like 'echo').
Expand All @@ -29,7 +29,7 @@ class EchoCompressor: public Compressor {
Compressor* Clone();
virtual std::string Describe();

static bool WillHandle(const zlib::Algorithms &alg);
static bool WillHandle(const zip::Algorithms &alg);

private:
bool is_healthy_;
Expand Down
6 changes: 3 additions & 3 deletions cvmfs/compression/compressor_zlib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

using namespace std; // NOLINT

namespace zlib {
namespace zip {

bool ZlibCompressor::WillHandle(const zlib::Algorithms &alg) {
bool ZlibCompressor::WillHandle(const zip::Algorithms &alg) {
return alg == kZlibDefault;
}

Expand All @@ -38,7 +38,7 @@ ZlibCompressor::ZlibCompressor(const Algorithms &alg)


Compressor* ZlibCompressor::Clone() {
ZlibCompressor* other = new ZlibCompressor(zlib::kZlibDefault);
ZlibCompressor* other = new ZlibCompressor(zip::kZlibDefault);
assert(stream_.avail_in == 0);
// Delete the other stream
int retcode = deflateEnd(&other->stream_);
Expand Down
Loading

0 comments on commit 8f69ffe

Please sign in to comment.