diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-01-23 05:31:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-01-23 05:31:44 +0000 |
commit | 166ede1642869f46a0aae2df885772f7383e9ab2 (patch) | |
tree | e94c5a1aa65e2c1b2370656f0df107edd33700f7 /split.cc | |
parent | Adding upstream version 1.24~pre1. (diff) | |
download | lziprecover-166ede1642869f46a0aae2df885772f7383e9ab2.tar.xz lziprecover-166ede1642869f46a0aae2df885772f7383e9ab2.zip |
Adding upstream version 1.24.upstream/1.24upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | split.cc | 33 |
1 files changed, 16 insertions, 17 deletions
@@ -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; |