+#include "fmacros.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
len += 2;
*target = (char*)malloc(len);
if (!readBytes(fp,*target,len)) {
- free(*target);
- *target = NULL;
return 0;
}
if (!consumeNewline(*target+len-2)) {
- free(*target);
- *target = NULL;
return 0;
}
(*target)[len-2] = '\0';
while(1) {
if (!multi) pos = ftell(fp);
- if (!readArgc(fp, &argc)) {
- break;
- }
+ if (!readArgc(fp, &argc)) break;
for (i = 0; i < argc; i++) {
- if (!readString(fp,&str)) {
- break;
- }
+ if (!readString(fp,&str)) break;
if (i == 0) {
if (strcasecmp(str, "multi") == 0) {
if (multi++) {
free(str);
}
- /* Check if loop was finished */
+ /* Stop if the loop did not finish */
if (i < argc) {
if (str) free(str);
break;
if (feof(fp) && multi && strlen(error) == 0) {
ERROR("Reached EOF before reading EXEC for MULTI");
}
-
if (strlen(error) > 0) {
printf("%s\n", error);
}
-
return pos;
}
}
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");