diff --git a/Sming/Core/Data/Stream/IFS/FileStream.cpp b/Sming/Core/Data/Stream/IFS/FileStream.cpp index a046ad3ef3..9cdf0eb02c 100644 --- a/Sming/Core/Data/Stream/IFS/FileStream.cpp +++ b/Sming/Core/Data/Stream/IFS/FileStream.cpp @@ -10,8 +10,6 @@ #include "FileStream.h" -#define ETAG_SIZE 16 - namespace IFS { void FileStream::attach(FileHandle file, size_t size) @@ -172,10 +170,27 @@ String FileStream::id() const return nullptr; } - char buf[ETAG_SIZE]; - m_snprintf(buf, ETAG_SIZE, _F("00f-%x-%x0-%x"), stat.id, stat.size, stat.name.length); - - return String(buf); + /* + Jan 2024. How ETAGs are generated is not specified. Previous implementation was like this: + + m_snprintf(buf, ETAG_SIZE, _F("00f-%x-%x0-%x"), stat.id, stat.size, stat.name.length); + + Issues are: + - on some architectures compiler warns about differing types %x vs arguments + - name can change without length being affected; if name changes then file lookup would fail anyway + - modification timestamp is a good metric, should be incorporated + */ + String id; + id += "00f-"; + id += String(stat.id, HEX); + id += '-'; + id += String(stat.size, HEX); + id += '-'; + id += String(stat.mtime, HEX); + id += '-'; + id += String(stat.name.length, HEX); + + return id; } bool FileStream::truncate(size_t newSize) diff --git a/tests/HostTests/modules/Files.cpp b/tests/HostTests/modules/Files.cpp index 05eef51a4b..ed25524c7f 100644 --- a/tests/HostTests/modules/Files.cpp +++ b/tests/HostTests/modules/Files.cpp @@ -88,6 +88,7 @@ class FilesTest : public TestGroup { fileSetContent(testFileName, testContent); FileStream fs(testFileName); + Serial << testFileName << " ID: " << fs.id() << endl; res = fs.truncate(100); pos = fs.getPos(); size = fs.getSize();