Skip to content

Commit

Permalink
lib-index: Add mail_cache_compress_forced()
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen authored and villesavolainen committed Nov 13, 2018
1 parent 57ac371 commit 000e3a5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/lib-index/mail-cache-compress.c
Expand Up @@ -432,7 +432,7 @@ static int mail_cache_compress_dotlock(struct mail_cache *cache,
return 0;
}

static int mail_cache_compress_locked(struct mail_cache *cache,
static int mail_cache_compress_locked(struct mail_cache *cache, bool forced,
struct mail_index_transaction *trans,
bool *unlock, struct dotlock **dotlock_r)
{
Expand All @@ -451,7 +451,8 @@ static int mail_cache_compress_locked(struct mail_cache *cache,
return -1;
/* we've locked the cache compression now. if somebody else had just
recreated the cache, reopen the cache and return success. */
if ((ret = mail_cache_compress_has_file_changed(cache)) != 0) {
if (!forced &&
(ret = mail_cache_compress_has_file_changed(cache)) != 0) {
if (ret < 0)
return -1;

Expand Down Expand Up @@ -493,9 +494,10 @@ static int mail_cache_compress_locked(struct mail_cache *cache,
return 0;
}

int mail_cache_compress(struct mail_cache *cache,
struct mail_index_transaction *trans,
struct mail_cache_compress_lock **lock_r)
static int
mail_cache_compress_full(struct mail_cache *cache, bool forced,
struct mail_index_transaction *trans,
struct mail_cache_compress_lock **lock_r)
{
struct dotlock *dotlock = NULL;
bool unlock = FALSE;
Expand Down Expand Up @@ -542,7 +544,7 @@ int mail_cache_compress(struct mail_cache *cache,
}
}
cache->compressing = TRUE;
ret = mail_cache_compress_locked(cache, trans, &unlock, &dotlock);
ret = mail_cache_compress_locked(cache, forced, trans, &unlock, &dotlock);
cache->compressing = FALSE;
if (unlock) {
if (mail_cache_unlock(cache) < 0)
Expand All @@ -561,6 +563,20 @@ int mail_cache_compress(struct mail_cache *cache,
return ret;
}

int mail_cache_compress(struct mail_cache *cache,
struct mail_index_transaction *trans,
struct mail_cache_compress_lock **lock_r)
{
return mail_cache_compress_full(cache, FALSE, trans, lock_r);
}

int mail_cache_compress_forced(struct mail_cache *cache,
struct mail_index_transaction *trans,
struct mail_cache_compress_lock **lock_r)
{
return mail_cache_compress_full(cache, TRUE, trans, lock_r);
}

void mail_cache_compress_unlock(struct mail_cache_compress_lock **_lock)
{
struct mail_cache_compress_lock *lock = *_lock;
Expand Down
3 changes: 3 additions & 0 deletions src/lib-index/mail-cache.h
Expand Up @@ -75,6 +75,9 @@ bool mail_cache_need_compress(struct mail_cache *cache);
int mail_cache_compress(struct mail_cache *cache,
struct mail_index_transaction *trans,
struct mail_cache_compress_lock **lock_r);
int mail_cache_compress_forced(struct mail_cache *cache,
struct mail_index_transaction *trans,
struct mail_cache_compress_lock **lock_r);
void mail_cache_compress_unlock(struct mail_cache_compress_lock **lock);
/* Returns TRUE if there is at least something in the cache. */
bool mail_cache_exists(struct mail_cache *cache);
Expand Down

0 comments on commit 000e3a5

Please sign in to comment.