Skip to content

Commit 206118e

Browse files
authored
Merge pull request #57 from plattfot/55/incorrect_compare
Add specific comparison functions for the different backends - For snapper: number comparison. - For DeNotebak: string comparison.
2 parents c1ac896 + 2d75ffe commit 206118e

3 files changed

Lines changed: 64 additions & 5 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<!-- SPDX-FileCopyrightText: 2026 Fredrik Salomonsson <plattfot@posteo.net> -->
2+
<!-- SPDX-License-Identifier: GPL-3.0-or-later -->
3+
### Added
4+
- Specific comparison functions for the different backends. [#55](https://github.com/plattfot/baksnapper/issues/55)

‎baksnapper.sh‎

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,44 @@ fi
566566

567567
snapshot_type=$sender_snapshot_type
568568

569+
# Check if two snapshots are the same using arithmetic
570+
# 1 [in]: snapshot a
571+
# 2 [in]: snapshot b
572+
function snapshot-same-number {
573+
(( "$1" == "$2" ))
574+
}
575+
576+
# Check if snapshot a is older than b using arithmetic
577+
# 1 [in]: snapshot a
578+
# 2 [in]: snapshot b
579+
function snapshot-older-number {
580+
(( "$1" < "$2" ))
581+
}
582+
583+
584+
# Check if two snapshots are the same using string comparison
585+
# 1 [in]: snapshot a
586+
# 2 [in]: snapshot b
587+
function snapshot-same-string {
588+
[[ "$1" == "$2" ]]
589+
}
590+
591+
# Check if snapshot a is older than b using string comparison
592+
# 1 [in]: snapshot a
593+
# 2 [in]: snapshot b
594+
function snapshot-older-string {
595+
[[ "$1" < "$2" ]]
596+
}
597+
598+
if [[ $snapshot_type == "snapper" ]]
599+
then
600+
snapshot_same=snapshot-same-number
601+
snapshot_older=snapshot-older-number
602+
else
603+
snapshot_same=snapshot-same-string
604+
snapshot_older=snapshot-older-string
605+
fi
606+
569607
# Using a bitmap to represent where a snapshot is located:
570608
# 0b01 → exist at the source
571609
# 0b10 → exist at the destination
@@ -656,12 +694,12 @@ function compare-snapshots {
656694
# "sort -g" when getting the snapshots.
657695
while (( idx_src < num_src_snapshots && idx_dest < num_dest_snapshots ))
658696
do
659-
if [[ "${src_snapshots[idx_src]}" == "${dest_snapshots[idx_dest]}" ]]
697+
if $snapshot_same "${src_snapshots[idx_src]}" "${dest_snapshots[idx_dest]}"
660698
then
661699
common["${src_snapshots[idx_src]}"]=0b11
662700
((++idx_src))
663701
((++idx_dest))
664-
elif [[ "${src_snapshots[idx_src]}" < "${dest_snapshots[idx_dest]}" ]]
702+
elif $snapshot_older "${src_snapshots[idx_src]}" "${dest_snapshots[idx_dest]}"
665703
then
666704
only_in_src+=("${src_snapshots[idx_src]}")
667705
((++idx_src))
@@ -825,8 +863,8 @@ function backup {
825863
local idx=${num_src_snapshots}-1
826864
for (( ; idx >= 0; --idx ))
827865
do
828-
if [[ "${src_snapshots[idx]}" < "$snapshot" && \
829-
${common[${src_snapshots[idx]}]} == 0b11 ]]
866+
if ( $snapshot_older "${src_snapshots[idx]}" "$snapshot" ) && \
867+
[[ ${common[${src_snapshots[idx]}]} == 0b11 ]]
830868
then
831869
break
832870
fi
@@ -859,7 +897,7 @@ function backup {
859897
local src_snapshot=${only_in_src[src_idx]}
860898
for (( ; idx < num_src_snapshots; ++idx ))
861899
do
862-
if [[ "${src_snapshots[idx]}" == "$src_snapshot" ]]
900+
if $snapshot_same "${src_snapshots[idx]}" "$src_snapshot"
863901
then
864902
break
865903
fi

‎meson.build‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,23 @@ foreach test_entry: [
312312
'suite': ['backup'],
313313
'env': test_env,
314314
},
315+
# https://github.com/plattfot/baksnapper/issues/55
316+
{
317+
'name': 'large-snapshot-range',
318+
'runner-args': [
319+
'--sender', '0,1,6984,10288,11005,11620,11736,11784,11804,11862,11867,11891,11915,11939,11959,11960,11961,11962,11963,11964,11965,11966,11967,11968,11969,11970,11971,11972,11973,11974,11975,11976,11977,11978,11979',
320+
'--receiver', '6984,8377:p=6984,9117:p=8377,9586:p=9117,10288:p=9586,10456:p=10288,10624:p=10456,10792:p=10624,10957:p=10792,10981:p=10957,11005:p=10981,11029:p=11005,11053:p=11029,11077:p=11053,11082:p=11077,11083:p=11082,11084:p=11083,11085:p=11084,11086:p=11085,11087:p=11086,',
321+
'--expected', '6984,8377:p=6984,9117:p=8377,9586:p=9117,10288:p=9586,10456:p=10288,10624:p=10456,10792:p=10624,10957:p=10792,10981:p=10957,11005:p=10981,11029:p=11005,11053:p=11029,11077:p=11053,11082:p=11077,11083:p=11082,11084:p=11083,11085:p=11084,11086:p=11085,11087:p=11086,11979:p=11005',
322+
],
323+
'baksnapper-args': [
324+
baksnapper,
325+
'--daemon', baksnapperd, '-v',
326+
],
327+
'configfile': 'default',
328+
'configfile-baksnapper-args': [],
329+
'suite': ['backup'],
330+
'env': test_env,
331+
},
315332
# DeNotebak
316333
{
317334
'name': 'denotebak-default',

0 commit comments

Comments
 (0)