@@ -234,17 +234,17 @@ get_file_type (mode_t *mode, bool nofollow, const char *path)
234234}
235235
236236int
237- create_file_if_missing_at (int dirfd , const char * file , libcrun_error_t * err )
237+ create_file_if_missing_at (int dirfd , const char * file , mode_t mode , libcrun_error_t * err )
238238{
239- cleanup_close int fd_write = openat (dirfd , file , O_CLOEXEC | O_CREAT | O_WRONLY , 0700 );
239+ cleanup_close int fd_write = openat (dirfd , file , O_CLOEXEC | O_CREAT | O_WRONLY , mode );
240240 if (fd_write < 0 )
241241 {
242- mode_t mode ;
242+ mode_t tmp_mode ;
243243 int ret ;
244244
245245 /* On errors, check if the file already exists. */
246- ret = get_file_type_at (dirfd , & mode , false, file );
247- if (ret == 0 && S_ISREG (mode ))
246+ ret = get_file_type_at (dirfd , & tmp_mode , false, file );
247+ if (ret == 0 && S_ISREG (tmp_mode ))
248248 return 0 ;
249249
250250 return crun_make_error (err , errno , "creating file `%s`" , file );
@@ -627,33 +627,6 @@ crun_ensure_directory (const char *path, int mode, bool nofollow, libcrun_error_
627627 return crun_ensure_directory_at (AT_FDCWD , path , mode , nofollow , err );
628628}
629629
630- int
631- crun_ensure_file_at (int dirfd , const char * path , int mode , bool nofollow , libcrun_error_t * err )
632- {
633- cleanup_free char * tmp = xstrdup (path );
634- size_t len = strlen (tmp );
635- char * it = tmp + len - 1 ;
636- int ret ;
637-
638- while (* it != '/' && it > tmp )
639- it -- ;
640- if (it > tmp )
641- {
642- * it = '\0' ;
643- ret = crun_ensure_directory_at (dirfd , tmp , mode , nofollow , err );
644- if (UNLIKELY (ret < 0 ))
645- return ret ;
646- * it = '/' ;
647- }
648- return create_file_if_missing_at (dirfd , tmp , err );
649- }
650-
651- int
652- crun_ensure_file (const char * path , int mode , bool nofollow , libcrun_error_t * err )
653- {
654- return crun_ensure_file_at (AT_FDCWD , path , mode , nofollow , err );
655- }
656-
657630static int
658631get_file_size (int fd , off_t * size )
659632{
0 commit comments