@@ -397,7 +397,7 @@ static void disk_destroy(cache *_c) {
397397
398398cache * cache_disk (const char * dirpath , cache * mem ,
399399 kwrite_fn kwrite , vwrite_fn vwrite ,
400- kread_fn kread , vread_fn vread ) {
400+ kread_fn kread , vread_fn vread , error * e ) {
401401 struct stat st ;
402402 disk_cache * res ;
403403 char * dirp ;
@@ -414,7 +414,10 @@ cache *cache_disk(const char *dirpath, cache *mem,
414414
415415 dirp = malloc (dirl + 1 ); /* With the NUL */
416416
417- if (dirp == NULL ) return NULL ;
417+ if (dirp == NULL ) {
418+ error_sys (e , "malloc" );
419+ return NULL ;
420+ }
418421
419422 strlcpy (dirp , dirpath , dirl + 1 );
420423
@@ -425,6 +428,7 @@ cache *cache_disk(const char *dirpath, cache *mem,
425428
426429 if (ensurep (NULL , dirp ) != 0 ) {
427430 free (dirp );
431+ error_sys (e , "ensurep" );
428432 return NULL ;
429433 }
430434
@@ -433,18 +437,24 @@ cache *cache_disk(const char *dirpath, cache *mem,
433437
434438 mkdir (dirp , 0777 ); /* This may fail, but it's ok */
435439
436- if (lstat (dirp , & st ) != 0 )
440+ if (lstat (dirp , & st ) != 0 ) {
441+ error_sys (e , "lstat" );
437442 return NULL ;
443+ }
438444
439445 /* Restore the good path at the end */
440446 dirp [dirl - 1 ] = sep ;
441447
442- if (!(st .st_mode & S_IFDIR ))
448+ if (!(st .st_mode & S_IFDIR )) {
449+ error_set (e , GA_SYS_ERROR , "Cache path exists but is not a directory" );
443450 return NULL ;
451+ }
444452
445453 res = calloc (sizeof (* res ), 1 );
446- if (res == NULL )
454+ if (res == NULL ) {
455+ error_sys (e , "calloc" );
447456 return NULL ;
457+ }
448458
449459 res -> dirp = dirp ;
450460 res -> mem = mem ;
0 commit comments