summaryrefslogtreecommitdiffstats
path: root/tarlz.h
diff options
context:
space:
mode:
Diffstat (limited to 'tarlz.h')
-rw-r--r--tarlz.h76
1 files changed, 49 insertions, 27 deletions
diff --git a/tarlz.h b/tarlz.h
index e9371ec..b2d8ccd 100644
--- a/tarlz.h
+++ b/tarlz.h
@@ -1,5 +1,5 @@
/* Tarlz - Archiver with multimember lzip compression
- Copyright (C) 2013-2020 Antonio Diaz Diaz.
+ Copyright (C) 2013-2021 Antonio Diaz Diaz.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -15,6 +15,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <sys/types.h>
+
#define max_file_size ( LLONG_MAX - header_size )
enum { header_size = 512 };
typedef uint8_t Tar_header[header_size];
@@ -71,6 +73,14 @@ inline bool dotdot_at_i( const char * const filename, const int i )
}
+inline bool contains_dotdot( const char * const filename )
+ {
+ for( int i = 0; filename[i]; ++i )
+ if( dotdot_at_i( filename, i ) ) return true;
+ return false;
+ }
+
+
class Resizable_buffer
{
char * p;
@@ -103,6 +113,7 @@ public:
class Extended // stores metadata from/for extended records
{
+ static std::vector< std::string > unknown_keywords; // already diagnosed
std::string linkpath_; // these are the real metadata
std::string path_;
long long file_size_; // >= 0 && <= max_file_size
@@ -119,6 +130,8 @@ class Extended // stores metadata from/for extended records
mutable bool crc_present_;
void calculate_sizes() const;
+ void unknown_keyword( const char * const buf,
+ const unsigned long long size ) const;
public:
static const std::string crc_record;
@@ -189,6 +202,14 @@ public:
crc = c;
}
+ uint32_t compute_crc( const uint8_t * const buffer, const int size ) const
+ {
+ uint32_t crc = 0xFFFFFFFFU;
+ for( int i = 0; i < size; ++i )
+ crc = data[(crc^buffer[i])&0xFF] ^ ( crc >> 8 );
+ return crc ^ 0xFFFFFFFFU;
+ }
+
// Calculates the crc of size bytes except a window of 8 bytes at pos
uint32_t windowed_crc( const uint8_t * const buffer, const int pos,
const int size ) const
@@ -380,6 +401,8 @@ bool show_member_name( const Extended & extended, const Tar_header header,
bool check_skip_filename( const Cl_options & cl_opts,
std::vector< char > & name_pending,
const char * const filename );
+mode_t get_umask();
+bool make_path( const std::string & name );
// defined in create.cc
bool copy_file( const int infd, const int outfd, const long long max_size = -1 );
@@ -406,29 +429,7 @@ int encode_lz( const Cl_options & cl_opts, const char * const archive_namep,
const int dictionary_size, const int match_len_limit,
const int outfd );
-// defined in delete.cc
-class Lzip_index;
-bool safe_seek( const int fd, const long long pos );
-int tail_copy( const char * const archive_namep, const Arg_parser & parser,
- std::vector< char > & name_pending,
- const Lzip_index & lzip_index, const long long istream_pos,
- const int infd, const int outfd, int retval );
-int delete_members( const Cl_options & cl_opts );
-
-// defined in delete_lz.cc
-int delete_members_lz( const Cl_options & cl_opts,
- const char * const archive_namep,
- std::vector< char > & name_pending,
- const Lzip_index & lzip_index,
- const int infd, const int outfd );
-
-// defined in exclude.cc
-namespace Exclude {
-void add_pattern( const std::string & arg );
-bool excluded( const char * const filename );
-} // end namespace Exclude
-
-// defined in extract.cc
+// defined in decode.cc
bool compare_file_type( std::string & estr, std::string & ostr,
const Cl_options & cl_opts,
const Extended & extended, const Tar_header header );
@@ -439,12 +440,32 @@ bool compare_file_contents( std::string & estr, std::string & ostr,
int decode( const Cl_options & cl_opts );
// defined in decode_lz.cc
-int preadblock( const int fd, uint8_t * const buf, const int size,
- const long long pos );
struct Archive_descriptor;
int decode_lz( const Cl_options & cl_opts, const Archive_descriptor & ad,
std::vector< char > & name_pending );
+// defined in delete.cc
+bool safe_seek( const int fd, const long long pos );
+int tail_copy( const Arg_parser & parser, const Archive_descriptor & ad,
+ std::vector< char > & name_pending, const long long istream_pos,
+ const int outfd, int retval );
+int delete_members( const Cl_options & cl_opts );
+
+// defined in delete_lz.cc
+int delete_members_lz( const Cl_options & cl_opts,
+ const Archive_descriptor & ad,
+ std::vector< char > & name_pending, const int outfd );
+
+// defined in exclude.cc
+namespace Exclude {
+void add_pattern( const std::string & arg );
+void clear();
+bool excluded( const char * const filename );
+} // end namespace Exclude
+
+// defined in extended.cc
+extern const CRC32 crc32c;
+
// defined in lzip_index.cc
int seek_read( const int fd, uint8_t * const buf, const int size,
const long long pos );
@@ -455,7 +476,8 @@ struct stat;
int hstat( const char * const filename, struct stat * const st,
const bool dereference );
int open_instream( const std::string & name );
-int open_outstream( const std::string & name, const bool create = true );
+int open_outstream( const std::string & name, const bool create = true,
+ Resizable_buffer * const rbufp = 0 );
void cleanup_and_fail( const int retval = 1 ); // terminate the program
void show_error( const char * const msg, const int errcode = 0,
const bool help = false );