Skip to content

Commit f2c55e8

Browse files
committed
better dzsave with zip output to a file
close down output earlier to help mark-sweep bindings
1 parent 279c1ef commit f2c55e8

File tree

2 files changed

+31
-37
lines changed

2 files changed

+31
-37
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
2/8/17 started 8.5.8
22
- fix transparency detection in merge, thanks Haida
33
- define env var VIPS_WARNING to hide warning messages
4+
- shut down dzsave output earlier to help mark-sweep bindings
45

56
9/6/17 started 8.5.7
67
- better smartcrop

libvips/foreign/dzsave.c

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
* - add dzsave_buffer
7272
* 11/11/16 Felix Bünemann
7373
* - better >4gb detection for zip output on older libgsfs
74+
* 18/8/17
75+
* - shut down the output earlier to flush zip output
7476
*/
7577

7678
/*
@@ -210,47 +212,28 @@ vips_gsf_tree_close( VipsGsfDirectory *tree )
210212
vips_slist_map2( tree->children,
211213
(VipsSListMap2Fn) vips_gsf_tree_close, NULL, NULL );
212214

213-
if( tree->out &&
214-
!gsf_output_is_closed( tree->out ) &&
215-
!gsf_output_close( tree->out ) ) {
216-
vips_error( "vips_gsf", "%s", _( "unable to close stream" ) );
217-
return( tree );
218-
}
219-
if( tree->container &&
220-
!gsf_output_is_closed( tree->container ) &&
221-
!gsf_output_close( tree->container ) ) {
222-
vips_error( "vips_gsf", "%s", _( "unable to close stream" ) );
223-
return( tree );
224-
}
225-
226-
return( NULL );
227-
}
228-
229-
/* Close and unref everything, can't fail. Call vips_gsf_tree_close() to get
230-
* an error return.
231-
*/
232-
static void *
233-
vips_gsf_tree_free( VipsGsfDirectory *tree )
234-
{
235-
vips_slist_map2( tree->children,
236-
(VipsSListMap2Fn) vips_gsf_tree_free, NULL, NULL );
237-
g_slist_free( tree->children );
238-
g_free( (char *) tree->name );
215+
if( tree->out ) {
216+
if( !gsf_output_is_closed( tree->out ) &&
217+
!gsf_output_close( tree->out ) ) {
218+
vips_error( "vips_gsf",
219+
"%s", _( "unable to close stream" ) );
220+
return( tree );
221+
}
239222

240-
if( tree->out ) {
241-
if( !gsf_output_is_closed( tree->out ) )
242-
(void) gsf_output_close( tree->out );
243223
g_object_unref( tree->out );
244224
}
245225

246226
if( tree->container ) {
247-
if( !gsf_output_is_closed( tree->container ) )
248-
(void) gsf_output_close( tree->container );
227+
if( !gsf_output_is_closed( tree->container ) &&
228+
!gsf_output_close( tree->container ) ) {
229+
vips_error( "vips_gsf",
230+
"%s", _( "unable to close stream" ) );
231+
return( tree );
232+
}
233+
249234
g_object_unref( tree->container );
250235
}
251236

252-
g_free( tree );
253-
254237
return( NULL );
255238
}
256239

@@ -562,7 +545,7 @@ vips_foreign_save_dz_dispose( GObject *gobject )
562545
VipsForeignSaveDz *dz = (VipsForeignSaveDz *) gobject;
563546

564547
VIPS_FREEF( layer_free, dz->layer );
565-
VIPS_FREEF( vips_gsf_tree_free, dz->tree );
548+
VIPS_FREEF( vips_gsf_tree_close, dz->tree );
566549
VIPS_FREEF( g_object_unref, dz->out );
567550
VIPS_FREE( dz->basename );
568551
VIPS_FREE( dz->dirname );
@@ -1908,9 +1891,6 @@ vips_foreign_save_dz_build( VipsObject *object )
19081891
write_vips_meta( dz ) )
19091892
return( -1 );
19101893

1911-
if( vips_gsf_tree_close( dz->tree ) )
1912-
return( -1 );
1913-
19141894
/* This is so ugly. In earlier versions of dzsave, we wrote x.dzi and
19151895
* x_files. Now we write x/x.dzi and x/x_files to make it possible to
19161896
* create zip files.
@@ -1942,6 +1922,19 @@ vips_foreign_save_dz_build( VipsObject *object )
19421922
return( -1 );
19431923
}
19441924

1925+
/* Shut down the output to flush everything.
1926+
*/
1927+
if( vips_gsf_tree_close( dz->tree ) )
1928+
return( -1 );
1929+
dz->tree = NULL;
1930+
1931+
/* If we are writing a zip to the filesystem, we must unref out to
1932+
* force it to disc.
1933+
*/
1934+
if( dz->container == VIPS_FOREIGN_DZ_CONTAINER_ZIP &&
1935+
dz->dirname != NULL )
1936+
VIPS_FREEF( g_object_unref, dz->out );
1937+
19451938
return( 0 );
19461939
}
19471940

0 commit comments

Comments
 (0)