diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sql.c | 8 | ||||
-rw-r--r-- | lib/util.c | 12 |
2 files changed, 16 insertions, 4 deletions
@@ -232,7 +232,7 @@ int db_delete_oldest_bytes(sqlite3 *db, int64_t bytes) { size_t bufsize = 1024; char *buf = malloc(bufsize); - while (bytes >= 0) { + while (true) { rc = sqlite3_step(stmt); if (rc == SQLITE_DONE) break; @@ -240,8 +240,12 @@ int db_delete_oldest_bytes(sqlite3 *db, int64_t bytes) { sqlite3_int64 index = sqlite3_column_int64(stmt, 2); int size = sqlite3_column_int(stmt, 0); + bytes -= size; + if (bytes <= 0) + break; + char _buf[22]; - sprintf(_buf, count ? "%lld" : ",%lld", index); + sprintf(_buf, count ? ",%lld" : "%lld", index); while (strlen(_buf) + strlen(buf) + 2 >= bufsize) { bufsize *= 2; char *__buf = malloc(bufsize); @@ -8,6 +8,12 @@ int check_file_exist(const char *storage) { return access(storage, F_OK) != -1; } +int check_file_size(const char *storage) { + struct stat st; + stat(storage, &st); + return st.st_size; +} + int check_basedir_exist(const char *storage) { char *_storage = strdup(storage); char *basedir = dirname(_storage); @@ -28,7 +34,9 @@ enum CompressionType get_compression(const char *flag) { } else if (!strcmp(flag, "lz4")) { return COMPRESS_LZ4; } else { - fprintf(stderr, "Unknown compression algorithm: %s\n", flag); - return 0; + FATAL("Unknown compression algorithm: %s\n", flag); + exit(1); } + + return 0; } |