diff options
| -rw-r--r-- | README.md | 10 | ||||
| -rw-r--r-- | src/create.cpp (renamed from src/backup.cpp) | 6 | ||||
| -rw-r--r-- | src/create.h (renamed from src/backup.h) | 6 | ||||
| -rw-r--r-- | src/main.cpp | 6 | ||||
| -rw-r--r-- | src/options.cpp | 18 | ||||
| -rw-r--r-- | src/options.h | 8 | ||||
| -rw-r--r-- | tests/002-missing_arguments.sh | 2 | ||||
| -rw-r--r-- | tests/003-too_many_arguments.sh | 2 | ||||
| -rw-r--r-- | tests/004-unknown_option.sh | 2 | ||||
| -rw-r--r-- | tests/005-missing_argument_for_option.sh | 2 | ||||
| -rw-r--r-- | tests/006-incorrect_buffer_size.sh | 4 | ||||
| -rw-r--r-- | tests/100-cannot_open_files.sh | 6 | ||||
| -rw-r--r-- | tests/400-successful_backup_restore.sh | 2 |
13 files changed, 37 insertions, 37 deletions
@@ -18,16 +18,16 @@ utility. > diff-dd version -> diff-dd backup [-B BUFFER_SIZE] -i INFILE -b BASEFILE -o OUTFILE +> diff-dd create [-B BUFFER_SIZE] -i INFILE -b BASEFILE -o OUTFILE > diff-dd restore [-B BUFFER_SIZE] -d DIFFFILE -o OUTFILE -## Backup +## Create Using ```diff-dd ``` for backup requires the full backup image to exist. Differential backup is created with: -> diff-dd backup -i INFILE -b BASEFILE -o OUTFILE +> diff-dd create -i INFILE -b BASEFILE -o OUTFILE The ```INFILE``` is a path to the file to backup differentially, the ```BASEFILE``` is the full image, and the ```OUTFILE``` is the file to @@ -45,7 +45,7 @@ The restoration means application of the changed data saved in the ```-B``` sets the size of the buffer for the data of the input and output files (default is 4 MiB). The input data is always buffered. The -output data is buffered only in backup mode. +output data is not buffered in the restore mode. ## Example @@ -55,7 +55,7 @@ First, the full image of the partition to backup has to be created: When the user decides to create the differential image, he or she runs: -> diff-dd backup -i /dev/sda1 -b full.img -o diff.img +> diff-dd create -i /dev/sda1 -b full.img -o diff.img If a data accident happens, the partition can be restored by running: diff --git a/src/backup.cpp b/src/create.cpp index 98898b9..460bdd1 100644 --- a/src/backup.cpp +++ b/src/create.cpp @@ -24,7 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "backup.h" +#include "create.h" #include "buffered_stream.h" #include "format_v2.h" @@ -248,7 +248,7 @@ class DiffFinder assert(m_old_page.getStart() == m_new_page.getStart()); if (m_old_page.getSize() != m_new_page.getSize()) { - throw BackupError( + throw CreateError( "cannot read the same amount of data from both files"); } @@ -350,7 +350,7 @@ class DiffFinder }; void -backup(const OptionsBackup &opts) +create(const OptionsCreate &opts) { std::ifstream in_istream{opts.getInFilePath(), std::ifstream::in | std::ifstream::binary}; diff --git a/src/backup.h b/src/create.h index ed7bf1a..bbfc374 100644 --- a/src/backup.h +++ b/src/create.h @@ -29,10 +29,10 @@ #include "exception.h" #include "options.h" -class BackupError : public DiffddError +class CreateError : public DiffddError { public: - explicit BackupError(const std::string &message) : DiffddError(message) {} + explicit CreateError(const std::string &message) : DiffddError(message) {} }; -void backup(const OptionsBackup &opts); +void create(const OptionsCreate &opts); diff --git a/src/main.cpp b/src/main.cpp index 499140f..364762d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,7 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "backup.h" +#include "create.h" #include "options.h" #include "restore.h" @@ -46,8 +46,8 @@ main(int argc, char **argv) OptionParser::printUsage(); } else if (OptionParser::isVersion(argc, argv)) { print_version(); - } else if (OptionParser::isBackup(argc, argv)) { - backup(OptionParser::parseBackup(argc, argv)); + } else if (OptionParser::isCreate(argc, argv)) { + create(OptionParser::parseCreate(argc, argv)); } else if (OptionParser::isRestore(argc, argv)) { restore(OptionParser::parseRestore(argc, argv)); } else { diff --git a/src/options.cpp b/src/options.cpp index a5912b6..9cf9d73 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -44,19 +44,19 @@ Options::getBufferSize() const } std::filesystem::path -OptionsBackup::getInFilePath() const +OptionsCreate::getInFilePath() const { return in_file_path; } std::filesystem::path -OptionsBackup::getBaseFilePath() const +OptionsCreate::getBaseFilePath() const { return base_file_path; } std::filesystem::path -OptionsBackup::getOutFilePath() const +OptionsCreate::getOutFilePath() const { return out_file_path; } @@ -76,7 +76,7 @@ OptionsRestore::getOutFilePath() const void OptionParser::printUsage() { - std::cout << "Usage: " << PROGRAM_NAME_STR << " backup"; + std::cout << "Usage: " << PROGRAM_NAME_STR << " create"; std::cout << " [-B BUFFER_SIZE] -i INFILE -b BASEFILE -o OUTFILE" << std::endl; @@ -101,9 +101,9 @@ OptionParser::isVersion(int argc, char **argv) } bool -OptionParser::isBackup(int argc, char **argv) +OptionParser::isCreate(int argc, char **argv) { - return isOperation(argc, argv, "backup"); + return isOperation(argc, argv, "create"); } bool @@ -112,10 +112,10 @@ OptionParser::isRestore(int argc, char **argv) return isOperation(argc, argv, "restore"); } -OptionsBackup -OptionParser::parseBackup(int argc, char **argv) +OptionsCreate +OptionParser::parseCreate(int argc, char **argv) { - OptionsBackup opts; + OptionsCreate opts; // Skip the executable name. Do not skip the operation name. getopt expects // to start at an argument immediately preceding the possible options. diff --git a/src/options.h b/src/options.h index ba7e7ac..593bcad 100644 --- a/src/options.h +++ b/src/options.h @@ -53,12 +53,12 @@ class Options uint32_t buffer_size; }; -class OptionsBackup : public Options +class OptionsCreate : public Options { friend class OptionParser; public: - virtual ~OptionsBackup() override = default; + virtual ~OptionsCreate() override = default; std::filesystem::path getInFilePath() const; std::filesystem::path getBaseFilePath() const; @@ -91,10 +91,10 @@ class OptionParser static void printUsage(); static bool isHelp(int argc, char **argv); static bool isVersion(int argc, char **argv); - static bool isBackup(int argc, char **argv); + static bool isCreate(int argc, char **argv); static bool isRestore(int argc, char **argv); ; - static OptionsBackup parseBackup(int argc, char **argv); + static OptionsCreate parseCreate(int argc, char **argv); static OptionsRestore parseRestore(int argc, char **argv); private: diff --git a/tests/002-missing_arguments.sh b/tests/002-missing_arguments.sh index c3aaa1b..2ebbd55 100644 --- a/tests/002-missing_arguments.sh +++ b/tests/002-missing_arguments.sh @@ -4,7 +4,7 @@ source ./assert.sh PROGRAM_EXEC="$1" -assert "Usage" "missing input file" 1 $PROGRAM_EXEC backup +assert "Usage" "missing input file" 1 $PROGRAM_EXEC create assert "Usage" "missing diff file" 1 $PROGRAM_EXEC restore exit 0 diff --git a/tests/003-too_many_arguments.sh b/tests/003-too_many_arguments.sh index 2891afd..dc53a69 100644 --- a/tests/003-too_many_arguments.sh +++ b/tests/003-too_many_arguments.sh @@ -4,7 +4,7 @@ source ./assert.sh PROGRAM_EXEC="$1" -assert "Usage" "too many arguments" 1 $PROGRAM_EXEC backup -i arg1 -b arg2 -o arg3 arg4 +assert "Usage" "too many arguments" 1 $PROGRAM_EXEC create -i arg1 -b arg2 -o arg3 arg4 assert "Usage" "too many arguments" 1 $PROGRAM_EXEC restore -d arg1 -o arg2 arg3 exit 0 diff --git a/tests/004-unknown_option.sh b/tests/004-unknown_option.sh index 452d904..9ed0d66 100644 --- a/tests/004-unknown_option.sh +++ b/tests/004-unknown_option.sh @@ -4,7 +4,7 @@ source ./assert.sh PROGRAM_EXEC="$1" -assert "Usage" "unknown option '-x'" 1 $PROGRAM_EXEC backup -x -i in -b base -o out +assert "Usage" "unknown option '-x'" 1 $PROGRAM_EXEC create -x -i in -b base -o out assert "Usage" "unknown option '-x'" 1 $PROGRAM_EXEC restore -x -d diff -o out exit 0 diff --git a/tests/005-missing_argument_for_option.sh b/tests/005-missing_argument_for_option.sh index 26569bc..6fdf18e 100644 --- a/tests/005-missing_argument_for_option.sh +++ b/tests/005-missing_argument_for_option.sh @@ -4,7 +4,7 @@ source ./assert.sh PROGRAM_EXEC="$1" -assert "Usage" "missing argument for option '-B'" 1 $PROGRAM_EXEC backup -B +assert "Usage" "missing argument for option '-B'" 1 $PROGRAM_EXEC create -B assert "Usage" "missing argument for option '-B'" 1 $PROGRAM_EXEC restore -B diff --git a/tests/006-incorrect_buffer_size.sh b/tests/006-incorrect_buffer_size.sh index 9c9b4ea..f104ebb 100644 --- a/tests/006-incorrect_buffer_size.sh +++ b/tests/006-incorrect_buffer_size.sh @@ -4,8 +4,8 @@ source ./assert.sh PROGRAM_EXEC="$1" -assert "Usage" "incorrect buffer size" 1 $PROGRAM_EXEC backup -B abc123 -i in -b base -o out -assert "Usage" "buffer size cannot be 0" 1 $PROGRAM_EXEC backup -B 0 -i in -b base -o out +assert "Usage" "incorrect buffer size" 1 $PROGRAM_EXEC create -B abc123 -i in -b base -o out +assert "Usage" "buffer size cannot be 0" 1 $PROGRAM_EXEC create -B 0 -i in -b base -o out assert "Usage" "incorrect buffer size" 1 $PROGRAM_EXEC restore -B abc123 -d diff -o out assert "Usage" "buffer size cannot be 0" 1 $PROGRAM_EXEC restore -B 0 -d diff -o out diff --git a/tests/100-cannot_open_files.sh b/tests/100-cannot_open_files.sh index e0a59d3..3ef74a6 100644 --- a/tests/100-cannot_open_files.sh +++ b/tests/100-cannot_open_files.sh @@ -6,18 +6,18 @@ PROGRAM_EXEC="$1" rm -f input base out touch base out -assert "" "cannot open input file" 1 $PROGRAM_EXEC backup -i input -b base -o out +assert "" "cannot open input file" 1 $PROGRAM_EXEC create -i input -b base -o out rm -f input base out touch input out -assert "" "cannot open base file" 1 $PROGRAM_EXEC backup -i input -b base -o out +assert "" "cannot open base file" 1 $PROGRAM_EXEC create -i input -b base -o out rm -f input base out rmdir outdir 2>/dev/null touch input base mkdir outdir chmod -w outdir -assert "" "cannot open output file" 1 $PROGRAM_EXEC backup -i input -b base -o outdir/out +assert "" "cannot open output file" 1 $PROGRAM_EXEC create -i input -b base -o outdir/out rm -f input base out rmdir outdir diff --git a/tests/400-successful_backup_restore.sh b/tests/400-successful_backup_restore.sh index f1a07c5..a10853b 100644 --- a/tests/400-successful_backup_restore.sh +++ b/tests/400-successful_backup_restore.sh @@ -29,7 +29,7 @@ printf '\xFF' | dd of=input bs=1 count=1 seek=$(( (512 * 3) - 1 )) conv=notrunc # The fourth sector will have the middle byte changed printf '\xFF' | dd of=input bs=1 count=1 seek=$(( (512 * 4) - (512 / 2) )) conv=notrunc 1>/dev/null 2>&1 -assert "" "" 0 $PROGRAM_EXEC backup -i input -b base -o out +assert "" "" 0 $PROGRAM_EXEC create -i input -b base -o out if ! files_are_the_same out 400-expected_backup_output.bin; then echo "assert: Backup output file differs from the expected one" |
