Support features sets

This commit is contained in:
Marcus Holland-Moritz 2023-07-28 14:33:42 +02:00
parent 7a9bd01775
commit 4e0d2ba25e
5 changed files with 121 additions and 1 deletions

View File

@ -361,6 +361,7 @@ list(
src/dwarfs/console_writer.cpp
src/dwarfs/entry.cpp
src/dwarfs/error.cpp
src/dwarfs/features.cpp
src/dwarfs/file_scanner.cpp
src/dwarfs/file_stat.cpp
src/dwarfs/file_type.cpp

31
include/dwarfs/features.h Normal file
View File

@ -0,0 +1,31 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/**
* \author Marcus Holland-Moritz (github@mhxnet.de)
* \copyright Copyright (c) Marcus Holland-Moritz
*
* This file is part of dwarfs.
*
* dwarfs is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* dwarfs is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with dwarfs. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <set>
#include <string>
namespace dwarfs {
std::set<std::string> get_unsupported_features(std::set<std::string> features);
} // namespace dwarfs

59
src/dwarfs/features.cpp Normal file
View File

@ -0,0 +1,59 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/**
* \author Marcus Holland-Moritz (github@mhxnet.de)
* \copyright Copyright (c) Marcus Holland-Moritz
*
* This file is part of dwarfs.
*
* dwarfs is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* dwarfs is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with dwarfs. If not, see <https://www.gnu.org/licenses/>.
*/
#include <algorithm>
#include <iterator>
#include "dwarfs/features.h"
namespace dwarfs {
namespace {
std::set<std::string> supported_features{
#ifdef DWARFS_HAVE_LIBZSTD
"zstd",
#endif
#ifdef DWARFS_HAVE_LIBLZ4
"lz4",
#endif
#ifdef DWARFS_HAVE_LIBLZMA
"lzma",
#endif
#ifdef DWARFS_HAVE_LIBBROTLI
"brotli",
#endif
#ifdef DWARFS_HAVE_FLAC
"flac",
#endif
};
} // namespace
std::set<std::string> get_unsupported_features(std::set<std::string> features) {
std::set<std::string> rv;
std::set_difference(features.begin(), features.end(),
supported_features.begin(), supported_features.end(),
std::inserter(rv, rv.end()));
return rv;
}
} // namespace dwarfs

View File

@ -44,6 +44,7 @@
#include <fsst.h>
#include "dwarfs/error.h"
#include "dwarfs/features.h"
#include "dwarfs/file_stat.h"
#include "dwarfs/fstypes.h"
#include "dwarfs/logger.h"
@ -136,6 +137,20 @@ map_frozen(std::span<uint8_t const> schema, std::span<uint8_t const> data) {
return ret;
}
MappedFrozen<thrift::metadata::metadata>
check_frozen(MappedFrozen<thrift::metadata::metadata> meta) {
if (meta.features()) {
auto unsupported = get_unsupported_features(meta.features()->thaw());
if (!unsupported.empty()) {
DWARFS_THROW(runtime_error,
fmt::format("file system uses the following features "
"unsupported by this build: {}",
boost::join(unsupported, ", ")));
}
}
return meta;
}
void analyze_frozen(std::ostream& os,
MappedFrozen<thrift::metadata::metadata> const& meta,
size_t total_size, int detail) {
@ -302,7 +317,8 @@ class metadata_ final : public metadata_v2::impl {
std::span<uint8_t const> data, metadata_options const& options,
int inode_offset, bool force_consistency_check)
: data_(data)
, meta_(map_frozen<thrift::metadata::metadata>(schema, data_))
, meta_(
check_frozen(map_frozen<thrift::metadata::metadata>(schema, data_)))
, global_(lgr, &meta_,
options.check_consistency || force_consistency_check)
, root_(dir_entry_view::from_dir_entry_index(0, &global_))

View File

@ -350,6 +350,19 @@ struct metadata {
25: optional string_table compact_symlinks
//=========================================================//
// fields added with dwarfs-0.7.0, file system version 2.5 //
//=========================================================//
// preferred path separator of original file system
26: optional UInt32 preferred_path_separator
//=========================================================//
// fields added with dwarfs-0.7.3, file system version 2.5 //
//=========================================================//
// The set of features used in this file system image. As long
// as an older binary supports all features, it will be able
// to use images created with newer versions.
27: optional set<string> features
}