Version v0.3.26 - Change .state file to plain text instead of binary
This commit is contained in:
34
src/pads.c
34
src/pads.c
@@ -89,7 +89,10 @@ int generate_pad(uint64_t size_bytes, int display_progress) {
|
||||
const char* pads_dir = get_current_pads_dir();
|
||||
struct statvfs stat;
|
||||
if (statvfs(pads_dir, &stat) == 0) {
|
||||
uint64_t available_bytes = stat.f_bavail * stat.f_frsize;
|
||||
// Use f_bfree (total free blocks) instead of f_bavail (available to non-root)
|
||||
// This gives the actual free space on the filesystem, which is more accurate
|
||||
// for removable media and user-owned directories
|
||||
uint64_t available_bytes = stat.f_bfree * stat.f_frsize;
|
||||
double available_gb = (double)available_bytes / (1024.0 * 1024.0 * 1024.0);
|
||||
double required_gb = (double)size_bytes / (1024.0 * 1024.0 * 1024.0);
|
||||
|
||||
@@ -233,7 +236,25 @@ int read_state_offset(const char* pad_chksum, uint64_t* offset) {
|
||||
const char* pads_dir = get_current_pads_dir();
|
||||
snprintf(state_filename, sizeof(state_filename), "%s/%s.state", pads_dir, pad_chksum);
|
||||
|
||||
FILE* state_file = fopen(state_filename, "rb");
|
||||
FILE* state_file = fopen(state_filename, "r");
|
||||
if (!state_file) {
|
||||
*offset = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Try to read as text format first (new format)
|
||||
char line[128];
|
||||
if (fgets(line, sizeof(line), state_file)) {
|
||||
// Check if it's text format (starts with "offset=")
|
||||
if (strncmp(line, "offset=", 7) == 0) {
|
||||
*offset = strtoull(line + 7, NULL, 10);
|
||||
fclose(state_file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Not text format, try binary format (legacy)
|
||||
fclose(state_file);
|
||||
state_file = fopen(state_filename, "rb");
|
||||
if (!state_file) {
|
||||
*offset = 0;
|
||||
return 0;
|
||||
@@ -244,8 +265,12 @@ int read_state_offset(const char* pad_chksum, uint64_t* offset) {
|
||||
*offset = 0;
|
||||
return 0;
|
||||
}
|
||||
fclose(state_file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
fclose(state_file);
|
||||
*offset = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -254,12 +279,13 @@ int write_state_offset(const char* pad_chksum, uint64_t offset) {
|
||||
const char* pads_dir = get_current_pads_dir();
|
||||
snprintf(state_filename, sizeof(state_filename), "%s/%s.state", pads_dir, pad_chksum);
|
||||
|
||||
FILE* state_file = fopen(state_filename, "wb");
|
||||
FILE* state_file = fopen(state_filename, "w");
|
||||
if (!state_file) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (fwrite(&offset, sizeof(uint64_t), 1, state_file) != 1) {
|
||||
// Write in text format for human readability
|
||||
if (fprintf(state_file, "offset=%lu\n", offset) < 0) {
|
||||
fclose(state_file);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user