Lines Matching refs:file

1 /* Copyright (c) 2010-2018 Dovecot authors, see the included COPYING file */
18 struct fs_file file;
82 struct sis_fs_file *file = i_new(struct sis_fs_file, 1);
83 return &file->file;
90 struct sis_fs_file *file = (struct sis_fs_file *)_file;
94 file->file.path = i_strdup(path);
95 file->fs = fs;
96 file->open_mode = mode;
108 file->hash_path = i_strdup_printf("%s/"HASH_DIR_NAME"/%s", dir, hash);
109 file->hash_file = fs_file_init_parent(_file, file->hash_path,
112 file->hash_input = fs_read_stream(file->hash_file, IO_BLOCK_SIZE);
113 if (i_stream_read(file->hash_input) == -1) {
116 e_error(file->file.event, "Couldn't read hash file %s: %m",
117 file->hash_path);
119 i_stream_destroy(&file->hash_input);
122 file->file.parent = fs_file_init_parent(_file, path, mode | flags);
127 struct sis_fs_file *file = (struct sis_fs_file *)_file;
129 fs_file_deinit(&file->hash_file);
131 i_free(file->hash);
132 i_free(file->hash_path);
133 i_free(file->file.path);
134 i_free(file);
139 struct sis_fs_file *file = (struct sis_fs_file *)_file;
141 i_stream_unref(&file->hash_input);
142 fs_file_close(file->hash_file);
146 static bool fs_sis_try_link(struct sis_fs_file *file)
151 if (i_stream_stat(file->hash_input, FALSE, &st) < 0)
154 /* we can use the existing file */
155 if (fs_copy(file->hash_file, file->file.parent) < 0) {
157 e_error(file->file.event, "%s",
158 fs_file_last_error(file->hash_file));
163 if (fs_stat(file->file.parent, &st2) < 0) {
164 e_error(file->file.event, "%s",
165 fs_file_last_error(file->file.parent));
166 if (fs_delete(file->file.parent) < 0) {
167 e_error(file->file.event, "%s",
168 fs_file_last_error(file->file.parent));
173 /* the hashes/ file was already replaced with something else */
174 if (fs_delete(file->file.parent) < 0) {
175 e_error(file->file.event, "%s",
176 fs_file_last_error(file->file.parent));
183 static void fs_sis_replace_hash_file(struct sis_fs_file *file)
185 struct fs *super_fs = file->file.parent->fs;
191 if (file->hash_input == NULL) {
192 /* hash file didn't exist previously. we should be able to
194 if (fs_copy(file->file.parent, file->hash_file) < 0) {
196 /* the file was just created. it's probably
200 e_error(file->file.event, "%s",
208 hash_fname = strrchr(file->hash_path, '/');
210 hash_fname = file->hash_path;
212 str_append_n(temp_path, file->hash_path,
213 (hash_fname-file->hash_path) + 1);
219 /* replace existing hash file atomically */
220 temp_file = fs_file_init_parent(&file->file, str_c(temp_path),
222 ret = fs_copy(file->file.parent, temp_file);
224 /* either someone's racing us or it's a stale file.
228 e_error(file->file.event, "%s", fs_last_error(super_fs));
229 ret = fs_copy(file->file.parent, temp_file);
232 e_error(file->file.event, "%s", fs_last_error(super_fs));
237 if (fs_rename(temp_file, file->hash_file) < 0) {
241 e_error(file->file.event, "%s", fs_last_error(super_fs));
250 struct sis_fs_file *file = (struct sis_fs_file *)_file;
255 if (file->hash_input != NULL &&
256 stream_cmp_block(file->hash_input, data, size) &&
257 i_stream_read_eof(file->hash_input)) {
258 /* try to use existing file */
259 if (fs_sis_try_link(file))
266 fs_sis_replace_hash_file(file);
273 struct sis_fs_file *file = (struct sis_fs_file *)_file;
281 file->fs_output = fs_write_stream(_file->parent);
282 if (file->hash_input == NULL) {
283 _file->output = file->fs_output;
287 _file->output = o_stream_create_cmp(file->fs_output,
288 file->hash_input);
296 struct sis_fs_file *file = (struct sis_fs_file *)_file;
300 fs_write_stream_abort_parent(_file, &file->fs_output);
305 if (file->hash_input != NULL &&
307 i_stream_read_eof(file->hash_input)) {
309 if (fs_sis_try_link(file)) {
310 fs_write_stream_abort_parent(_file, &file->fs_output);
317 if (fs_write_stream_finish(_file->parent, &file->fs_output) < 0)
320 fs_sis_replace_hash_file(file);