rearrange tree after dz save to fs for compat
rearrange the directory tree after dzsave for compatibility with earlier libvips
This commit is contained in:
parent
ccead97c05
commit
d9affe1c2a
@ -1607,6 +1607,37 @@ vips_foreign_save_dz_build( VipsObject *object )
|
||||
if( vips_gsf_tree_close( dz->tree ) )
|
||||
return( -1 );
|
||||
|
||||
/* This is so ugly. In earlier versions of dzsave, we wrote x.dzi and
|
||||
* x_files. Now we write x/x.dzi and x/x_files to make it possible to
|
||||
* create zip files.
|
||||
*
|
||||
* For compatibility, rearrange the directory tree.
|
||||
*
|
||||
* FIXME have a flag to stop this stupidity
|
||||
*/
|
||||
if( dz->layout == VIPS_FOREIGN_DZ_LAYOUT_DZ &&
|
||||
dz->container == VIPS_FOREIGN_DZ_CONTAINER_FS ) {
|
||||
char old_name[VIPS_PATH_MAX];
|
||||
char new_name[VIPS_PATH_MAX];
|
||||
|
||||
vips_snprintf( old_name, VIPS_PATH_MAX, "%s/%s/%s.dzi",
|
||||
dz->dirname, dz->basename, dz->basename );
|
||||
vips_snprintf( new_name, VIPS_PATH_MAX, "%s/%s.dzi",
|
||||
dz->dirname, dz->basename );
|
||||
if( vips_rename( old_name, new_name ) )
|
||||
return( -1 );
|
||||
|
||||
vips_snprintf( old_name, VIPS_PATH_MAX, "%s/%s/%s_files",
|
||||
dz->dirname, dz->basename, dz->basename );
|
||||
vips_snprintf( new_name, VIPS_PATH_MAX, "%s/%s_files",
|
||||
dz->dirname, dz->basename );
|
||||
if( vips_rename( old_name, new_name ) )
|
||||
return( -1 );
|
||||
|
||||
if( vips_rmdirf( "%s/%s", dz->dirname, dz->basename ) )
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
|
@ -219,6 +219,9 @@ int vips_existsf( 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, ... )
|
||||
__attribute__((format(printf, 1, 2)));
|
||||
int vips_rename( const char *old_name, const char *new_name );
|
||||
FILE *vips_popenf( const char *fmt, const char *mode, ... )
|
||||
__attribute__((format(printf, 1, 3)));
|
||||
|
||||
|
@ -1060,6 +1060,45 @@ vips_mkdirf( const char *name, ... )
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/* Remove a directory.
|
||||
*/
|
||||
int
|
||||
vips_rmdirf( const char *name, ... )
|
||||
{
|
||||
va_list ap;
|
||||
char *path;
|
||||
|
||||
va_start( ap, name );
|
||||
path = g_strdup_vprintf( name, ap );
|
||||
va_end( ap );
|
||||
|
||||
if( g_rmdir( path ) ) {
|
||||
vips_error( "rmdir",
|
||||
_( "unable to remove directory \"%s\", %s" ),
|
||||
path, strerror( errno ) );
|
||||
g_free( path );
|
||||
return( -1 );
|
||||
}
|
||||
g_free( path );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/* Rename a file.
|
||||
*/
|
||||
int
|
||||
vips_rename( const char *old_name, const char *new_name )
|
||||
{
|
||||
if( g_rename( old_name, new_name ) ) {
|
||||
vips_error( "rename",
|
||||
_( "unable to rename file \"%s\" as \"%s\", %s" ),
|
||||
old_name, new_name, strerror( errno ) );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/* Chop off any trailing whitespace.
|
||||
*/
|
||||
void
|
||||
|
Loading…
Reference in New Issue
Block a user