Skip to content

Commit

Permalink
Tweaked lfs_file_flush to still flush caches when build under LFS_REA…
Browse files Browse the repository at this point in the history
…DONLY

A slight varation to the fix from ondrap
  • Loading branch information
geky committed Mar 21, 2022
1 parent e955b9f commit 03f088b
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions lfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2730,19 +2730,15 @@ static int lfs_file_outline(lfs_t *lfs, lfs_file_t *file) {
}
#endif

static void lfs_file_invalidate_reading_flag(lfs_t *lfs, lfs_file_t *file) {
static int lfs_file_flush(lfs_t *lfs, lfs_file_t *file) {
if (file->flags & LFS_F_READING) {
if (!(file->flags & LFS_F_INLINE)) {
lfs_cache_drop(lfs, &file->cache);
}
file->flags &= ~LFS_F_READING;
}
}

#ifndef LFS_READONLY
static int lfs_file_flush(lfs_t *lfs, lfs_file_t *file) {
lfs_file_invalidate_reading_flag(lfs, file);

if (file->flags & LFS_F_WRITING) {
lfs_off_t pos = file->pos;

Expand Down Expand Up @@ -2809,10 +2805,10 @@ static int lfs_file_flush(lfs_t *lfs, lfs_file_t *file) {

file->pos = pos;
}
#endif

return 0;
}
#endif

#ifndef LFS_READONLY
static int lfs_file_rawsync(lfs_t *lfs, lfs_file_t *file) {
Expand Down Expand Up @@ -3085,17 +3081,11 @@ static lfs_soff_t lfs_file_rawseek(lfs_t *lfs, lfs_file_t *file,
return npos;
}

#ifndef LFS_READONLY
// write out everything beforehand, may be noop if rdonly
int err = lfs_file_flush(lfs, file);
if (err) {
return err;
}
#else
// Seek doesn't update cache parameters properly.
// It has to be invalidated otherwise next read will return incorrect values.
lfs_file_invalidate_reading_flag(lfs,file);
#endif

// update pos
file->pos = npos;
Expand Down

0 comments on commit 03f088b

Please sign in to comment.