Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
rikyoz committed Oct 7, 2023
2 parents 3759449 + 58273a6 commit a90f5f7
Show file tree
Hide file tree
Showing 36 changed files with 274 additions and 266 deletions.
7 changes: 6 additions & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ body:
label: bit7z version
multiple: true
options:
- 4.0
- 4.0.x
- 3.2.x
- 3.1.x
- 3.0.x
Expand All @@ -35,15 +35,20 @@ body:
- BIT7Z_AUTO_PREFIX_LONG_PATHS
- BIT7Z_BUILD_TESTS
- BIT7Z_BUILD_DOCS
- BIT7Z_CUSTOM_7ZIP_PATH
- BIT7Z_DISABLE_ZIP_ASCII_PWD_CHECK
- BIT7Z_GENERATE_PIC
- BIT7Z_LINK_LIBCPP
- BIT7Z_PATH_SANITIZATION
- BIT7Z_REGEX_MATCHING
- BIT7Z_STATIC_RUNTIME
- BIT7Z_TESTS_FILESYSTEM
- BIT7Z_TESTS_NO_SANITIZERS
- BIT7Z_TESTS_USE_SYSTEM_7ZIP
- BIT7Z_USE_LEGACY_IUNKNOWN
- BIT7Z_USE_NATIVE_STRING
- BIT7Z_USE_STD_BYTE
- BIT7Z_USE_SYSTEM_CODEPAGE
- BIT7Z_VS_LIBNAME_OUTDIR_STYLE
validations:
required: false
Expand Down
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,10 @@ endif()
if( UNIX )
target_compile_definitions( ${LIB_TARGET} PRIVATE _LARGEFILE64_SOURCE _LARGEFILE_SOURCE _REENTRANT
EXTERNAL_CODECS ENV_UNIX BREAK_HANDLER USE_WIN_FILE )
target_compile_definitions( ${LIB_TARGET} PUBLIC _TIME_BITS=64 _FILE_OFFSET_BITS=64 )
target_compile_definitions( ${LIB_TARGET} PUBLIC _TIME_BITS=64 )
if ( ( NOT ANDROID ) OR ( ANDROID_PLATFORM GREATER_EQUAL 24 ) )
target_compile_definitions( ${LIB_TARGET} PUBLIC _FILE_OFFSET_BITS=64 )
endif()
target_link_libraries( ${LIB_TARGET} PUBLIC ${CMAKE_DL_LIBS} )
endif()

Expand Down
8 changes: 6 additions & 2 deletions include/bit7z/bitformat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ template< typename Enum >
using underlying_type_t = typename std::underlying_type< Enum >::type;

