1
0
Fork 0

Merging upstream version 1.24.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-21 11:32:42 +01:00
parent cefe4620fe
commit bbed90a132
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
35 changed files with 910 additions and 848 deletions

View file

@ -1,5 +1,5 @@
/* Lziprecover - Data recovery tool for the lzip format
Copyright (C) 2009-2023 Antonio Diaz Diaz.
Copyright (C) 2009-2024 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
@ -34,16 +34,17 @@
namespace {
void first_filename( const std::string & input_filename,
bool first_filename( const std::string & input_filename,
const std::string & default_output_filename,
const int max_digits )
{
output_filename = default_output_filename.empty() ?
input_filename : default_output_filename;
const bool to_file = default_output_filename.size();
output_filename = to_file ? default_output_filename : input_filename;
int b = output_filename.size();
while( b > 0 && output_filename[b-1] != '/' ) --b;
output_filename.insert( b, "rec1" );
if( max_digits > 1 ) output_filename.insert( b + 3, max_digits - 1, '0' );
return to_file;
}
@ -108,7 +109,8 @@ int split_file( const std::string & input_filename,
if( !safe_seek( infd, 0, filename ) ) return 1;
int max_digits = 1;
for( long i = lzip_index.blocks( true ); i >= 10; i /= 10 ) ++max_digits;
first_filename( input_filename, default_output_filename, max_digits );
bool to_file = // if true, create intermediate dirs
first_filename( input_filename, default_output_filename, max_digits );
long long stream_pos = 0; // first pos not yet written to file
set_signal_handler();
@ -117,26 +119,23 @@ int split_file( const std::string & input_filename,
const Block & mb = lzip_index.mblock( i );
if( mb.pos() > stream_pos ) // gap
{
if( !open_outstream( force, true, false, false ) ) return 1;
if( !open_outstream( force, true, false, false, to_file ) ) return 1;
if( !copy_file( infd, outfd, mb.pos() - stream_pos ) ||
close_outstream( &in_stats ) != 0 )
cleanup_and_fail( 1 );
next_filename( max_digits );
!close_outstream( &in_stats ) ) cleanup_and_fail( 1 );
next_filename( max_digits ); to_file = false;
}
if( !open_outstream( force, true, false, false ) ) return 1; // member
if( !open_outstream( force, true, false, false, to_file ) ) return 1; // member
if( !copy_file( infd, outfd, mb.size() ) ||
close_outstream( &in_stats ) != 0 )
cleanup_and_fail( 1 );
next_filename( max_digits );
!close_outstream( &in_stats ) ) cleanup_and_fail( 1 );
next_filename( max_digits ); to_file = false;
stream_pos = mb.end();
}
if( lzip_index.file_size() > stream_pos ) // trailing data
{
if( !open_outstream( force, true, false, false ) ) return 1;
if( !open_outstream( force, true, false, false, to_file ) ) return 1;
if( !copy_file( infd, outfd, lzip_index.file_size() - stream_pos ) ||
close_outstream( &in_stats ) != 0 )
cleanup_and_fail( 1 );
next_filename( max_digits );
!close_outstream( &in_stats ) ) cleanup_and_fail( 1 );
next_filename( max_digits ); to_file = false;
}
close( infd );
return 0;