Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <utime.h>
#include <unistd.h>
#include <cstring>
#include <string>
Expand All @@ -25,6 +26,12 @@
#include <direct.h>
#endif

#if CONFIG_SPIFFS_USE_MTIME
#if SPIFFS_OBJ_META_LEN != 4
#error You must set both CONFIG_SPIFFS_USE_MTIME=1 and CONFIG_SPIFFS_META_LENGTH=4 for ESP IDF MTIME compatibility.
#endif
#endif

static std::vector<uint8_t> s_flashmem;

static std::string s_dirName;
Expand Down Expand Up @@ -154,6 +161,13 @@ int addFile(char* name, const char* path)
std::cout << "file size: " << size << std::endl;
}

// read and update file modification time
#if CONFIG_SPIFFS_USE_MTIME
struct stat sbuff;
stat(path, &sbuff);
SPIFFS_fupdate_meta(&s_fs, dst, &sbuff.st_mtime);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please handle the possibly different sizeof(time_t) explicitly? E.g.

uint32_t meta = (maybe truncate?) sbuff.st_mtime;
SPIFFS_fupdate_meta(&s_fs, dst, &meta);

And similar in unpackFile below.

#endif

size_t left = size;
uint8_t data_byte;
while (left > 0) {
Expand Down Expand Up @@ -369,6 +383,15 @@ bool unpackFile(spiffs_dirent *spiffsFile, const char *destPath)
// Close file.
fclose(dst);

// Update file modification time.
#if CONFIG_SPIFFS_USE_MTIME
spiffs_stat sstat;
SPIFFS_stat(&s_fs, (const char*)spiffsFile->name, &sstat);
struct utimbuf times;
memcpy(&times.actime, sstat.meta, 4);
memcpy(&times.modtime, sstat.meta, 4);
utime(destPath, &times);
#endif

return true;
}
Expand Down