-
Notifications
You must be signed in to change notification settings - Fork 528
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dropped libarchive dependency and added internal tar extraction class…
… + libzip for zip decompression
- Loading branch information
Paolo
committed
Mar 16, 2021
1 parent
e877c63
commit d94a628
Showing
10 changed files
with
361 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#ifndef TAR_H | ||
#define TAR_H | ||
|
||
#include <string> | ||
#include <vector> | ||
#include <stdexcept> | ||
#include <cmath> | ||
|
||
|
||
enum tar_type_flag { | ||
REGTYPE = '0', /* regular file */ | ||
AREGTYPE = '\0', /* regular file */ | ||
LNKTYPE = '1', /* link */ | ||
SYMTYPE = '2', /* reserved */ | ||
CHRTYPE = '3', /* character special */ | ||
BLKTYPE = '4', /* block special */ | ||
DIRTYPE = '5', /* directory */ | ||
FIFOTYPE = '6', /* FIFO special */ | ||
CONTTYPE = '7', /* reserved */ | ||
XHDTYPE = 'x', /* Extended header referring to the next file in the archive */ | ||
XGLTYPE = 'g' /* Global extended header */ | ||
}; | ||
|
||
struct tar_posix_header | ||
{ /* byte offset */ | ||
char name[100]; /* 0 */ | ||
char mode[8]; /* 100 */ | ||
char uid[8]; /* 108 */ | ||
char gid[8]; /* 116 */ | ||
char size[12]; /* 124 */ | ||
char mtime[12]; /* 136 */ | ||
char chksum[8]; /* 148 */ | ||
char typeflag; /* 156 */ | ||
char linkname[100]; /* 157 */ | ||
char magic[6]; /* 257 */ | ||
char version[2]; /* 263 */ | ||
char uname[32]; /* 265 */ | ||
char gname[32]; /* 297 */ | ||
char devmajor[8]; /* 329 */ | ||
char devminor[8]; /* 337 */ | ||
char prefix[155]; /* 345 */ | ||
char pad[12]; /* 500 */ | ||
/* 512 */ | ||
}; | ||
|
||
class Tar | ||
{ | ||
public: | ||
|
||
struct File | ||
{ | ||
std::string name; | ||
int mode; | ||
int ownerId; | ||
int groupId; | ||
int size; | ||
int lastModified; | ||
tar_type_flag typeflag; | ||
std::string linkedName; | ||
size_t position; | ||
}; | ||
|
||
Tar(std::string filename); | ||
~Tar(); | ||
void extract(const File& file, std::string to); | ||
bool extract(std::string fileName, std::string to); | ||
const std::vector<File>& getFileList() const; | ||
private: | ||
FILE* tarfile = NULL; | ||
std::vector<File> fileList; | ||
|
||
int oct_to_int(char* oct); | ||
int oct_to_sz(char* oct); | ||
|
||
static constexpr int EXTRACT_BUFFER_SZ = 1024 * 16; | ||
}; | ||
|
||
#endif // TAR_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
FIND_PATH(LIBZIP_INCLUDE_DIR | ||
zip.h | ||
"$ENV{LIB_DIR}/include" | ||
"$ENV{INCLUDE}" | ||
/usr/local/include | ||
/usr/include | ||
) | ||
|
||
FIND_PATH(LIBZIP_CONF_INCLUDE_DIR | ||
zipconf.h | ||
"$ENV{LIB_DIR}/include" | ||
"$ENV{LIB_DIR}/lib/libzip/include" | ||
"$ENV{LIB}/lib/libzip/include" | ||
/usr/local/lib/libzip/include | ||
/usr/lib/libzip/include | ||
/usr/local/include | ||
/usr/include | ||
"$ENV{INCLUDE}" | ||
) | ||
|
||
FIND_LIBRARY(LIBZIP_LIBRARY NAMES zip PATHS "$ENV{LIB_DIR}/lib" "$ENV{LIB}" /usr/local/lib /usr/lib ) | ||
|
||
INCLUDE(FindPackageHandleStandardArgs) | ||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibZip DEFAULT_MSG | ||
LIBZIP_LIBRARY LIBZIP_INCLUDE_DIR LIBZIP_CONF_INCLUDE_DIR) | ||
|
||
SET(LIBZIP_INCLUDE_DIRS ${LIBZIP_INCLUDE_DIR} ${LIBZIP_CONF_INCLUDE_DIR}) | ||
MARK_AS_ADVANCED(LIBZIP_LIBRARY LIBZIP_INCLUDE_DIR LIBZIP_CONF_INCLUDE_DIR LIBZIP_INCLUDE_DIRS) | ||
|
||
IF (LIBZIP_FOUND) | ||
MESSAGE(STATUS "Found libzip: ${LIBZIP_LIBRARY}") | ||
ELSE (LIPZIP_FOUND) | ||
MESSAGE(FATAL_ERROR "Could not find libzip") | ||
ENDIF (LIBZIP_FOUND) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.