template< typename Enum >
inline constexpr auto to_underlying( Enum e ) noexcept -> underlying_type_t< Enum > {
return static_cast< underlying_type_t< Enum > >( e );
inline constexpr auto to_underlying( Enum enum_value ) noexcept -> underlying_type_t< Enum > {
return static_cast< underlying_type_t< Enum > >( enum_value );
}

inline constexpr auto operator|( FormatFeatures lhs, FormatFeatures rhs ) noexcept -> FormatFeatures {
Expand Down Expand Up @@ -176,6 +176,7 @@ extern const BitInFormat Auto;
#endif
extern const BitInFormat Rar; ///< RAR Archive Format
extern const BitInFormat Arj; ///< ARJ Archive Format
//NOLINTNEXTLINE(*-identifier-length)
extern const BitInFormat Z; ///< Z Archive Format
extern const BitInFormat Lzh; ///< LZH Archive Format
extern const BitInFormat Cab; ///< CAB Archive Format
Expand All @@ -193,6 +194,7 @@ extern const BitInFormat GPT; ///< GPT Archive Format
extern const BitInFormat Rar5; ///< RAR5 Archive Format
extern const BitInFormat IHex; ///< IHEX Archive Format
extern const BitInFormat Hxs; ///< HXS Archive Format
//NOLINTNEXTLINE(*-identifier-length)
extern const BitInFormat TE; ///< TE Archive Format
extern const BitInFormat UEFIc; ///< UEFIc Archive Format
extern const BitInFormat UEFIs; ///< UEFIs Archive Format
Expand All @@ -207,6 +209,7 @@ extern const BitInFormat Ntfs; ///< NTFS Archive Format
extern const BitInFormat Fat; ///< FAT Archive Format
extern const BitInFormat Mbr; ///< MBR Archive Format
extern const BitInFormat Vhd; ///< VHD Archive Format
//NOLINTNEXTLINE(*-identifier-length)
extern const BitInFormat Pe; ///< PE Archive Format
extern const BitInFormat Elf; ///< ELF Archive Format
extern const BitInFormat Macho; ///< MACHO Archive Format
Expand All @@ -226,6 +229,7 @@ extern const BitInFormat Cpio; ///< CPIO Archive Format
extern const BitInOutFormat Zip; ///< ZIP Archive Format
extern const BitInOutFormat BZip2; ///< BZIP2 Archive Format
extern const BitInOutFormat SevenZip; ///< 7Z Archive Format
//NOLINTNEXTLINE(*-identifier-length)
extern const BitInOutFormat Xz; ///< XZ Archive Format
extern const BitInOutFormat Wim; ///< WIM Archive Format
extern const BitInOutFormat Tar; ///< TAR Archive Format
Expand Down
14 changes: 7 additions & 7 deletions include/bit7z/bittypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ struct StringTraits;
template<>
struct StringTraits< char > {
template< class T >
static inline auto convertToString( T&& value ) -> std::string {
return std::to_string( std::forward< T >( value ) );
static inline auto convertToString( T value ) -> std::string {
return std::to_string( value );
}
};

template<>
struct StringTraits< wchar_t > {
template< class T >
static inline auto convertToString( T&& value ) -> std::wstring {
return std::to_wstring( std::forward< T >( value ) );
static inline auto convertToString( T value ) -> std::wstring {
return std::to_wstring( value );
}
};
/** @endcond */
Expand Down Expand Up @@ -97,9 +97,9 @@ using tstring = std::basic_string< tchar >;
using tregex = std::basic_regex< tchar >;
#endif

template< typename T >
inline auto to_tstring( T&& arg ) -> std::basic_string< tchar > {
return StringTraits< tchar >::convertToString( std::forward< T >( arg ) );
template< typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type >
inline auto to_tstring( T arg ) -> std::basic_string< tchar > {
return StringTraits< tchar >::convertToString( arg );
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/bitabstractarchivecreator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ auto is_valid_dictionary_size( BitCompressionMethod method, uint32_t dictionaryS
}
}

auto is_valid_word_size( const BitInOutFormat& format, BitCompressionMethod method, uint32_t wordSize ) noexcept -> bool {
auto is_valid_word_size( const BitInOutFormat& fmt, BitCompressionMethod method, uint32_t wordSize ) noexcept -> bool {
constexpr auto kMinLzmaWordSize = 5u;
constexpr auto kMaxLzmaWordSize = 273u;
constexpr auto kMinPpmdWordSize = 2u;
Expand All @@ -78,8 +78,8 @@ auto is_valid_word_size( const BitInOutFormat& format, BitCompressionMethod meth
return wordSize >= kMinLzmaWordSize && wordSize <= kMaxLzmaWordSize;
case BitCompressionMethod::Ppmd:
return wordSize >= kMinPpmdWordSize && wordSize <=
( format == BitFormat::Zip ? kMaxZipPpmdWordSize
: kMax7zPpmdWordSize );
( fmt == BitFormat::Zip ? kMaxZipPpmdWordSize
: kMax7zPpmdWordSize );
case BitCompressionMethod::Deflate64:
return wordSize >= kMinDeflateWordSize && wordSize <= kMaxDeflate64WordSize;
case BitCompressionMethod::Deflate:
Expand Down
6 changes: 4 additions & 2 deletions src/bitarchiveeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "internal/fsitem.hpp"
#include "internal/renameditem.hpp"
#include "internal/stdinputitem.hpp"
#include "internal/util.hpp"

namespace bit7z {

Expand Down Expand Up @@ -61,7 +62,7 @@ void BitArchiveEditor::renameItem( const tstring& oldPath, const tstring& newPat
void BitArchiveEditor::updateItem( uint32_t index, const tstring& inFile ) {
checkIndex( index );
auto itemName = inputArchive()->itemProperty( index, BitProperty::Path );
mEditedItems[ index ] = std::make_unique< FilesystemItem >( inFile, itemName.getNativeString() );
mEditedItems[ index ] = std::make_unique< FilesystemItem >( tstring_to_path( inFile ), itemName.getNativeString() );
}

void BitArchiveEditor::updateItem( uint32_t index, const std::vector< byte_t >& inBuffer ) {
Expand All @@ -77,7 +78,8 @@ void BitArchiveEditor::updateItem( uint32_t index, std::istream& inStream ) {
}

void BitArchiveEditor::updateItem( const tstring& itemPath, const tstring& inFile ) {
mEditedItems[ findItem( itemPath ) ] = std::make_unique< FilesystemItem >( inFile, itemPath );
mEditedItems[ findItem( itemPath ) ] = std::make_unique< FilesystemItem >( tstring_to_path( inFile ),
tstring_to_path( itemPath ) );
}

void BitArchiveEditor::updateItem( const tstring& itemPath, const std::vector< byte_t >& inBuffer ) {
Expand Down
2 changes: 1 addition & 1 deletion src/bitarchiveitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ auto BitArchiveItem::crc() const -> uint32_t {
// On MSVC, these macros are not defined!
#if !defined(S_ISLNK) && defined(S_IFMT)
#ifndef S_IFLNK
constexpr auto S_IFLNK = 0120000;
constexpr auto S_IFLNK = 0xA000;
#endif
#define S_ISLNK( m ) (((m) & S_IFMT) == S_IFLNK)
#endif
Expand Down
4 changes: 1 addition & 3 deletions src/bitarchivereader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
#include <numeric>

#include "bitarchivereader.hpp"
#include "internal/extractcallback.hpp"

#include <7zip/PropID.h>
#include "internal/operationresult.hpp"

using namespace bit7z;

Expand Down
2 changes: 1 addition & 1 deletion src/bitinputarchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,4 +387,4 @@ auto BitInputArchive::ConstIterator::operator->() noexcept -> BitInputArchive::C
BitInputArchive::ConstIterator::ConstIterator( uint32_t itemIndex, const BitInputArchive& itemArchive ) noexcept
: mItemOffset( itemIndex, itemArchive ) {}

}
} // namespace bit7z
16 changes: 10 additions & 6 deletions src/bititemsvector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "internal/bufferitem.hpp"
#include "internal/fsindexer.hpp"
#include "internal/stdinputitem.hpp"
#include "internal/util.hpp"

using namespace bit7z;
using filesystem::FilesystemItem;
Expand All @@ -38,15 +39,17 @@ 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 ) {
const FilesystemItem item{ filePath, options.retainFolderStructure ? filePath : BIT7Z_STRING( "" ), symlinkPolicy };
const FilesystemItem item{ filePath,
options.retainFolderStructure ? tstring_to_path( filePath ) : fs::path{},
symlinkPolicy };
indexItem( item, options );
}
}

void BitItemsVector::indexPathsMap( const std::map< tstring, tstring >& inPaths, IndexingOptions options ) {
const auto symlinkPolicy = options.followSymlinks ? SymlinkPolicy::Follow : SymlinkPolicy::DoNotFollow;
for ( const auto& filePair : inPaths ) {
const FilesystemItem item{ fs::path( filePair.first ), fs::path( filePair.second ), symlinkPolicy };
const FilesystemItem item{ tstring_to_path( filePair.first ), tstring_to_path( filePair.second ), symlinkPolicy };
indexItem( item, options );
}
}
Expand All @@ -67,20 +70,21 @@ void BitItemsVector::indexItem( const FilesystemItem& item, IndexingOptions opti
}

void BitItemsVector::indexFile( const tstring& inFile, const tstring& name, bool followSymlinks ) {
if ( fs::is_directory( inFile ) ) {
const fs::path filePath = tstring_to_path( inFile );
if ( fs::is_directory( filePath ) ) {
throw BitException( "Input path points to a directory, not a file",
std::make_error_code( std::errc::invalid_argument ), inFile );
}
const auto symlinkPolicy = followSymlinks ? SymlinkPolicy::Follow : SymlinkPolicy::DoNotFollow;
mItems.emplace_back( std::make_unique< FilesystemItem >( inFile, name, symlinkPolicy ) );
mItems.emplace_back( std::make_unique< FilesystemItem >( filePath, tstring_to_path( name ), symlinkPolicy ) );
}

void BitItemsVector::indexBuffer( const vector< byte_t >& inBuffer, const tstring& name ) {
mItems.emplace_back( std::make_unique< BufferItem >( inBuffer, name ) );
mItems.emplace_back( std::make_unique< BufferItem >( inBuffer, tstring_to_path( name ) ) );
}

void BitItemsVector::indexStream( std::istream& inStream, const tstring& name ) {
mItems.emplace_back( std::make_unique< StdInputItem >( inStream, name ) );
mItems.emplace_back( std::make_unique< StdInputItem >( inStream, tstring_to_path( name ) ) );
}

auto BitItemsVector::size() const -> size_t {
Expand Down
12 changes: 6 additions & 6 deletions src/bitoutputarchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ void BitOutputArchive::addFiles( const tstring& inDir, const tstring& filter, Fi
options.retainFolderStructure = mArchiveCreator.retainDirectories();
options.onlyFiles = true;
options.followSymlinks = !mArchiveCreator.storeSymbolicLinks();
mNewItemsVector.indexDirectory( inDir, filter, policy, options );
mNewItemsVector.indexDirectory( tstring_to_path( inDir ), filter, policy, options );
}

void BitOutputArchive::addDirectory( const tstring& inDir ) {
IndexingOptions options{};
options.retainFolderStructure = mArchiveCreator.retainDirectories();
options.followSymlinks = !mArchiveCreator.storeSymbolicLinks();
mNewItemsVector.indexDirectory( inDir, BIT7Z_STRING( "" ), FilterPolicy::Include, options );
mNewItemsVector.indexDirectory( tstring_to_path( inDir ), BIT7Z_STRING( "" ), FilterPolicy::Include, options );
}

auto BitOutputArchive::initOutArchive() const -> CMyComPtr< IOutArchive > {
Expand Down Expand Up @@ -185,7 +185,7 @@ void BitOutputArchive::compressOut( IOutArchive* outArc,
void BitOutputArchive::compressToFile( const fs::path& outFile, UpdateCallback* updateCallback ) {
// Note: if mInputArchive != nullptr, newArc will actually point to the same IInArchive object used by the old_arc
// (see initUpdatableArchive function of BitInputArchive)!
const bool updatingArchive = mInputArchive != nullptr && mInputArchive->archivePath() == outFile;
const bool updatingArchive = mInputArchive != nullptr && tstring_to_path( mInputArchive->archivePath() ) == outFile;
const CMyComPtr< IOutArchive > newArc = initOutArchive();
CMyComPtr< IOutStream > outStream = initOutFileStream( outFile, updatingArchive );
compressOut( newArc, outStream, updateCallback );
Expand Down Expand Up @@ -222,7 +222,7 @@ void BitOutputArchive::compressToFile( const fs::path& outFile, UpdateCallback*

void BitOutputArchive::compressTo( const tstring& outFile ) {
using namespace bit7z::filesystem;
const fs::path outPath = FORMAT_LONG_PATH( outFile );
const fs::path outPath = tstring_to_path( outFile );
std::error_code error;
if ( fs::exists( outPath, error ) ) {
const OverwriteMode overwriteMode = mArchiveCreator.overwriteMode();
Expand Down Expand Up @@ -322,12 +322,12 @@ auto BitOutputArchive::itemStream( InputIndex index, ISequentialInStream** inStr

const HRESULT res = newItem.getStream( inStream );
if ( FAILED( res ) ) {
auto path = newItem.path();
auto path = tstring_to_path( newItem.path() );
std::error_code error;
if ( fs::exists( path, error ) ) {
error = std::make_error_code( std::errc::file_exists );
}
mFailedFiles.emplace_back( path, error );
mFailedFiles.emplace_back( path_to_tstring( path ), error );
}
return res;
}
Expand Down
16 changes: 8 additions & 8 deletions src/internal/cfixedbufferoutstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
#ifdef __cpp_if_constexpr

template< class T, class U >
constexpr auto cmp_less( T t, U u ) noexcept -> bool {
constexpr auto cmp_less( T first, U second ) noexcept -> bool {
using UT = std::make_unsigned_t< T >;
using UU = std::make_unsigned_t< U >;
if constexpr ( std::is_signed< T >::value == std::is_signed< U >::value ) {
return t < u;
return first < second;
} else if constexpr ( std::is_signed< T >::value ) {
return t < 0 || UT( t ) < u;
return first < 0 || UT( first ) < second;
} else {
return u >= 0 && t < UU( u );
return second >= 0 && first < UU( second );
}
}

Expand All @@ -56,13 +56,13 @@ cmp_less( T t, U u ) noexcept -> std::enable_if_t< !std::is_signed< T >::value &
#endif

template< class T, class U >
constexpr auto cmp_greater( T t, U u ) noexcept -> bool {
return cmp_less( u, t );
constexpr auto cmp_greater( T first, U second ) noexcept -> bool {
return cmp_less( second, first ); // NOLINT(*-suspicious-call-argument)
}

template< class T, class U >
constexpr auto cmp_greater_equal( T t, U u ) noexcept -> bool {
return !cmp_less( t, u );
constexpr auto cmp_greater_equal( T first, U second ) noexcept -> bool {
return !cmp_less( first, second );
}

namespace bit7z {
Expand Down
4 changes: 0 additions & 4 deletions src/internal/cstdinstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ STDMETHODIMP CStdInStream::Seek( Int64 offset, UInt32 seekOrigin, UInt64* newPos
std::ios_base::seekdir way; // NOLINT(cppcoreguidelines-init-variables)
RINOK( to_seekdir( seekOrigin, way ) )

/*if ( offset < 0 ) { // GZip uses negative offsets!
return HRESULT_WIN32_ERROR_NEGATIVE_SEEK;
}*/

mInputStream.seekg( static_cast< std::istream::off_type >( offset ), way );

if ( mInputStream.bad() ) {
Expand Down
4 changes: 0 additions & 4 deletions src/internal/cstdoutstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ STDMETHODIMP CStdOutStream::Seek( Int64 offset, UInt32 seekOrigin, UInt64* newPo
std::ios_base::seekdir way; // NOLINT(cppcoreguidelines-init-variables)
RINOK( to_seekdir( seekOrigin, way ) )

/*if ( offset < 0 ) { //Tar sometimes uses negative offsets
return HRESULT_WIN32_ERROR_NEGATIVE_SEEK;
}*/

mOutputStream.seekp( static_cast< std::ostream::off_type >( offset ), way );

if ( mOutputStream.bad() ) {
Expand Down
6 changes: 4 additions & 2 deletions src/internal/fileextractcallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ namespace bit7z {

FileExtractCallback::FileExtractCallback( const BitInputArchive& inputArchive, const tstring& directoryPath )
: ExtractCallback( inputArchive ),
mInFilePath( inputArchive.archivePath() ),
mDirectoryPath( directoryPath ),
mInFilePath( tstring_to_path( inputArchive.archivePath() ) ),
mDirectoryPath( tstring_to_path( directoryPath ) ),
mRetainDirectories( inputArchive.handler().retainDirectories() ) {}

void FileExtractCallback::releaseStream() {
Expand Down Expand Up @@ -88,6 +88,8 @@ auto FileExtractCallback::getOutStream( uint32_t index, ISequentialOutStream** o

if ( !isItemFolder( index ) ) { // File
if ( mHandler.fileCallback() ) {
// Here we don't use the path_to_tstring function to avoid allocating a string object
// when using BIT7Z_USE_NATIVE_STRING.
#if defined( BIT7Z_USE_NATIVE_STRING )
const auto& filePathString = filePath.native();
#elif !defined( BIT7Z_USE_SYSTEM_CODEPAGE )
Expand Down
6 changes: 3 additions & 3 deletions src/internal/fsitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ namespace filesystem {
/* NOTES:
* 1) mPath contains the path to the file, including the filename. It can be relative or absolute, according to what
* the user passes as the path parameter in the constructor.
* 2) mSearchPath contains the search path in which the item was found (e.g., if FilesystemIndexer is searching for items in
* "foo/bar/", each FilesystemItem created for the elements it found will have mSearchPath == "foo/bar").
* As in mPath, mSearchPath does not contain trailing / or \! *
* 2) mSearchPath contains the search path in which the item was found (e.g., if FilesystemIndexer is searching
* for items in "foo/bar/", each FilesystemItem created for the elements it found will have
* mSearchPath == "foo/bar"). As in mPath, mSearchPath does not contain trailing / or \! *
* 3) mInArchivePath is the path of the item in the archive. If not already given (i.e., the user doesn't want to custom
* the path of the file in the archive), the path in the archive is calculated from mPath and mSearchPath
* (see inArchivePath() method). */
Expand Down
Loading

0 comments on commit a90f5f7

Please sign in to comment.