Mercurial > dovecot > original-hg > dovecot-1.2
comparison src/lib-storage/index/dbox/dbox-file.c @ 6940:414c9d631a81 HEAD
Replaced t_push/t_pop calls with T_FRAME*() macros.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 05 Dec 2007 17:47:44 +0200 |
parents | 47c746a769ba |
children | f2c37fe48668 |
comparison
equal
deleted
inserted
replaced
6939:c7b42fea5fcc | 6940:414c9d631a81 |
---|---|
326 pos = 2; | 326 pos = 2; |
327 | 327 |
328 file->append_offset = 0; | 328 file->append_offset = 0; |
329 file->msg_header_size = 0; | 329 file->msg_header_size = 0; |
330 | 330 |
331 t_push(); | |
332 for (tmp = t_strsplit(line, " "); *tmp != NULL; tmp++) { | 331 for (tmp = t_strsplit(line, " "); *tmp != NULL; tmp++) { |
333 key = **tmp; | 332 key = **tmp; |
334 value = *tmp + 1; | 333 value = *tmp + 1; |
335 | 334 |
336 switch (key) { | 335 switch (key) { |
346 file->create_time = strtoul(value, NULL, 16); | 345 file->create_time = strtoul(value, NULL, 16); |
347 break; | 346 break; |
348 } | 347 } |
349 pos += strlen(value) + 2; | 348 pos += strlen(value) + 2; |
350 } | 349 } |
351 t_pop(); | |
352 | 350 |
353 if (file->msg_header_size == 0) { | 351 if (file->msg_header_size == 0) { |
354 dbox_file_set_corrupted(file, "Missing message header size"); | 352 dbox_file_set_corrupted(file, "Missing message header size"); |
355 return -1; | 353 return -1; |
356 } | 354 } |
361 } | 359 } |
362 | 360 |
363 static int dbox_file_read_header(struct dbox_file *file) | 361 static int dbox_file_read_header(struct dbox_file *file) |
364 { | 362 { |
365 const char *line; | 363 const char *line; |
364 int ret; | |
366 | 365 |
367 i_stream_seek(file->input, 0); | 366 i_stream_seek(file->input, 0); |
368 line = i_stream_read_next_line(file->input); | 367 line = i_stream_read_next_line(file->input); |
369 if (line == NULL) { | 368 if (line == NULL) { |
370 if (file->input->stream_errno == 0) | 369 if (file->input->stream_errno == 0) |
372 | 371 |
373 dbox_file_set_syscall_error(file, "read"); | 372 dbox_file_set_syscall_error(file, "read"); |
374 return -1; | 373 return -1; |
375 } | 374 } |
376 file->file_header_size = file->input->v_offset; | 375 file->file_header_size = file->input->v_offset; |
377 return dbox_file_parse_header(file, line) < 0 ? 0 : 1; | 376 T_FRAME( |
377 ret = dbox_file_parse_header(file, line) < 0 ? 0 : 1; | |
378 ); | |
379 return ret; | |
378 } | 380 } |
379 | 381 |
380 static int dbox_file_open_fd(struct dbox_file *file) | 382 static int dbox_file_open_fd(struct dbox_file *file) |
381 { | 383 { |
382 const char *path; | 384 const char *path; |
987 | 989 |
988 dbox_index_unlock_file(file->mbox->dbox_index, file->file_id); | 990 dbox_index_unlock_file(file->mbox->dbox_index, file->file_id); |
989 return ret; | 991 return ret; |
990 } | 992 } |
991 | 993 |
992 int dbox_file_metadata_write(struct dbox_file *file) | 994 static int dbox_file_metadata_write_real(struct dbox_file *file) |
993 { | 995 { |
994 const char *const *metadata, *const *changes; | 996 const char *const *metadata, *const *changes; |
995 unsigned int i, j, count, changes_count, space_needed, skip_pos; | 997 unsigned int i, j, count, changes_count, space_needed, skip_pos; |
996 char space[DBOX_EXTRA_SPACE]; | 998 char space[DBOX_EXTRA_SPACE]; |
997 string_t *str; | 999 string_t *str; |
1020 if (j != changes_count) | 1022 if (j != changes_count) |
1021 break; | 1023 break; |
1022 skip_pos += strlen(metadata[i]) + 1; | 1024 skip_pos += strlen(metadata[i]) + 1; |
1023 } | 1025 } |
1024 | 1026 |
1025 t_push(); | |
1026 str = t_str_new(512); | 1027 str = t_str_new(512); |
1027 last_change_len = orig_len = 0; | 1028 last_change_len = orig_len = 0; |
1028 /* overwrite existing metadata fields */ | 1029 /* overwrite existing metadata fields */ |
1029 for (; i < count; i++) { | 1030 for (; i < count; i++) { |
1030 for (j = 0; j < changes_count; j++) { | 1031 for (j = 0; j < changes_count; j++) { |
1056 } | 1057 } |
1057 } | 1058 } |
1058 str_truncate(str, last_change_len); | 1059 str_truncate(str, last_change_len); |
1059 if (skip_pos + str_len(str) >= file->metadata_len) { | 1060 if (skip_pos + str_len(str) >= file->metadata_len) { |
1060 if ((ret = dbox_file_grow_metadata(file, skip_pos + | 1061 if ((ret = dbox_file_grow_metadata(file, skip_pos + |
1061 str_len(str))) <= 0) { | 1062 str_len(str))) <= 0) |
1062 t_pop(); | |
1063 return ret; | 1063 return ret; |
1064 } | |
1065 } | 1064 } |
1066 | 1065 |
1067 memset(space, DBOX_METADATA_SPACE, sizeof(space)); | 1066 memset(space, DBOX_METADATA_SPACE, sizeof(space)); |
1068 while (skip_pos + str_len(str) < file->metadata_space_pos) { | 1067 while (skip_pos + str_len(str) < file->metadata_space_pos) { |
1069 space_needed = file->metadata_space_pos - | 1068 space_needed = file->metadata_space_pos - |
1072 } | 1071 } |
1073 i_assert(skip_pos + str_len(str) <= file->metadata_len); | 1072 i_assert(skip_pos + str_len(str) <= file->metadata_len); |
1074 | 1073 |
1075 ret = pwrite_full(file->fd, str_data(str), str_len(str), | 1074 ret = pwrite_full(file->fd, str_data(str), str_len(str), |
1076 offset + skip_pos); | 1075 offset + skip_pos); |
1077 if (ret < 0) | 1076 if (ret < 0) { |
1078 dbox_file_set_syscall_error(file, "pwrite"); | 1077 dbox_file_set_syscall_error(file, "pwrite"); |
1079 t_pop(); | 1078 return -1; |
1080 return ret < 0 ? -1 : 1; | 1079 } |
1080 return 1; | |
1081 } | |
1082 | |
1083 int dbox_file_metadata_write(struct dbox_file *file) | |
1084 { | |
1085 int ret; | |
1086 | |
1087 T_FRAME( | |
1088 ret = dbox_file_metadata_write_real(file); | |
1089 ); | |
1090 return ret; | |
1081 } | 1091 } |
1082 | 1092 |
1083 int dbox_file_metadata_write_to(struct dbox_file *file, struct ostream *output) | 1093 int dbox_file_metadata_write_to(struct dbox_file *file, struct ostream *output) |
1084 { | 1094 { |
1085 struct dbox_metadata_header metadata_hdr; | 1095 struct dbox_metadata_header metadata_hdr; |