1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-29 05:21:37 +03:00

Hook up custom timestamp proc for SD/SDFS (#7686)

The SDFS implementation didn't include plumbing to support user-supplied
timestamp generators (for file create/write times) because the SDFat
library doesn't support a callback parameter.

Work around it by using a single, global (inside sdfs namespace) that
the static timestamp callback member can see and use.

Add a test of the feature in CI.

Fixes #7682
This commit is contained in:
Earle F. Philhower, III
2020-10-31 08:05:34 -07:00
committed by GitHub
parent 996211f132
commit 1bb0815fed
3 changed files with 46 additions and 4 deletions

View File

@ -162,4 +162,35 @@ TEST_CASE("SD.h FILE_WRITE macro is append", "[fs]")
REQUIRE(u == 0);
}
// SDFS timestamp setter (#7682)
static time_t _my_time(void)
{
struct tm t;
bzero(&t, sizeof(t));
t.tm_year = 120;
t.tm_mon = 9;
t.tm_mday = 22;
t.tm_hour = 12;
t.tm_min = 13;
t.tm_sec = 14;
return mktime(&t);
}
TEST_CASE("SDFS timeCallback")
{
SDFS_MOCK_DECLARE(64, 8, 512, "");
REQUIRE(SDFS.begin());
REQUIRE(SD.begin(4));
SDFS.setTimeCallback(_my_time);
File f = SD.open("/file.txt", "w");
f.write("Had we but world enough, and time,");
f.close();
time_t expected = _my_time();
f = SD.open("/file.txt", "r");
REQUIRE(abs(f.getCreationTime() - expected) < 60); // FAT has less precision in timestamp than time_t
REQUIRE(abs(f.getLastWrite() - expected) < 60); // FAT has less precision in timestamp than time_t
f.close();
}
};