function, cache->filepath);
}
+static void mail_cache_unlink(struct mail_cache *cache)
+{
+ if (!cache->index->readonly)
+ (void)unlink(cache->filepath);
+}
+
void mail_cache_set_corrupted(struct mail_cache *cache, const char *fmt, ...)
{
va_list va;
- (void)unlink(cache->filepath);
+ mail_cache_unlink(cache);
/* mark the cache as unusable */
cache->hdr = NULL;
if (hdr->version != MAIL_CACHE_VERSION) {
/* version changed - upgrade silently */
- (void)unlink(cache->filepath);
+ mail_cache_unlink(cache);
return FALSE;
}
if (hdr->compat_sizeof_uoff_t != sizeof(uoff_t)) {
/* architecture change - handle silently(?) */
- (void)unlink(cache->filepath);
+ mail_cache_unlink(cache);
return FALSE;
}
if (hdr->indexid != cache->index->indexid) {
/* index id changed - handle silently */
- (void)unlink(cache->filepath);
+ mail_cache_unlink(cache);
return FALSE;
}
if (hdr->file_seq == 0) {
ret = mail_index_sync_map(&index->map, type,
TRUE);
}
- } else if (ret == 0) {
+ } else if (ret == 0 && index->readonly) {
/* make sure we don't try to open the file again */
if (unlink(index->filepath) < 0 && errno != ENOENT)
mail_index_set_syscall_error(index, "unlink()");
i_assert(index->log_locked);
- if (!mail_index_map_has_changed(map))
+ if (!mail_index_map_has_changed(map) || index->readonly)
return;
if (hdr->base_header_size < sizeof(*hdr)) {
const char *path;
int last_errno = 0;
- if (MAIL_INDEX_IS_IN_MEMORY(index))
+ if (MAIL_INDEX_IS_IN_MEMORY(index) || index->readonly)
return 0;
/* main index */
index->indexid = 0;
index->map->hdr.flags |= MAIL_INDEX_HDR_FLAG_CORRUPTED;
- if (unlink(index->filepath) < 0 && errno != ENOENT && errno != ESTALE)
- mail_index_set_syscall_error(index, "unlink()");
+ if (!index->readonly) {
+ if (unlink(index->filepath) < 0 &&
+ errno != ENOENT && errno != ESTALE)
+ mail_index_set_syscall_error(index, "unlink()");
+ }
}
void mail_index_fchown(struct mail_index *index, int fd, const char *path)
file->corrupted = TRUE;
file->hdr.indexid = 0;
- if (!MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file)) {
+ if (!MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file) &&
+ !file->log->index->readonly) {
/* indexid=0 marks the log file as corrupted */
unsigned int offset =
offsetof(struct mail_transaction_log_header, indexid);
static ssize_t
mail_transaction_log_file_read_header(struct mail_transaction_log_file *file)
{
- ssize_t pos;
- int ret;
+ ssize_t pos, ret;
memset(&file->hdr, 0, sizeof(file->hdr));
i_assert(!MAIL_INDEX_IS_IN_MEMORY(index));
+ if (file->log->index->readonly) {
+ mail_index_set_error(index,
+ "Can't create log file %s: Index is read-only",
+ file->filepath);
+ return -1;
+ }
+
/* With dotlocking we might already have path.lock created, so this
filename has to be different. */
old_mask = umask(index->mode ^ 0666);
if (ret == 0) {
/* corrupted */
- if (unlink(file->filepath) < 0 && errno != ENOENT) {
+ if (file->log->index->readonly) {
+ /* don't delete */
+ } else if (unlink(file->filepath) < 0 &&
+ errno != ENOENT) {
mail_index_set_error(file->log->index,
"unlink(%s) failed: %m",
file->filepath);
return;
}
- if (st.st_mtime + MAIL_TRANSACTION_LOG2_STALE_SECS <= ioloop_time) {
+ if (st.st_mtime + MAIL_TRANSACTION_LOG2_STALE_SECS <= ioloop_time &&
+ !log->index->readonly) {
if (unlink(log->filepath2) < 0 && errno != ENOENT) {
mail_index_set_error(log->index,
"unlink(%s) failed: %m", log->filepath2);
int mailbox_list_index_set_corrupted(struct mailbox_list_index *index,
const char *str)
{
- (void)unlink(index->filepath);
+ if (!index->mail_index->readonly)
+ (void)unlink(index->filepath);
mailbox_list_index_file_close(index);
i_error("Corrupted mailbox list index file %s: %s",