|
71 | 71 | * - add dzsave_buffer
|
72 | 72 | * 11/11/16 Felix Bünemann
|
73 | 73 | * - better >4gb detection for zip output on older libgsfs
|
| 74 | + * 18/8/17 |
| 75 | + * - shut down the output earlier to flush zip output |
74 | 76 | */
|
75 | 77 |
|
76 | 78 | /*
|
@@ -210,47 +212,28 @@ vips_gsf_tree_close( VipsGsfDirectory *tree )
|
210 | 212 | vips_slist_map2( tree->children,
|
211 | 213 | (VipsSListMap2Fn) vips_gsf_tree_close, NULL, NULL );
|
212 | 214 |
|
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 | + } |
239 | 222 |
|
240 |
| - if( tree->out ) { |
241 |
| - if( !gsf_output_is_closed( tree->out ) ) |
242 |
| - (void) gsf_output_close( tree->out ); |
243 | 223 | g_object_unref( tree->out );
|
244 | 224 | }
|
245 | 225 |
|
246 | 226 | 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 | + |
249 | 234 | g_object_unref( tree->container );
|
250 | 235 | }
|
251 | 236 |
|
252 |
| - g_free( tree ); |
253 |
| - |
254 | 237 | return( NULL );
|
255 | 238 | }
|
256 | 239 |
|
@@ -562,7 +545,7 @@ vips_foreign_save_dz_dispose( GObject *gobject )
|
562 | 545 | VipsForeignSaveDz *dz = (VipsForeignSaveDz *) gobject;
|
563 | 546 |
|
564 | 547 | VIPS_FREEF( layer_free, dz->layer );
|
565 |
| - VIPS_FREEF( vips_gsf_tree_free, dz->tree ); |
| 548 | + VIPS_FREEF( vips_gsf_tree_close, dz->tree ); |
566 | 549 | VIPS_FREEF( g_object_unref, dz->out );
|
567 | 550 | VIPS_FREE( dz->basename );
|
568 | 551 | VIPS_FREE( dz->dirname );
|
@@ -1908,9 +1891,6 @@ vips_foreign_save_dz_build( VipsObject *object )
|
1908 | 1891 | write_vips_meta( dz ) )
|
1909 | 1892 | return( -1 );
|
1910 | 1893 |
|
1911 |
| - if( vips_gsf_tree_close( dz->tree ) ) |
1912 |
| - return( -1 ); |
1913 |
| - |
1914 | 1894 | /* This is so ugly. In earlier versions of dzsave, we wrote x.dzi and
|
1915 | 1895 | * x_files. Now we write x/x.dzi and x/x_files to make it possible to
|
1916 | 1896 | * create zip files.
|
@@ -1942,6 +1922,19 @@ vips_foreign_save_dz_build( VipsObject *object )
|
1942 | 1922 | return( -1 );
|
1943 | 1923 | }
|
1944 | 1924 |
|
| 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 | + |
1945 | 1938 | return( 0 );
|
1946 | 1939 | }
|
1947 | 1940 |
|
|
0 commit comments