diff --git a/CMakeLists.txt b/CMakeLists.txt index f24ea597..ca22d5b3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,10 +2,10 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at https://mozilla.org/MPL/2.0/. -cmake_minimum_required( VERSION 3.11 ) +cmake_minimum_required( VERSION 3.14 ) project( bit7z - VERSION 4.0.6 + VERSION 4.0.7 DESCRIPTION "A C++ static library offering a clean and simple interface to the 7-zip/p7zip shared libraries" HOMEPAGE_URL "https://github.com/rikyoz/bit7z/" ) set( CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "ON" ) diff --git a/README.md b/README.md index b06bbaad..fb5a48cf 100644 --- a/README.md +++ b/README.md @@ -290,11 +290,11 @@ add_subdirectory( ${CMAKE_SOURCE_DIR}/third_party/bit7z ) target_link_libraries( ${YOUR_TARGET} PRIVATE bit7z ) ``` -The library is highly customizable: for a detailed list of the available build options, please refer to the [wiki](https://github.com/rikyoz/bit7z/wiki/Building-the-library). +The library is highly customizable: for a detailed list of the available build options, please refer to the [wiki](https://github.com/rikyoz/bit7z/wiki/Building-the-library#%EF%B8%8F-build-options). -### πŸ“‘ 7-zip Version +### πŸ“Œ 7-zip Version -While configuring bit7z via CMake, it automatically downloads the latest version of 7-zip currently supported by the library. +While configuring bit7z via CMake, it automatically downloads the latest version of 7-zip supported by the library. Optionally, you can specify a different version of 7-zip via the CMake option `BIT7Z_7ZIP_VERSION` (e.g., `-DBIT7Z_7ZIP_VERSION="22.01"`). @@ -304,16 +304,26 @@ Please note that, in general, it is best to use the same version of 7-zip of the #### Using 7-zip v23.01 on Linux and macOS +By default, bit7z is compatible with the `7z.so` from 7-zip v23.01 and later. + +If you plan to use the `7z.so` from p7zip or 7-zip v22.01 and earlier instead, you have two ways to make bit7z compatible: + ++ Configure bit7z with the CMake option `-DBIT7Z_USE_LEGACY_IUNKNOWN=ON`; _or_ ++ Configure bit7z for 7-zip v22.01 (i.e., `-DBIT7Z_7ZIP_VERSION="22.01"`). +
- Expand for more details! + Expand for more details -_On Linux and macOS_, 7-zip v23.01 introduced breaking changes to the IUnknown interface. If you build bit7z for such a version of 7-zip (the default), it will not support using the shared libraries from previous versions of 7-zip (or from p7zip). Conversely, bit7z made for earlier versions of 7-zip or for p7zip is incompatible with the shared libraries from 7-zip v23.01 and later. +_On Linux and macOS_, 7-zip v23.01 introduced breaking changes to the IUnknown interface. +As a result, if you build bit7z for such a version of 7-zip (the default), it will not support using the shared libraries from previous versions of 7-zip (or from p7zip). +Conversely, bit7z made for earlier versions of 7-zip or for p7zip is incompatible with the shared libraries from 7-zip v23.01 and later. -You can build the shared libraries of 7-zip v23.01 in a backward-compatible mode by defining the macro `Z7_USE_VIRTUAL_DESTRUCTOR_IN_IUNKNOWN`. If this is your case, you can build bit7z for v23.01 using the option `BIT7Z_USE_LEGACY_IUNKNOWN` (in this case, bit7z will be compatible also with previous versions of 7-zip/p7zip). +You can build the shared libraries of 7-zip v23.01 in a backward-compatible mode by defining the macro `Z7_USE_VIRTUAL_DESTRUCTOR_IN_IUNKNOWN`. +If this is your case, you'll need to enable the `BIT7Z_USE_LEGACY_IUNKNOWN` to make bit7z work (in this case, bit7z will be compatible also with previous versions of 7-zip/p7zip).
-### 🌐 String Encoding +### πŸ—ΊοΈ String Encoding By default, bit7z follows the [UTF-8 Everywhere Manifesto](http://utf8everywhere.org/) to simplify the use of the library within cross-platform projects. In short, this means that: diff --git a/include/bit7z/bitarchiveeditor.hpp b/include/bit7z/bitarchiveeditor.hpp index adfb18d6..08b8277d 100644 --- a/include/bit7z/bitarchiveeditor.hpp +++ b/include/bit7z/bitarchiveeditor.hpp @@ -146,7 +146,7 @@ class BIT7Z_MAYBE_UNUSED BitArchiveEditor final : public BitArchiveWriter { void updateItem( const tstring& itemPath, std::istream& inStream ); /** - * @brief Marks the item at the given index as deleted. + * @brief Marks as deleted the item at the given index. * * @note By default, if the item is a folder, only its metadata is deleted, not the files within it. * If instead the policy is set to DeletePolicy::RecurseDirs, @@ -154,25 +154,30 @@ class BIT7Z_MAYBE_UNUSED BitArchiveEditor final : public BitArchiveWriter { * * @param index the index of the item to be deleted. * @param policy the policy to be used when deleting items. + * + * @throws BitException if the index is invalid. */ void deleteItem( uint32_t index, DeletePolicy policy = DeletePolicy::ItemOnly ); /** - * @brief Marks the item(s) with the given path (in the archive) as deleted. + * @brief Marks as deleted the archive's item(s) with the specified path. * - * @note By default, if a matching item is a folder, only its metadata is deleted, not the files within it. - * If instead the policy is set to DeletePolicy::RecurseDirs, - * then the items within the folder will also be deleted. + * @note By default, if the marked item is a folder, only its metadata will be deleted, not the files within it. + * To delete the folder contents as well, set the `policy` to `DeletePolicy::RecurseDirs`. * - * @note If the specified path ends with a trailing path separator, only matching folders will be deleted - * (and the items they contain will be deleted according to the policy). + * @note The specified path must not begin with a path separator. * - * @note Generally, an archive may contain two or more items with the same paths; - * if this is the case, all of them will be marked as deleted if they match the given path - * (the same rules about trailing path separators and policy apply). + * @note A path with a trailing separator will _only_ be considered if + * the policy is DeletePolicy::RecurseDirs, and will only match folders; + * with DeletePolicy::ItemOnly, no item will match a path with a trailing separator. + * + * @note Generally, archives may contain multiple items with the same paths. + * If this is the case, all matching items will be marked as deleted according to the specified policy. * * @param itemPath the path (in the archive) of the item to be deleted. * @param policy the policy to be used when deleting items. + * + * @throws BitException if the specified path is empty or invalid, or if no matching item could be found. */ void deleteItem( const tstring& itemPath, DeletePolicy policy = DeletePolicy::ItemOnly ); diff --git a/include/bit7z/bitoutputarchive.hpp b/include/bit7z/bitoutputarchive.hpp index 52cc7a6d..3b4edb56 100644 --- a/include/bit7z/bitoutputarchive.hpp +++ b/include/bit7z/bitoutputarchive.hpp @@ -171,13 +171,10 @@ class BitOutputArchive { * @brief Adds all the files inside the given directory path that match the given wildcard filter. * * @param inDir the directory where to search for files to be added to the output archive. - * @param filter (optional) the wildcard filter to be used for searching the files. - * @param recursive (optional) recursively search the files in the given directory - * and all of its subdirectories. + * @param filter the wildcard filter to be used for searching the files. + * @param recursive recursively search the files in the given directory and all of its subdirectories. */ - void addFiles( const tstring& inDir, - const tstring& filter = BIT7Z_STRING( "*" ), - bool recursive = true ); + void addFiles( const tstring& inDir, const tstring& filter, bool recursive ); /** * @brief Adds all the files inside the given directory path that match the given wildcard filter. diff --git a/src/bitarchivereader.cpp b/src/bitarchivereader.cpp index c9c5ae98..d2492f72 100644 --- a/src/bitarchivereader.cpp +++ b/src/bitarchivereader.cpp @@ -64,8 +64,11 @@ auto BitArchiveReader::archiveProperties() const -> std::map< BitProperty, BitPr } auto BitArchiveReader::items() const -> std::vector< BitArchiveItemInfo > { + const auto count = itemsCount(); + std::vector< BitArchiveItemInfo > result; - for ( uint32_t i = 0; i < itemsCount(); ++i ) { + result.reserve( count ); + for ( uint32_t i = 0; i < count; ++i ) { BitArchiveItemInfo item( i ); for ( uint32_t j = kpidNoProperty; j <= kpidCopyLink; ++j ) { // We cast property twice (here and in archiveProperty), to make the code is easier to read. @@ -75,7 +78,7 @@ auto BitArchiveReader::items() const -> std::vector< BitArchiveItemInfo > { item.setProperty( property, propertyValue ); } } - result.push_back( item ); + result.push_back( std::move( item ) ); } return result; } diff --git a/src/bititemsvector.cpp b/src/bititemsvector.cpp index 951b3947..016cc3d9 100644 --- a/src/bititemsvector.cpp +++ b/src/bititemsvector.cpp @@ -50,9 +50,10 @@ void BitItemsVector::indexDirectory( const fs::path& inDir, void BitItemsVector::indexPaths( const std::vector< tstring >& inPaths, IndexingOptions options ) { const auto symlinkPolicy = options.followSymlinks ? SymlinkPolicy::Follow : SymlinkPolicy::DoNotFollow; - for ( const auto& filePath : inPaths ) { + for ( const auto& inputPath : inPaths ) { + const auto filePath = tstring_to_path( inputPath ); const FilesystemItem item{ filePath, - options.retainFolderStructure ? tstring_to_path( filePath ) : fs::path{}, + options.retainFolderStructure ? filePath : fs::path{}, symlinkPolicy }; indexItem( item, options ); } diff --git a/tests/src/test_dateutil.cpp b/tests/src/test_dateutil.cpp index dadff23e..2375f865 100644 --- a/tests/src/test_dateutil.cpp +++ b/tests/src/test_dateutil.cpp @@ -24,7 +24,7 @@ using namespace bit7z; struct DateConversionTest { const char* name; - std::time_t dateTime; + std::int64_t dateTime; // Using std::int64_t instead of std::time_t to use 64-bit time on x86 FILETIME fileTime; }; @@ -37,7 +37,6 @@ TEST_CASE( "fsutil: Date conversions", "[fsutil][date functions]" ) { DateConversionTest{ "1 January 1970, 00:00", 0, { 3577643008, 27111902 } } ); DYNAMIC_SECTION( "Date: " << testDate.name ) { - #ifndef _WIN32 SECTION( "From std::time_t to FILETIME" ) { auto output = time_to_FILETIME( testDate.dateTime ); @@ -46,20 +45,17 @@ TEST_CASE( "fsutil: Date conversions", "[fsutil][date functions]" ) { } #endif - SECTION( "From FILETIME...") { - std::time_t output{}; #ifndef _WIN32 - SECTION( "...to std::filesystem::file_time_type" ) { - auto result = FILETIME_to_file_time_type( testDate.fileTime ); - output = std::time_t{ duration_cast< seconds >( result.time_since_epoch() ).count() }; - } + SECTION( "From FILETIME to std::filesystem::file_time_type" ) { + auto result = FILETIME_to_file_time_type( testDate.fileTime ); + auto output = duration_cast< seconds >( result.time_since_epoch() ).count(); + REQUIRE( output == testDate.dateTime ); + } #endif - SECTION( "...to bit7z::time_type" ) { - auto result = FILETIME_to_time_type( testDate.fileTime ); - output = bit7z::time_type::clock::to_time_t( result ); - } - + SECTION( "From FILETIME to bit7z::time_type" ) { + auto result = FILETIME_to_time_type( testDate.fileTime ); + auto output = bit7z::time_type::clock::to_time_t( result ); REQUIRE( output == testDate.dateTime ); } }