Version v0.3.40 - -m Add directory encryption (TAR+GZIP+OTP), integrate ranger for directory selection, add microtar/miniz libraries, remove binary state file backward compatibility - enforce text format only
This commit is contained in:
26
src/pads.c
26
src/pads.c
@@ -253,10 +253,10 @@ int generate_pad(uint64_t size_bytes, int display_progress) {
|
||||
}
|
||||
|
||||
// Initialize state file with offset 32 (first 32 bytes reserved for checksum encryption)
|
||||
FILE* state_file = fopen(state_path, "wb");
|
||||
FILE* state_file = fopen(state_path, "w");
|
||||
if (state_file) {
|
||||
uint64_t reserved_bytes = 32;
|
||||
fwrite(&reserved_bytes, sizeof(uint64_t), 1, state_file);
|
||||
fprintf(state_file, "offset=%lu\n", reserved_bytes);
|
||||
fclose(state_file);
|
||||
} else {
|
||||
printf("Error: Failed to create state file\n");
|
||||
@@ -292,7 +292,7 @@ int read_state_offset(const char* pad_chksum, uint64_t* offset) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Try to read as text format first (new format)
|
||||
// Read text format only (required format: "offset=<number>")
|
||||
char line[128];
|
||||
if (fgets(line, sizeof(line), state_file)) {
|
||||
// Check if it's text format (starts with "offset=")
|
||||
@@ -302,21 +302,13 @@ int read_state_offset(const char* pad_chksum, uint64_t* offset) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Not text format, try binary format (legacy)
|
||||
// Not in proper text format - error
|
||||
fclose(state_file);
|
||||
state_file = fopen(state_filename, "rb");
|
||||
if (!state_file) {
|
||||
*offset = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (fread(offset, sizeof(uint64_t), 1, state_file) != 1) {
|
||||
fclose(state_file);
|
||||
*offset = 0;
|
||||
return 0;
|
||||
}
|
||||
fclose(state_file);
|
||||
return 0;
|
||||
fprintf(stderr, "Error: State file '%s' is not in proper text format\n", state_filename);
|
||||
fprintf(stderr, "Expected format: offset=<number>\n");
|
||||
fprintf(stderr, "Please convert old binary state files to text format\n");
|
||||
*offset = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
fclose(state_file);
|
||||
|
||||
Reference in New Issue
Block a user