add dir detector

useful for blocking open for read of directories
This commit is contained in:
John Cupitt 2020-03-06 18:05:16 +00:00
parent d13c0a69fd
commit a592d99bb2
4 changed files with 31 additions and 5 deletions

View File

@ -13,6 +13,7 @@
VIPS_PIPE_READ_LIMIT
- revise gifload to fix BACKGROUND and PREVIOUS dispose [alon-ne]
- add subsample_mode, deprecate no_subsample in jpegsave [Elad-Laufer]
- add vips_isdirf()
31/1/19 started 8.9.2
- fix a deadlock with --vips-leak [DarthSim]

View File

@ -535,7 +535,12 @@ vips_foreign_find_load( const char *name )
*/
if( !vips_existsf( "%s", filename ) ) {
vips_error( "VipsForeignLoad",
_( "file \"%s\" not readable" ), name );
_( "file \"%s\" does not exist" ), name );
return( NULL );
}
if( vips_isdirf( "%s", filename ) ) {
vips_error( "VipsForeignLoad",
_( "\"%s\" is a directory" ), name );
return( NULL );
}

View File

@ -281,6 +281,8 @@ gint64 vips__seek( int fd, gint64 pos, int whence );
int vips__ftruncate( int fd, gint64 pos );
int vips_existsf( const char *name, ... )
__attribute__((format(printf, 1, 2)));
int vips_isdirf( const char *name, ... )
__attribute__((format(printf, 1, 2)));
int vips_mkdirf( const char *name, ... )
__attribute__((format(printf, 1, 2)));
int vips_rmdirf( const char *name, ... )

View File

@ -1157,7 +1157,7 @@ vips__ftruncate( int fd, gint64 pos )
return( 0 );
}
/* TRUE if file exists and is not a directory.
/* TRUE if file exists. True for directories as well.
*/
gboolean
vips_existsf( const char *name, ... )
@ -1170,9 +1170,27 @@ vips_existsf( const char *name, ... )
path = g_strdup_vprintf( name, ap );
va_end( ap );
/* A regular (not a directory) file.
*/
result = g_file_test( path, G_FILE_TEST_IS_REGULAR );
result = g_file_test( path, G_FILE_TEST_EXISTS );
g_free( path );
return( result );
}
/* TRUE if file exists and is a directory.
*/
gboolean
vips_isdirf( const char *name, ... )
{
va_list ap;
char *path;
gboolean result;
va_start( ap, name );
path = g_strdup_vprintf( name, ap );
va_end( ap );
result = g_file_test( path, G_FILE_TEST_IS_DIR );
g_free( path );