aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md8
-rw-r--r--src/backup.cpp31
-rw-r--r--src/options.cpp8
-rw-r--r--src/options.h4
-rw-r--r--tests/004-unknown_option.sh2
-rw-r--r--tests/006-incorrect_buffer_size.sh6
-rw-r--r--tests/007-incorrect_sector_size.sh6
-rw-r--r--tests/100-cannot_open_files.sh18
-rw-r--r--tests/200-input_and_reference_size_differs.sh8
-rw-r--r--tests/201-input_or_reference_size_is_not_multiple_of_sector_size.sh10
-rw-r--r--tests/400-successful_backup_restore.sh18
11 files changed, 59 insertions, 60 deletions
diff --git a/README.md b/README.md
index 98cec46..90c7340 100644
--- a/README.md
+++ b/README.md
@@ -18,7 +18,7 @@ is read twice when restoring it. Because of that, it is slower.
> diff-dd help
-> diff-dd backup [-s SECTOR_SIZE] [-b BUFFER_SIZE] INFILE REFFILE OUTFILE
+> diff-dd backup [-s SECTOR_SIZE] [-b BUFFER_SIZE] INFILE BASEFILE OUTFILE
> diff-dd restore [-s SECTOR_SIZE] [-b BUFFER_SIZE] INFILE OUTFILE
@@ -27,12 +27,12 @@ is read twice when restoring it. Because of that, it is slower.
Using ```diff-dd ``` for backup requires the full backup image to
exist. Differential backup is created with:
-> diff-dd backup INFILE REFFILE OUTFILE
+> diff-dd backup INFILE BASEFILE OUTFILE
The ```INFILE``` is a path to the file to backup differentially, the
-```REFFILE``` is the full image, and the ```OUTFILE``` is the file to
+```BASEFILE``` is the full image, and the ```OUTFILE``` is the file to
which only the changed sectors of the ```INFILE```, compared to the
-```REFFILE```, and their offsets will be saved.
+```BASEFILE```, and their offsets will be saved.
## Restore
diff --git a/src/backup.cpp b/src/backup.cpp
index 111d3f3..bf8bfaf 100644
--- a/src/backup.cpp
+++ b/src/backup.cpp
@@ -43,20 +43,20 @@ check_files(const OptionsBackup &opts)
std::string(e.what()));
}
- size_t ref_size{0};
+ size_t base_size{0};
try {
- ref_size = std::filesystem::file_size(opts.getRefFilePath());
+ base_size = std::filesystem::file_size(opts.getBaseFilePath());
} catch (const std::exception &e) {
- throw BackupError("cannot get size of reference file: " +
+ throw BackupError("cannot get size of base file: " +
std::string(e.what()));
}
- /* Check sizes of the input file and the reference file */
- if (in_size != ref_size) {
- throw BackupError("input file and reference file differ in size");
+ /* Check sizes of the input file and the base file */
+ if (in_size != base_size) {
+ throw BackupError("input file and base file differ in size");
} else if ((in_size % opts.getSectorSize()) != 0) {
throw BackupError(
- "size of input file and reference file is not multiple of " +
+ "size of input file and base file is not multiple of " +
std::to_string(opts.getSectorSize()));
}
}
@@ -67,7 +67,7 @@ backup(const OptionsBackup &opts)
check_files(opts);
BufferedFileReader in_file(opts.getInFilePath(), opts.getBufferSize());
- BufferedFileReader ref_file(opts.getRefFilePath(), opts.getBufferSize());
+ BufferedFileReader base_file(opts.getBaseFilePath(), opts.getBufferSize());
BufferedFileWriter out_file(opts.getOutFilePath(), opts.getBufferSize());
std::unique_ptr<char[]> in_buffer;
@@ -77,12 +77,11 @@ backup(const OptionsBackup &opts)
throw BackupError("cannot allocate sector buffer for input file data");
}
- std::unique_ptr<char[]> ref_buffer;
+ std::unique_ptr<char[]> base_buffer;
try {
- ref_buffer = std::make_unique<char[]>(opts.getSectorSize());
+ base_buffer = std::make_unique<char[]>(opts.getSectorSize());
} catch (const std::bad_alloc &e) {
- throw BackupError(
- "cannot allocate sector buffer for reference file data");
+ throw BackupError("cannot allocate sector buffer for base file data");
}
uint64_t input_file_offset{0};
@@ -90,10 +89,10 @@ backup(const OptionsBackup &opts)
// Read sectors
const size_t in_read_size =
in_file.read(in_buffer.get(), opts.getSectorSize());
- const size_t ref_read_size =
- ref_file.read(ref_buffer.get(), opts.getSectorSize());
+ const size_t base_read_size =
+ base_file.read(base_buffer.get(), opts.getSectorSize());
- if (in_read_size != ref_read_size) {
+ if (in_read_size != base_read_size) {
throw BackupError(
"cannot read equal amount of bytes from the input files");
} else if (in_read_size == 0) {
@@ -103,7 +102,7 @@ backup(const OptionsBackup &opts)
}
// Check for difference
- const bool differ = (memcmp(in_buffer.get(), ref_buffer.get(),
+ const bool differ = (memcmp(in_buffer.get(), base_buffer.get(),
opts.getSectorSize()) != 0);
if (differ) {
// Backup sector
diff --git a/src/options.cpp b/src/options.cpp
index 9fc89cd..ed6eec8 100644
--- a/src/options.cpp
+++ b/src/options.cpp
@@ -60,9 +60,9 @@ OptionsBackup::getInFilePath() const
}
std::filesystem::path
-OptionsBackup::getRefFilePath() const
+OptionsBackup::getBaseFilePath() const
{
- return ref_file_path;
+ return base_file_path;
}
std::filesystem::path
@@ -87,7 +87,7 @@ void
OptionParser::printUsage()
{
std::cout << "Usage: " << PROGRAM_NAME_STR << " backup [-s SECTOR_SIZE]";
- std::cout << " [-b BUFFER_SIZE] INFILE REFFILE OUTFILE" << std::endl;
+ std::cout << " [-b BUFFER_SIZE] INFILE BASEFILE OUTFILE" << std::endl;
std::cout << " Or: " << PROGRAM_NAME_STR << " restore [-s SECTOR_SIZE]";
std::cout << "[-b BUFFER_SIZE] REFFILE OUTFILE" << std::endl;
@@ -126,7 +126,7 @@ OptionParser::parseBackup(int argc, char **argv)
throw OptionError("too many arguments");
} else {
opts.in_file_path = next_arg(&argv);
- opts.ref_file_path = next_arg(&argv);
+ opts.base_file_path = next_arg(&argv);
opts.out_file_path = next_arg(&argv);
}
diff --git a/src/options.h b/src/options.h
index 058ad58..e22b3e3 100644
--- a/src/options.h
+++ b/src/options.h
@@ -64,12 +64,12 @@ class OptionsBackup : public Options
virtual ~OptionsBackup() override = default;
std::filesystem::path getInFilePath() const;
- std::filesystem::path getRefFilePath() const;
+ std::filesystem::path getBaseFilePath() const;
std::filesystem::path getOutFilePath() const;
private:
std::filesystem::path in_file_path;
- std::filesystem::path ref_file_path;
+ std::filesystem::path base_file_path;
std::filesystem::path out_file_path;
};
diff --git a/tests/004-unknown_option.sh b/tests/004-unknown_option.sh
index 3373b0c..583f1ca 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 in ref out
+assert "Usage" "unknown option '-x'" 1 $PROGRAM_EXEC backup -x in base out
assert "Usage" "unknown option '-x'" 1 $PROGRAM_EXEC restore -x ref out
exit 0
diff --git a/tests/006-incorrect_buffer_size.sh b/tests/006-incorrect_buffer_size.sh
index 8640305..a579b26 100644
--- a/tests/006-incorrect_buffer_size.sh
+++ b/tests/006-incorrect_buffer_size.sh
@@ -4,9 +4,9 @@ source ./assert.sh
PROGRAM_EXEC="$1"
-assert "Usage" "incorrect sector size" 1 $PROGRAM_EXEC backup -s abc123 in ref out
-assert "Usage" "sector size cannot be 0" 1 $PROGRAM_EXEC backup -s 0 in ref out
-assert "Usage" "sector size cannot larger than buffer size" 1 $PROGRAM_EXEC backup -s 2 -b 1 in ref out
+assert "Usage" "incorrect sector size" 1 $PROGRAM_EXEC backup -s abc123 in base out
+assert "Usage" "sector size cannot be 0" 1 $PROGRAM_EXEC backup -s 0 in base out
+assert "Usage" "sector size cannot larger than buffer size" 1 $PROGRAM_EXEC backup -s 2 -b 1 in base out
assert "Usage" "incorrect sector size" 1 $PROGRAM_EXEC restore -s abc123 in out
assert "Usage" "sector size cannot be 0" 1 $PROGRAM_EXEC restore -s 0 in out
diff --git a/tests/007-incorrect_sector_size.sh b/tests/007-incorrect_sector_size.sh
index 6194d12..89f7051 100644
--- a/tests/007-incorrect_sector_size.sh
+++ b/tests/007-incorrect_sector_size.sh
@@ -4,9 +4,9 @@ source ./assert.sh
PROGRAM_EXEC="$1"
-assert "Usage" "incorrect buffer size" 1 $PROGRAM_EXEC backup -b abc123 in ref out
-assert "Usage" "buffer size cannot be 0" 1 $PROGRAM_EXEC backup -b 0 in ref out
-assert "Usage" "buffer size is not multiple of sector size" 1 $PROGRAM_EXEC backup -b 3 -s 2 in ref out
+assert "Usage" "incorrect buffer size" 1 $PROGRAM_EXEC backup -b abc123 in base out
+assert "Usage" "buffer size cannot be 0" 1 $PROGRAM_EXEC backup -b 0 in base out
+assert "Usage" "buffer size is not multiple of sector size" 1 $PROGRAM_EXEC backup -b 3 -s 2 in base out
assert "Usage" "incorrect buffer size" 1 $PROGRAM_EXEC restore -b abc123 in out
assert "Usage" "buffer size cannot be 0" 1 $PROGRAM_EXEC restore -b 0 in out
diff --git a/tests/100-cannot_open_files.sh b/tests/100-cannot_open_files.sh
index 4e7c45f..64d2a87 100644
--- a/tests/100-cannot_open_files.sh
+++ b/tests/100-cannot_open_files.sh
@@ -4,22 +4,22 @@ source ./assert.sh
PROGRAM_EXEC="$1"
-rm -f input ref out
-touch ref out
-assert "" "cannot get size of input file" 1 $PROGRAM_EXEC backup input ref out
+rm -f input base out
+touch base out
+assert "" "cannot get size of input file" 1 $PROGRAM_EXEC backup input base out
-rm -f input ref out
+rm -f input base out
touch input out
-assert "" "cannot get size of reference file" 1 $PROGRAM_EXEC backup input ref out
+assert "" "cannot get size of base file" 1 $PROGRAM_EXEC backup input base out
-rm -f input ref out
+rm -f input base out
rmdir outdir 2>/dev/null
-touch input ref
+touch input base
mkdir outdir
chmod -w outdir
-assert "" "cannot open output file" 1 $PROGRAM_EXEC backup input ref outdir/out
+assert "" "cannot open output file" 1 $PROGRAM_EXEC backup input base outdir/out
-rm -f input ref out
+rm -f input base out
rmdir outdir
exit 0
diff --git a/tests/200-input_and_reference_size_differs.sh b/tests/200-input_and_reference_size_differs.sh
index a17ecab..ca0f368 100644
--- a/tests/200-input_and_reference_size_differs.sh
+++ b/tests/200-input_and_reference_size_differs.sh
@@ -4,12 +4,12 @@ source ./assert.sh
PROGRAM_EXEC="$1"
-rm -f input ref
+rm -f input base
dd if=/dev/zero of=input bs=500 count=1 1>/dev/null 2>&1
-dd if=/dev/zero of=ref bs=501 count=1 1>/dev/null 2>&1
+dd if=/dev/zero of=base bs=501 count=1 1>/dev/null 2>&1
-assert "" "input file and reference file differ in size" 1 $PROGRAM_EXEC backup input ref out
+assert "" "input file and base file differ in size" 1 $PROGRAM_EXEC backup input base out
-rm -f input ref out
+rm -f input base out
exit 0
diff --git a/tests/201-input_or_reference_size_is_not_multiple_of_sector_size.sh b/tests/201-input_or_reference_size_is_not_multiple_of_sector_size.sh
index 2dd7d44..abfb3c5 100644
--- a/tests/201-input_or_reference_size_is_not_multiple_of_sector_size.sh
+++ b/tests/201-input_or_reference_size_is_not_multiple_of_sector_size.sh
@@ -4,13 +4,13 @@ source ./assert.sh
PROGRAM_EXEC="$1"
-rm -f input ref
+rm -f input base
dd if=/dev/zero of=input bs=513 count=1 1>/dev/null 2>&1
-dd if=/dev/zero of=ref bs=513 count=1 1>/dev/null 2>&1
+dd if=/dev/zero of=base bs=513 count=1 1>/dev/null 2>&1
-assert "" "size of input file and reference file is not multiple of [0-9]" \
- 1 $PROGRAM_EXEC backup -s 512 input ref out
+assert "" "size of input file and base file is not multiple of [0-9]" \
+ 1 $PROGRAM_EXEC backup -s 512 input base out
-rm -f input ref out
+rm -f input base out
exit 0
diff --git a/tests/400-successful_backup_restore.sh b/tests/400-successful_backup_restore.sh
index bf07a00..8274964 100644
--- a/tests/400-successful_backup_restore.sh
+++ b/tests/400-successful_backup_restore.sh
@@ -9,14 +9,14 @@ function files_are_the_same()
[ -z "$(diff "$1" "$2")" ]
}
-rm -f input backedup_input ref out
+rm -f input backedup_input base out
-# Create a four-sector reference file (the original file)
-dd if=/dev/zero of=ref bs=512 count=4 1>/dev/null 2>&1
+# Create a four-sector base file (the original file)
+dd if=/dev/zero of=base bs=512 count=4 1>/dev/null 2>&1
# Change the orignal file to make it an input file for differential backup
# There will be four different sectors in the input file
-cp ref input
+cp base input
# The first sector will have the 0th byte chaged
printf '\xFF' | dd of=input bs=1 count=1 seek=0 conv=notrunc 1>/dev/null 2>&1
@@ -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 -s 512 input ref out
+assert "" "" 0 $PROGRAM_EXEC backup -s 512 input base out
if ! files_are_the_same out 400-expected_backup_output.bin; then
echo "assert: Backup output file differs from the expected one"
@@ -38,9 +38,9 @@ fi
# Modify the file to backup (the input file used in the backup phase)
cp input backedup_input
-cp ref input
-if ! files_are_the_same ref input; then
- echo "assert: The input file must be the same as the reference one before restoring it"
+cp base input
+if ! files_are_the_same base input; then
+ echo "assert: The input file must be the same as the base one before restoring it"
exit 1
fi
@@ -51,6 +51,6 @@ if ! files_are_the_same input backedup_input; then
exit 1
fi
-rm -f input backedup_input ref out
+rm -f input backedup_input base out
exit 0