Skip to content

Commit

Permalink
Merge branch 'hotfix/v4.0.7' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
rikyoz committed May 16, 2024
2 parents 67b3db0 + 31b3809 commit dfe2c7c
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 42 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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" )
Expand Down
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"`).

Expand All @@ -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"`).

<details>
<summary>Expand for more details!</summary>
<summary>Expand for more details</summary>

_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).

</details>

### 🌐 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:
Expand Down
25 changes: 15 additions & 10 deletions include/bit7z/bitarchiveeditor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,33 +146,38 @@ 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,
* then the items within the folder will also be deleted.
*
* @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 );

Expand Down
9 changes: 3 additions & 6 deletions include/bit7z/bitoutputarchive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 5 additions & 2 deletions src/bitarchivereader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}
Expand Down
5 changes: 3 additions & 2 deletions src/bititemsvector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down
22 changes: 9 additions & 13 deletions tests/src/test_dateutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand All @@ -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 );
Expand All @@ -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 );
}
}
Expand Down

0 comments on commit dfe2c7c

Please sign in to comment.