diff --git a/ChangeLog b/ChangeLog index 49a599cc..b0a430ec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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] diff --git a/libvips/foreign/foreign.c b/libvips/foreign/foreign.c index a0669d55..41574ee1 100644 --- a/libvips/foreign/foreign.c +++ b/libvips/foreign/foreign.c @@ -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 ); } diff --git a/libvips/include/vips/util.h b/libvips/include/vips/util.h index d9cdf93e..82862f4c 100644 --- a/libvips/include/vips/util.h +++ b/libvips/include/vips/util.h @@ -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, ... ) diff --git a/libvips/iofuncs/util.c b/libvips/iofuncs/util.c index b749541d..1aa5253a 100644 --- a/libvips/iofuncs/util.c +++ b/libvips/iofuncs/util.c @@ -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 );