Skip to content

Commit

Permalink
backport #7434
Browse files Browse the repository at this point in the history
  • Loading branch information
d-a-v committed Jul 18, 2020
1 parent 5337f93 commit 7f98636
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions libraries/LittleFS/src/LittleFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ FileImplPtr LittleFSImpl::open(const char* path, OpenMode openMode, AccessMode a
// a directory whose name we are carrying around but which cannot be read or written
return std::make_shared<LittleFSFileImpl>(this, path, nullptr, flags, creation);
} else if (rc == 0) {
lfs_file_sync(&_lfs, fd.get());
return std::make_shared<LittleFSFileImpl>(this, path, fd, flags, creation);
} else {
DEBUGV("LittleFSDirImpl::openFile: rc=%d fd=%p path=`%s` openMode=%d accessMode=%d err=%d\n",
Expand Down
22 changes: 22 additions & 0 deletions tests/host/fs/test_fs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,28 @@ TEST_CASE(TESTPRE "seek() pase EOF returns error (#7323)", TESTPAT)
f.close();
}

TEST_CASE(TESTPRE "Rewriting file frees space immediately (#7426)", TESTPAT)
{
FS_MOCK_DECLARE(64, 8, 512, "");
REQUIRE(FSTYPE.begin());
FSInfo inf;
FSTYPE.info(inf);
// Calculate the size to write per-FS, due to differing overheads
int kbToWrite = (inf.totalBytes - inf.usedBytes - 8192) / 1024;
// Create and overwrite a file >50% of spaceA (48/64K)
for (auto x = 0; x < 2; x++) {
auto f = FSTYPE.open("/file1.bin", "w");
REQUIRE(f);
uint8_t buff[1024];
memset(buff, 0xaa, 1024);
for (auto i = 0; i < kbToWrite; i++) {
REQUIRE(f.write(buff, 1024));
}
f.close();
FSTYPE.info(inf);
}
}

#ifdef FS_HAS_DIRS

#if FSTYPE != SDFS
Expand Down

0 comments on commit 7f98636

Please sign in to comment.