X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/e51fa063db5fbb53c754738d87146551aebfd8e2..32a6651355cc75f19f40b7d7a4cbd419ea19f39f:/redis-check-aof.c diff --git a/redis-check-aof.c b/redis-check-aof.c index 8d72e6b2..ff0d1f82 100644 --- a/redis-check-aof.c +++ b/redis-check-aof.c @@ -1,3 +1,4 @@ +#include "fmacros.h" #include #include #include @@ -154,16 +155,26 @@ int main(int argc, char **argv) { } long pos = process(fp); - if (pos < size) { + long diff = size-pos; + if (diff > 0) { 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) { - printf("Could not truncate AOF to size %ld\n", pos); + printf("Failed to truncate AOF\n"); exit(1); } else { - printf("AOF succesfully truncated to %ld bytes\n", pos); + printf("Successfully truncated AOF\n"); } } else { - printf("First invalid operation at offset %ld\n", pos); + printf("AOF is not valid\n"); + exit(1); } } else { printf("AOF is valid\n");