Skip to content

Commit 2c44f77

Browse files
author
Mallory Paine
committed
If we have a partial chunk whose length is < expected chunk length, and we've just extended the length of the file, we'll need to invalidate this partial chunk by removing it from _chunkDictionary. Thus, the next time someone needs an entry from this chunk, it will be properly recreated with its correct, updated entry count.
1 parent 8a83894 commit 2c44f77

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

FastImageCache/FICImageTable.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,16 @@ - (void)_setEntryCount:(NSInteger)entryCount {
453453
_fileLength = fileLength;
454454
_entryCount = entryCount;
455455
_chunkCount = _entriesPerChunk > 0 ? ((_entryCount + _entriesPerChunk - 1) / _entriesPerChunk) : 0;
456+
457+
NSDictionary *chunkDictionary = [_chunkDictionary copy];
458+
for (FICImageTableChunk *chunk in [chunkDictionary allValues]) {
459+
if ([chunk length] != _chunkLength) {
460+
// Issue 31: https://github.com/path/FastImageCache/issues/31
461+
// Somehow, we have a partial chunk whose length needs to be adjusted
462+
// since we changed our file length.
463+
[self _setChunk:nil index:[chunk index]];
464+
}
465+
}
456466
}
457467
}
458468
}

FastImageCache/FICImageTableChunk.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
*/
3737
@property (nonatomic, assign, readonly) off_t fileOffset;
3838

39+
@property (nonatomic, assign, readonly) size_t length;
40+
41+
3942
///----------------------------------------
4043
/// @name Initializing an Image Table Chunk
4144
///----------------------------------------

FastImageCache/FICImageTableChunk.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ @implementation FICImageTableChunk
2727

2828
@synthesize bytes = _bytes;
2929
@synthesize fileOffset = _fileOffset;
30+
@synthesize length = _length;
3031

3132
#pragma mark - Object Lifecycle
3233

0 commit comments

Comments
 (0)