mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-23 08:38:27 -05:00
ask for confirmation before AOF is truncated
This commit is contained in:
parent
e51fa063db
commit
81330149f8
@ -154,16 +154,26 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
long pos = process(fp);
|
long pos = process(fp);
|
||||||
if (pos < size) {
|
long diff = size-pos;
|
||||||
|
if (diff > 0) {
|
||||||
if (fix) {
|
if (fix) {
|
||||||
|
char buf[2];
|
||||||
|
printf("This will shrink the AOF from %ld bytes, with %ld bytes, to %ld bytes\n",size,diff,pos);
|
||||||
|
printf("Continue? [y/N]: ");
|
||||||
|
if (fgets(buf,sizeof(buf),stdin) == NULL ||
|
||||||
|
strncasecmp(buf,"y",1) != 0) {
|
||||||
|
printf("Aborting...\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
if (ftruncate(fileno(fp), pos) == -1) {
|
if (ftruncate(fileno(fp), pos) == -1) {
|
||||||
printf("Could not truncate AOF to size %ld\n", pos);
|
printf("Failed to truncate AOF\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
} else {
|
} else {
|
||||||
printf("AOF succesfully truncated to %ld bytes\n", pos);
|
printf("Successfully truncated AOF\n");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
printf("First invalid operation at offset %ld\n", pos);
|
printf("AOF is not valid\n");
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
printf("AOF is valid\n");
|
printf("AOF is valid\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user