Mercurial > dovecot > core-2.2
changeset 16269:5ce775d70c7d
lib-fs: Added fs_file_close() to explicitly close all streams that the file has open.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 10 Apr 2013 21:18:07 +0300 |
parents | a3bd79aec23a |
children | 0ff3c63eb183 |
files | src/lib-fs/fs-api-private.h src/lib-fs/fs-api.c src/lib-fs/fs-api.h src/lib-fs/fs-metawrap.c src/lib-fs/fs-posix.c src/lib-fs/fs-sis-queue.c src/lib-fs/fs-sis.c |
diffstat | 7 files changed, 59 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-fs/fs-api-private.h Wed Apr 10 18:48:54 2013 +0300 +++ b/src/lib-fs/fs-api-private.h Wed Apr 10 21:18:07 2013 +0300 @@ -15,6 +15,7 @@ enum fs_open_mode mode, enum fs_open_flags flags); void (*file_deinit)(struct fs_file *file); + void (*file_close)(struct fs_file *file); const char *(*get_path)(struct fs_file *file); void (*set_async_callback)(struct fs_file *file,
--- a/src/lib-fs/fs-api.c Wed Apr 10 18:48:54 2013 +0300 +++ b/src/lib-fs/fs-api.c Wed Apr 10 21:18:07 2013 +0300 @@ -164,6 +164,19 @@ *_file = NULL; + fs_file_close(file); + + file->fs->files_open_count--; + T_BEGIN { + file->fs->v.file_deinit(file); + } T_END; + + if (metadata_pool != NULL) + pool_unref(&metadata_pool); +} + +void fs_file_close(struct fs_file *file) +{ if (file->pending_read_input != NULL) i_stream_unref(&file->pending_read_input); if (file->seekable_input != NULL) @@ -173,14 +186,9 @@ i_stream_unref(&file->copy_input); (void)fs_write_stream_abort(file, &file->copy_output); } - - file->fs->files_open_count--; - T_BEGIN { - file->fs->v.file_deinit(file); + if (file->fs->v.file_close != NULL) T_BEGIN { + file->fs->v.file_close(file); } T_END; - - if (metadata_pool != NULL) - pool_unref(&metadata_pool); } enum fs_properties fs_get_properties(struct fs *fs)
--- a/src/lib-fs/fs-api.h Wed Apr 10 18:48:54 2013 +0300 +++ b/src/lib-fs/fs-api.h Wed Apr 10 21:18:07 2013 +0300 @@ -95,6 +95,9 @@ struct fs_file *fs_file_init(struct fs *fs, const char *path, int mode_flags); void fs_file_deinit(struct fs_file **file); +/* If the file has an input streams open, close them. */ +void fs_file_close(struct fs_file *file); + /* Return properties supported by backend. */ enum fs_properties fs_get_properties(struct fs *fs);
--- a/src/lib-fs/fs-metawrap.c Wed Apr 10 18:48:54 2013 +0300 +++ b/src/lib-fs/fs-metawrap.c Wed Apr 10 21:18:07 2013 +0300 @@ -123,15 +123,25 @@ { struct metawrap_fs_file *file = (struct metawrap_fs_file *)_file; - if (file->input != NULL) - i_stream_unref(&file->input); - if (file->super_read != file->super) + if (file->super_read != file->super && file->super_read != NULL) fs_file_deinit(&file->super_read); fs_file_deinit(&file->super); i_free(file->file.path); i_free(file); } +static void fs_metawrap_file_close(struct fs_file *_file) +{ + struct metawrap_fs_file *file = (struct metawrap_fs_file *)_file; + + if (file->input != NULL) + i_stream_unref(&file->input); + if (file->super_read != NULL) + fs_file_close(file->super_read); + if (file->super != NULL) + fs_file_close(file->super); +} + static const char *fs_metawrap_file_get_path(struct fs_file *_file) { struct metawrap_fs_file *file = (struct metawrap_fs_file *)_file; @@ -408,6 +418,7 @@ fs_metawrap_get_properties, fs_metawrap_file_init, fs_metawrap_file_deinit, + fs_metawrap_file_close, fs_metawrap_file_get_path, fs_metawrap_set_async_callback, fs_metawrap_wait_async,
--- a/src/lib-fs/fs-posix.c Wed Apr 10 18:48:54 2013 +0300 +++ b/src/lib-fs/fs-posix.c Wed Apr 10 21:18:07 2013 +0300 @@ -252,8 +252,10 @@ return &file->file; } -static void fs_posix_file_close(struct posix_fs_file *file) +static void fs_posix_file_close(struct fs_file *_file) { + struct posix_fs_file *file = (struct posix_fs_file *)_file; + if (file->fd != -1 && file->file.output == NULL) { if (close(file->fd) < 0) { fs_set_critical(file->file.fs, "close(%s) failed: %m", @@ -286,7 +288,6 @@ break; } - fs_posix_file_close(file); i_free(file->temp_path); i_free(file->file.path); i_free(file); @@ -333,7 +334,7 @@ ret = read(file->fd, buf, size); if (ret < 0) fs_set_error(_file->fs, "read(%s) failed: %m", _file->path); - fs_posix_file_close(file); + fs_posix_file_close(_file); return ret; } @@ -349,7 +350,7 @@ } else { input = i_stream_create_fd(file->fd, max_buffer_size, FALSE); } - i_stream_add_destroy_callback(input, fs_posix_file_close, file); + i_stream_add_destroy_callback(input, fs_posix_file_close, _file); return input; } @@ -754,6 +755,7 @@ fs_posix_get_properties, fs_posix_file_init, fs_posix_file_deinit, + fs_posix_file_close, NULL, NULL, NULL, NULL, NULL,
--- a/src/lib-fs/fs-sis-queue.c Wed Apr 10 18:48:54 2013 +0300 +++ b/src/lib-fs/fs-sis-queue.c Wed Apr 10 21:18:07 2013 +0300 @@ -117,6 +117,14 @@ i_free(file); } +static void fs_sis_queue_file_close(struct fs_file *_file) +{ + struct sis_queue_fs_file *file = (struct sis_queue_fs_file *)_file; + + if (file->super != NULL) + fs_file_close(file->super); +} + static const char *fs_sis_queue_file_get_path(struct fs_file *_file) { struct sis_queue_fs_file *file = (struct sis_queue_fs_file *)_file; @@ -352,6 +360,7 @@ fs_sis_queue_get_properties, fs_sis_queue_file_init, fs_sis_queue_file_deinit, + fs_sis_queue_file_close, fs_sis_queue_file_get_path, fs_sis_queue_set_async_callback, fs_sis_queue_wait_async,
--- a/src/lib-fs/fs-sis.c Wed Apr 10 18:48:54 2013 +0300 +++ b/src/lib-fs/fs-sis.c Wed Apr 10 21:18:07 2013 +0300 @@ -145,8 +145,6 @@ { struct sis_fs_file *file = (struct sis_fs_file *)_file; - if (file->hash_input != NULL) - i_stream_unref(&file->hash_input); fs_file_deinit(&file->hash_file); fs_file_deinit(&file->super); i_free(file->hash); @@ -155,6 +153,16 @@ i_free(file); } +static void fs_sis_file_close(struct fs_file *_file) +{ + struct sis_fs_file *file = (struct sis_fs_file *)_file; + + if (file->hash_input != NULL) + i_stream_unref(&file->hash_input); + fs_file_close(file->hash_file); + fs_file_close(file->super); +} + static const char *fs_sis_file_get_path(struct fs_file *_file) { struct sis_fs_file *file = (struct sis_fs_file *)_file; @@ -486,6 +494,7 @@ fs_sis_get_properties, fs_sis_file_init, fs_sis_file_deinit, + fs_sis_file_close, fs_sis_file_get_path, fs_sis_set_async_callback, fs_sis_wait_async,