@@ -623,7 +623,7 @@ static bool db_load_from_save(){
623623 db_block_free (u1);
624624 break ;
625625 case ' t' :
626- if (sscanf (bp, " t:%s" , & buffer2) != 1 ){
626+ if (sscanf (bp, " t:%s" , buffer2) != 1 ){
627627 WARN (" Table parsing error\n " );
628628 continue ;
629629 }
@@ -640,7 +640,7 @@ static bool db_load_from_save(){
640640 WARN (" File entry must be after table\n " );
641641 continue ;
642642 }
643- if (sscanf (bp+1 , " :%d:%u:%u:%u:%s" , &d1, &u2, &u3, &u4, & buffer2) != 5 ){
643+ if (sscanf (bp+1 , " :%d:%u:%u:%u:%s" , &d1, &u2, &u3, &u4, buffer2) != 5 ){
644644 WARN (" Entry parsing error\n " );
645645 continue ;
646646 }
@@ -704,8 +704,8 @@ bool db_open(const char* path) {
704704 bool will_black = false ;
705705
706706 // Create paths as char*'s
707- snprintf (db.path_root , MAX_PATH , " %s/" , path);
708- snprintf (db.path_single , MAX_PATH , " %s/files/" , path);
707+ snprintf (db.path_root , SHORT_PATH , " %s/" , path);
708+ snprintf (db.path_single , SHORT_PATH , " %s/files/" , path);
709709
710710 // Initialize folder structure if it doesnt exist
711711 db_init_folders ();
@@ -715,7 +715,7 @@ bool db_open(const char* path) {
715715 db.table_gc = kh_begin (db.tables );
716716
717717 // Load from index if available
718- snprintf (db.path_blockfile , MAX_PATH , " %s/blockfile.db" , path);
718+ snprintf (db.path_blockfile , SHORT_PATH , " %s/blockfile.db" , path);
719719
720720 if (!db_load_from_save ()){
721721 PWARN (" Unable to load index from disk, will blank database" );
@@ -736,7 +736,9 @@ bool db_open(const char* path) {
736736 if (will_black){
737737 if (size > (BLOCK_MAX_LOAD * BLOCK_LENGTH)) {
738738 size = BLOCK_MAX_LOAD * BLOCK_LENGTH;
739- ftruncate (db.fd_blockfile , size);
739+ if (ftruncate (db.fd_blockfile , size) == -1 ){
740+ PFATAL (" Failed to truncate blockfile: %s" , db.path_blockfile );
741+ }
740742 db.blocks_exist = (uint32_t )(size / BLOCK_LENGTH);
741743 }
742744 for (off64_t i = 0 ; i < size; i += BLOCK_LENGTH) {
@@ -782,7 +784,7 @@ void db_target_open(struct cache_target* target, bool write) {
782784 target->fd = db_entry_open (target->entry , 0 );
783785 }
784786 if (target->fd <= 0 ) {
785- WARN (" Unable to open cache file: %d " , target->entry );
787+ WARN (" Unable to open cache file: %s " , target->entry -> key );
786788 }
787789 }
788790 else {
@@ -1391,7 +1393,7 @@ static pid_t db_index_flush(bool copyOnWrite){
13911393 if (ce->writing || ce->deleted ) continue ;
13921394
13931395 // Write entry key to index
1394- temp = snprintf (buffer, sizeof (buffer), " %s:%d:%u:%u :%u:" , ce->block >= 0 ? " b" :" e" , ce->block , ce->data_length , ce->expires , ce->it );
1396+ temp = snprintf (buffer, sizeof (buffer), " %s:%d:%u:%lu :%u:" , ce->block >= 0 ? " b" :" e" , ce->block , ce->data_length , ce->expires , ce->it );
13951397 if (!full_write (fd, buffer, temp)) goto close_fd;
13961398 if (!full_write (fd, ce->key , ce->key_length )) goto close_fd;
13971399 if (!full_write (fd, " \n " , 1 )) goto close_fd;
0 commit comments