Fix FS timestamp not working

Fix FS commands with incomplete root
Fix slow time set at start if no need time server
Update debug message in Flash FS
Fix FATFS / LittleFS bugs
This commit is contained in:
Luc 2020-05-28 13:42:18 +02:00
parent 26fef41f73
commit 7fcb0bdbee
9 changed files with 131 additions and 142 deletions

View File

@ -24,6 +24,10 @@
#include "../settings_esp3d.h" #include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h" #include "../../modules/authentication/authentication_service.h"
#include "../../modules/filesystem/esp_filesystem.h" #include "../../modules/filesystem/esp_filesystem.h"
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
#include "../../modules/time/time_server.h"
#endif //FILESYSTEM_TIMESTAMP_FEATURE
//List ESP Filesystem //List ESP Filesystem
//[ESP720]<Root> pwd=<admin password> //[ESP720]<Root> pwd=<admin password>
bool Commands::ESP720(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output) bool Commands::ESP720(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
@ -75,9 +79,7 @@ bool Commands::ESP720(const char* cmd_params, level_authenticate_type auth_type,
output->print(ESP_FileSystem::formatBytes(sub.size()).c_str()); output->print(ESP_FileSystem::formatBytes(sub.size()).c_str());
output->print(" \t"); output->print(" \t");
#ifdef FILESYSTEM_TIMESTAMP_FEATURE #ifdef FILESYSTEM_TIMESTAMP_FEATURE
time_t t = sub.getLastWrite(); output->print(timeserver.current_time(sub.getLastWrite()));
struct tm * tmstruct = localtime(&t);
output->printf("%d-%02d-%02d %02d:%02d:%02d",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
output->print(" \t"); output->print(" \t");
#endif //FILESYSTEM_TIMESTAMP_FEATURE #endif //FILESYSTEM_TIMESTAMP_FEATURE
output->printLN(""); output->printLN("");

View File

@ -22,7 +22,7 @@
#define _VERSION_ESP3D_H #define _VERSION_ESP3D_H
//version and sources location //version and sources location
#define FW_VERSION "3.0.0.a40" #define FW_VERSION "3.0.0.a41"
#define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0" #define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0"
#endif //_VERSION_ESP3D_H #endif //_VERSION_ESP3D_H

View File

@ -70,26 +70,26 @@ bool ESP_FileSystem::format()
ESP_File ESP_FileSystem::open(const char* path, uint8_t mode) ESP_File ESP_FileSystem::open(const char* path, uint8_t mode)
{ {
log_esp3d("open %s", path);
//do some check //do some check
if(((strcmp(path,"/") == 0) && ((mode == ESP_FILE_WRITE) || (mode == ESP_FILE_APPEND))) || (strlen(path) == 0)) { if(((strcmp(path,"/") == 0) && ((mode == ESP_FILE_WRITE) || (mode == ESP_FILE_APPEND))) || (strlen(path) == 0)) {
log_esp3d("reject %s", path);
return ESP_File(); return ESP_File();
} }
// path must start by '/' // path must start by '/'
if (path[0] != '/') { if (path[0] != '/') {
log_esp3d("%s is invalid path", path);
return ESP_File(); return ESP_File();
} }
if (mode != ESP_FILE_READ) {
//check container exists
String p = path;
p.remove(p.lastIndexOf('/') +1);
if (!exists(p.c_str())) {
log_esp3d("Error opening: %s", path);
return ESP_File();
}
}
File tmp = FFat.open(path, (mode == ESP_FILE_READ)?FILE_READ:(mode == ESP_FILE_WRITE)?FILE_WRITE:FILE_APPEND); File tmp = FFat.open(path, (mode == ESP_FILE_READ)?FILE_READ:(mode == ESP_FILE_WRITE)?FILE_WRITE:FILE_APPEND);
ESP_File esptmp(&tmp, tmp.isDirectory(),(mode == ESP_FILE_READ)?false:true, path); if(tmp) {
return esptmp; ESP_File esptmp(&tmp, tmp.isDirectory(),(mode == ESP_FILE_READ)?false:true, path);
log_esp3d("%s is a %s", path,tmp.isDirectory()?"Dir":"File");
return esptmp;
} else {
log_esp3d("open %s failed", path);
return ESP_File();
}
} }
bool ESP_FileSystem::exists(const char* path) bool ESP_FileSystem::exists(const char* path)
@ -105,6 +105,7 @@ bool ESP_FileSystem::exists(const char* path)
if (root) { if (root) {
res = root.isDirectory(); res = root.isDirectory();
} }
root.close();
} }
return res; return res;
} }
@ -116,17 +117,35 @@ bool ESP_FileSystem::remove(const char *path)
bool ESP_FileSystem::mkdir(const char *path) bool ESP_FileSystem::mkdir(const char *path)
{ {
return FFat.mkdir(path); String p = path;
if(p[0]!='/') {
p="/"+p;
}
if (p[p.length()-1] == '/') {
if (p!="/") {
p.remove(p.length()-1);
}
}
return FFat.mkdir(p);
} }
bool ESP_FileSystem::rmdir(const char *path) bool ESP_FileSystem::rmdir(const char *path)
{ {
if (!exists(path)) { String p = path;
if(p[0]!='/') {
p="/"+p;
}
if (p[p.length()-1] == '/') {
if (p!="/") {
p.remove(p.length()-1);
}
}
if (!exists(p.c_str())) {
return false; return false;
} }
bool res = true; bool res = true;
GenLinkedList<String > pathlist; GenLinkedList<String > pathlist;
String p = path;
pathlist.push(p); pathlist.push(p);
while (pathlist.count() > 0) { while (pathlist.count() > 0) {
File dir = FFat.open(pathlist.getLast().c_str()); File dir = FFat.open(pathlist.getLast().c_str());
@ -178,6 +197,7 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path
_iswritemode = iswritemode; _iswritemode = iswritemode;
_size = 0; _size = 0;
if (!handle) { if (!handle) {
log_esp3d("No handle");
return ; return ;
} }
bool set =false; bool set =false;
@ -186,29 +206,11 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path
tFile_handle[i] = *((File*)handle); tFile_handle[i] = *((File*)handle);
//filename //filename
_filename = tFile_handle[i].name(); _filename = tFile_handle[i].name();
//if root
if (_filename == "/") {
_filename = "/.";
}
if (_isdir) {
if (_filename[_filename.length()-1] != '.') {
if (_filename[_filename.length()-2] != '/') {
_filename+="/";
}
_filename+=".";
}
}
//name //name
if (_filename == "/.") { if (_filename == "/") {
_name = "/"; _name = "/";
} else { } else {
_name = _filename; _name = _filename;
if (_name.endsWith("/.")) {
_name.remove( _name.length() - 2,2);
_isfakedir = true;
_isdir = true;
}
if (_name[0] == '/') { if (_name[0] == '/') {
_name.remove( 0, 1); _name.remove( 0, 1);
} }
@ -222,16 +224,21 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path
//time //time
_lastwrite = tFile_handle[i].getLastWrite(); _lastwrite = tFile_handle[i].getLastWrite();
_index = i; _index = i;
//log_esp3d("Opening File at index %d",_index); log_esp3d("Opening File at index %d",_index);
log_esp3d("name: %s", _name.c_str());
log_esp3d("filename: %s", _filename.c_str());
set = true; set = true;
} }
} }
if(!set) {
log_esp3d("No handle available");
}
} }
void ESP_File::close() void ESP_File::close()
{ {
if (_index != -1) { if (_index != -1) {
//log_esp3d("Closing File at index %d", _index); log_esp3d("Closing File at index %d", _index);
tFile_handle[_index].close(); tFile_handle[_index].close();
//reopen if mode = write //reopen if mode = write
//udate size + date //udate size + date
@ -244,7 +251,6 @@ void ESP_File::close()
} }
} }
tFile_handle[_index] = File(); tFile_handle[_index] = File();
//log_esp3d("Closing File at index %d",_index);
_index = -1; _index = -1;
} }
} }
@ -252,7 +258,7 @@ void ESP_File::close()
ESP_File ESP_File::openNextFile() ESP_File ESP_File::openNextFile()
{ {
if ((_index == -1) || !_isdir) { if ((_index == -1) || !_isdir) {
log_esp3d("openNextFile failed"); log_esp3d("openNextFile %d failed", _index);
return ESP_File(); return ESP_File();
} }
File tmp = tFile_handle[_index].openNextFile(); File tmp = tFile_handle[_index].openNextFile();
@ -260,35 +266,7 @@ ESP_File ESP_File::openNextFile()
log_esp3d("tmp name :%s %s", tmp.name(), (tmp.isDirectory())?"isDir":"isFile"); log_esp3d("tmp name :%s %s", tmp.name(), (tmp.isDirectory())?"isDir":"isFile");
ESP_File esptmp(&tmp, tmp.isDirectory()); ESP_File esptmp(&tmp, tmp.isDirectory());
esptmp.close(); esptmp.close();
String sub = esptmp.filename(); return esptmp;
sub.remove(0,_filename.length()-1);
int pos = sub.indexOf("/");
if (pos!=-1) {
//is subdir
sub = sub.substring(0,pos);
//log_esp3d("file name:%s name: %s %s sub:%s root:%s", esptmp.filename(), esptmp.name(), (esptmp.isDirectory())?"isDir":"isFile", sub.c_str(), _filename.c_str());
String tag = "*" + sub + "*";
//test if already in directory list
if (_dirlist.indexOf(tag) == -1) {//not in list so add it and return the info
_dirlist+= tag;
String fname = _filename.substring(0,_filename.length()-1) + sub + "/.";
//log_esp3d("Found dir name: %s filename:%s", sub.c_str(), fname.c_str());
esptmp = ESP_File(sub.c_str(), fname.c_str());
return esptmp;
} else { //already in list so ignore it
//log_esp3d("Dir name: %s already in list", sub.c_str());
tmp = tFile_handle[_index].openNextFile();
}
} else { //is file
//log_esp3d("file name:%s name: %s %s sub:%s root:%s", esptmp.filename(), esptmp.name(), (esptmp.isDirectory())?"isDir":"isFile", sub.c_str(), _filename.c_str());
if (sub == ".") {
//log_esp3d("Dir tag, ignore it");
tmp = tFile_handle[_index].openNextFile();
} else {
return esptmp;
}
}
} }
return ESP_File(); return ESP_File();
} }

View File

@ -120,7 +120,12 @@ bool ESP_FileSystem::exists(const char* path)
bool ESP_FileSystem::remove(const char *path) bool ESP_FileSystem::remove(const char *path)
{ {
return LittleFS.remove(path); String p = path;
if(p[0]!='/') {
p="/"+p;
}
log_esp3d("delete %s", p.c_str());
return LittleFS.remove(p);
} }
bool ESP_FileSystem::mkdir(const char *path) bool ESP_FileSystem::mkdir(const char *path)
@ -132,6 +137,9 @@ bool ESP_FileSystem::mkdir(const char *path)
spath.remove(spath.length()-1); spath.remove(spath.length()-1);
} }
} }
if (spath[0]!='/') {
spath = "/"+spath;
}
return LittleFS.mkdir(spath.c_str()); return LittleFS.mkdir(spath.c_str());
} }
@ -205,6 +213,7 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path
_iswritemode = iswritemode; _iswritemode = iswritemode;
_size = 0; _size = 0;
if (!handle) { if (!handle) {
log_esp3d("No handle");
return ; return ;
} }
bool set =false; bool set =false;
@ -220,7 +229,6 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path
if (!((_filename[_filename.length()-1] == '/') || (_filename == "/"))) { if (!((_filename[_filename.length()-1] == '/') || (_filename == "/"))) {
_filename+="/"; _filename+="/";
} }
//log_esp3d("Filename: %s", _filename.c_str());
//Name //Name
if (_filename == "/") { if (_filename == "/") {
_name = "/"; _name = "/";
@ -228,7 +236,9 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path
_name.remove( 0, _name.lastIndexOf('/')+1); _name.remove( 0, _name.lastIndexOf('/')+1);
} }
} }
//log_esp3d("Name: %s index: %d", _name.c_str(), _index); log_esp3d("Dir: %s index: %d", _name.c_str(), _index);
log_esp3d("name: %s", _name.c_str());
log_esp3d("filename: %s", _filename.c_str());
set = true; set = true;
} }
} }
@ -239,33 +249,17 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path
if (!tFile_handle[i]) { if (!tFile_handle[i]) {
tFile_handle[i] = *((File*)handle); tFile_handle[i] = *((File*)handle);
//filename //filename
_filename = tFile_handle[i].name(); _filename = tFile_handle[i].fullName();
if (_isdir) {
if (!((_filename[_filename.length()-1] == '/') || (_filename == "/"))) {
_filename+="/";
}
}
//name //name
if (_filename == "/") { _name = tFile_handle[i].name();
_name = "/";
} else {
_name = _filename;
if (_name[0] == '/') {
_name.remove( 0, 1);
}
int pos = _name.lastIndexOf('/');
if (pos != -1) {
_name.remove( 0, pos+1);
}
}
//size //size
_size = tFile_handle[i].size(); _size = tFile_handle[i].size();
//time //time
//TODO - not yet implemented in esp core _lastwrite = tFile_handle[i].getLastWrite();
//_lastwrite = tFile_handle[i].getLastWrite();
_lastwrite = 0;
_index = i; _index = i;
//log_esp3d("Opening File at index %d",_index); log_esp3d("Opening File at index %d",_index);
log_esp3d("name: %s", _name.c_str());
log_esp3d("filename: %s", _filename.c_str());
set = true; set = true;
} }
} }
@ -275,26 +269,26 @@ void ESP_File::close()
{ {
if (_index != -1) { if (_index != -1) {
if (_isdir) { if (_isdir) {
//log_esp3d("Closing Dir at index %d", _index); log_esp3d("Closing Dir at index %d", _index);
tDir_handle[_index] = Dir(); tDir_handle[_index] = Dir();
_index = -1; _index = -1;
return; return;
} }
//log_esp3d("Closing File at index %d", _index); log_esp3d("Closing File at index %d", _index);
log_esp3d("Size is %d", tFile_handle[_index].size());
tFile_handle[_index].close(); tFile_handle[_index].close();
//reopen if mode = write //reopen if mode = write
//udate size + date //udate size + date
if (_iswritemode && !_isdir) { if (_iswritemode && !_isdir) {
log_esp3d("Updating Size of %s",_filename.c_str());
File ftmp = LittleFS.open(_filename.c_str(), "r"); File ftmp = LittleFS.open(_filename.c_str(), "r");
if (ftmp) { if (ftmp) {
_size = ftmp.size(); _size = ftmp.size();
//TODO - not yet implemented in esp core log_esp3d("Updating Size to %d", ftmp.size());
//_lastwrite = ftmp.getLastWrite(); _lastwrite = ftmp.getLastWrite();
_lastwrite = 0;
ftmp.close(); ftmp.close();
} }
} }
//log_esp3d("Closing File at index %d",_index);
_index = -1; _index = -1;
} }
} }

View File

@ -78,8 +78,14 @@ ESP_File ESP_FileSystem::open(const char* path, uint8_t mode)
} }
//TODO add support if path = /DIR1/ <- with last / //TODO add support if path = /DIR1/ <- with last /
File tmp = SPIFFS.open(path, (mode == ESP_FILE_READ)?FILE_READ:(mode == ESP_FILE_WRITE)?FILE_WRITE:FILE_APPEND); File tmp = SPIFFS.open(path, (mode == ESP_FILE_READ)?FILE_READ:(mode == ESP_FILE_WRITE)?FILE_WRITE:FILE_APPEND);
ESP_File esptmp(&tmp, tmp.isDirectory(),(mode == ESP_FILE_READ)?false:true, path); if(tmp) {
return esptmp; ESP_File esptmp(&tmp, tmp.isDirectory(),(mode == ESP_FILE_READ)?false:true, path);
log_esp3d("%s is a %s", path,tmp.isDirectory()?"Dir":"File");
return esptmp;
} else {
log_esp3d("open %s failed", path);
return ESP_File();
}
} }
bool ESP_FileSystem::exists(const char* path) bool ESP_FileSystem::exists(const char* path)
@ -103,7 +109,7 @@ bool ESP_FileSystem::exists(const char* path)
newpath+="/"; newpath+="/";
} }
newpath+="."; newpath+=".";
//log_esp3d("Check %s", newpath.c_str()); log_esp3d("Check %s", newpath.c_str());
res = SPIFFS.exists(newpath); res = SPIFFS.exists(newpath);
if (!res) { if (!res) {
ESP_File f = ESP_FileSystem::open(path, ESP_FILE_READ); ESP_File f = ESP_FileSystem::open(path, ESP_FILE_READ);
@ -123,7 +129,11 @@ bool ESP_FileSystem::exists(const char* path)
bool ESP_FileSystem::remove(const char *path) bool ESP_FileSystem::remove(const char *path)
{ {
return SPIFFS.remove(path); String p = path;
if(p[0]!='/') {
p="/"+p;
}
return SPIFFS.remove(p);
} }
bool ESP_FileSystem::mkdir(const char *path) bool ESP_FileSystem::mkdir(const char *path)
@ -134,7 +144,7 @@ bool ESP_FileSystem::mkdir(const char *path)
p+="/"; p+="/";
} }
p+="."; p+=".";
//log_esp3d("Dir create : %s", p.c_str()); log_esp3d("Dir create : %s", p.c_str());
ESP_File f = open(p.c_str(), ESP_FILE_WRITE); ESP_File f = open(p.c_str(), ESP_FILE_WRITE);
if (f) { if (f) {
f.close(); f.close();
@ -148,6 +158,9 @@ bool ESP_FileSystem::rmdir(const char *path)
{ {
String spath = path; String spath = path;
spath.trim(); spath.trim();
if(spath[0]!='/') {
spath="/"+spath;
}
if (spath[spath.length()-1] == '/') { if (spath[spath.length()-1] == '/') {
if (spath!="/") { if (spath!="/") {
spath.remove(spath.length()-1); spath.remove(spath.length()-1);
@ -158,7 +171,7 @@ bool ESP_FileSystem::rmdir(const char *path)
if (ftmp) { if (ftmp) {
File pfile = ftmp.openNextFile(); File pfile = ftmp.openNextFile();
while (pfile) { while (pfile) {
//log_esp3d("File: %s",pfile.name()); log_esp3d("File: %s",pfile.name());
if (!SPIFFS.remove(pfile.name())) { if (!SPIFFS.remove(pfile.name())) {
pfile.close(); pfile.close();
return false; return false;
@ -193,6 +206,7 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path
_iswritemode = iswritemode; _iswritemode = iswritemode;
_size = 0; _size = 0;
if (!handle) { if (!handle) {
log_esp3d("No handle");
return ; return ;
} }
bool set =false; bool set =false;
@ -237,7 +251,9 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path
//time //time
_lastwrite = tFile_handle[i].getLastWrite(); _lastwrite = tFile_handle[i].getLastWrite();
_index = i; _index = i;
//log_esp3d("Opening File at index %d",_index); log_esp3d("Opening File at index %d",_index);
log_esp3d("name: %s", _name.c_str());
log_esp3d("filename: %s", _filename.c_str());
set = true; set = true;
} }
} }
@ -246,7 +262,7 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path
void ESP_File::close() void ESP_File::close()
{ {
if (_index != -1) { if (_index != -1) {
//log_esp3d("Closing File at index %d", _index); log_esp3d("Closing File at index %d", _index);
tFile_handle[_index].close(); tFile_handle[_index].close();
//reopen if mode = write //reopen if mode = write
//udate size + date //udate size + date
@ -259,7 +275,6 @@ void ESP_File::close()
} }
} }
tFile_handle[_index] = File(); tFile_handle[_index] = File();
//log_esp3d("Closing File at index %d",_index);
_index = -1; _index = -1;
} }
} }

View File

@ -82,13 +82,14 @@ ESP_File ESP_FileSystem::open(const char* path, uint8_t mode)
} }
File ftmp = SPIFFS.open(path, (mode == ESP_FILE_READ)?"r":(mode == ESP_FILE_WRITE)?"w":"a"); File ftmp = SPIFFS.open(path, (mode == ESP_FILE_READ)?"r":(mode == ESP_FILE_WRITE)?"w":"a");
if(ftmp) { if(ftmp) {
//log_esp3d("Success openening: %s", path); log_esp3d("Success openening file: %s", path);
ESP_File esptmp(&ftmp, false,(mode == ESP_FILE_READ)?false:true, path); ESP_File esptmp(&ftmp, false,(mode == ESP_FILE_READ)?false:true, path);
return esptmp; return esptmp;
} }
(void)mode; (void)mode;
Dir dtmp = SPIFFS.openDir(path); Dir dtmp = SPIFFS.openDir(path);
ESP_File esptmp(&dtmp, true, false, path); ESP_File esptmp(&dtmp, true, false, path);
log_esp3d("Success openening dir: %s", path);
return esptmp; return esptmp;
} }
@ -113,7 +114,7 @@ bool ESP_FileSystem::exists(const char* path)
newpath+="/"; newpath+="/";
} }
newpath+="."; newpath+=".";
//log_esp3d("Check %s", newpath.c_str()); log_esp3d("Check %s", newpath.c_str());
res = SPIFFS.exists(newpath); res = SPIFFS.exists(newpath);
if (!res) { if (!res) {
ESP_File f = ESP_FileSystem::open(path, ESP_FILE_READ); ESP_File f = ESP_FileSystem::open(path, ESP_FILE_READ);
@ -133,7 +134,11 @@ bool ESP_FileSystem::exists(const char* path)
bool ESP_FileSystem::remove(const char *path) bool ESP_FileSystem::remove(const char *path)
{ {
return SPIFFS.remove(path); String p = path;
if(p[0]!='/') {
p="/"+p;
}
return SPIFFS.remove(p);
} }
bool ESP_FileSystem::mkdir(const char *path) bool ESP_FileSystem::mkdir(const char *path)
@ -144,7 +149,7 @@ bool ESP_FileSystem::mkdir(const char *path)
p+="/"; p+="/";
} }
p+="."; p+=".";
//log_esp3d("Dir create : %s", p.c_str()); log_esp3d("Dir create : %s", p.c_str());
ESP_File f = open(p.c_str(), ESP_FILE_WRITE); ESP_File f = open(p.c_str(), ESP_FILE_WRITE);
if (f) { if (f) {
f.close(); f.close();
@ -157,6 +162,7 @@ bool ESP_FileSystem::mkdir(const char *path)
bool ESP_FileSystem::rmdir(const char *path) bool ESP_FileSystem::rmdir(const char *path)
{ {
Dir dtmp = SPIFFS.openDir(path); Dir dtmp = SPIFFS.openDir(path);
log_esp3d("Deleting : %s",path);
while (dtmp.next()) { while (dtmp.next()) {
if (!SPIFFS.remove(dtmp.fileName().c_str())) { if (!SPIFFS.remove(dtmp.fileName().c_str())) {
return false; return false;
@ -186,6 +192,7 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path
_iswritemode = iswritemode; _iswritemode = iswritemode;
_size = 0; _size = 0;
if (!handle) { if (!handle) {
log_esp3d("No handle");
return ; return ;
} }
bool set =false; bool set =false;
@ -206,7 +213,7 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path
} }
_filename+="."; _filename+=".";
} }
//log_esp3d("Filename: %s", _filename.c_str()); log_esp3d("Filename: %s", _filename.c_str());
//Name //Name
if (_filename == "/.") { if (_filename == "/.") {
_name = "/"; _name = "/";
@ -220,7 +227,9 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path
_name.remove( 0, _name.lastIndexOf('/')+1); _name.remove( 0, _name.lastIndexOf('/')+1);
} }
} }
//log_esp3d("Name: %s index: %d", _name.c_str(), _index); log_esp3d("Dir: %s index: %d", _name.c_str(), _index);
log_esp3d("name: %s", _name.c_str());
log_esp3d("filename: %s", _filename.c_str());
set = true; set = true;
} }
} }
@ -265,11 +274,11 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path
//size //size
_size = tFile_handle[i].size(); _size = tFile_handle[i].size();
//time //time
//TODO - not yet implemented in esp core _lastwrite = tFile_handle[i].getLastWrite();
//_lastwrite = tFile_handle[i].getLastWrite();
_lastwrite = 0;
_index = i; _index = i;
//log_esp3d("Opening File at index %d",_index); log_esp3d("Opening File at index %d",_index);
log_esp3d("name: %s", _name.c_str());
log_esp3d("filename: %s", _filename.c_str());
set = true; set = true;
} }
} }
@ -279,12 +288,12 @@ void ESP_File::close()
{ {
if (_index != -1) { if (_index != -1) {
if (_isdir && !_isfakedir) { if (_isdir && !_isfakedir) {
//log_esp3d("Closing Dir at index %d", _index); log_esp3d("Closing Dir at index %d", _index);
tDir_handle[_index] = Dir(); tDir_handle[_index] = Dir();
_index = -1; _index = -1;
return; return;
} }
//log_esp3d("Closing File at index %d", _index); log_esp3d("Closing File at index %d", _index);
tFile_handle[_index].close(); tFile_handle[_index].close();
//reopen if mode = write //reopen if mode = write
//udate size + date //udate size + date
@ -292,13 +301,10 @@ void ESP_File::close()
File ftmp = SPIFFS.open(_filename.c_str(), "r"); File ftmp = SPIFFS.open(_filename.c_str(), "r");
if (ftmp) { if (ftmp) {
_size = ftmp.size(); _size = ftmp.size();
//TODO - Not yet available in esp core _lastwrite = ftmp.getLastWrite();
//_lastwrite = ftmp.getLastWrite();
_lastwrite = 0;
ftmp.close(); ftmp.close();
} }
} }
//log_esp3d("Closing File at index %d",_index);
_index = -1; _index = -1;
} }
} }

View File

@ -28,6 +28,9 @@
#endif //ARDUINO_ARCH_ESP8266 #endif //ARDUINO_ARCH_ESP8266
#include "../../filesystem/esp_filesystem.h" #include "../../filesystem/esp_filesystem.h"
#include "../../authentication/authentication_service.h" #include "../../authentication/authentication_service.h"
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
#include "../../time/time_server.h"
#endif //FILESYSTEM_TIMESTAMP_FEATURE
//Filesystem //Filesystem
//Filesystem files list and file commands //Filesystem files list and file commands
void HTTP_Server::handleFSFileList () void HTTP_Server::handleFSFileList ()
@ -111,7 +114,7 @@ void HTTP_Server::handleFSFileList ()
//create a directory //create a directory
if (_webserver->arg ("action") == "createdir" && _webserver->hasArg ("filename") ) { if (_webserver->arg ("action") == "createdir" && _webserver->hasArg ("filename") ) {
String filename; String filename;
filename = path + _webserver->arg ("filename") + "/."; filename = path + _webserver->arg ("filename");
String shortname = _webserver->arg ("filename"); String shortname = _webserver->arg ("filename");
shortname.replace ("/", ""); shortname.replace ("/", "");
filename.replace ("//", "/"); filename.replace ("//", "/");
@ -161,11 +164,7 @@ void HTTP_Server::handleFSFileList ()
} }
#ifdef FILESYSTEM_TIMESTAMP_FEATURE #ifdef FILESYSTEM_TIMESTAMP_FEATURE
buffer2send+="\",\"time\":\""; buffer2send+="\",\"time\":\"";
time_t t = sub.getLastWrite(); buffer2send+=timeserver.current_time(sub.getLastWrite());
struct tm * tmstruct = localtime(&t);
char str[20]; //buffer should be 20
sprintf(str,"%d-%02d-%02d %02d:%02d:%02d",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
buffer2send+=str;
#endif //FILESYSTEM_TIMESTAMP_FEATURE #endif //FILESYSTEM_TIMESTAMP_FEATURE
buffer2send+="\"}"; buffer2send+="\"}";
if (buffer2send.length() > 1100) { if (buffer2send.length() > 1100) {

View File

@ -99,6 +99,7 @@ void HTTP_Server::FSFileupload ()
} }
//Upload end //Upload end
} else if(upload.status == UPLOAD_FILE_END) { } else if(upload.status == UPLOAD_FILE_END) {
log_esp3d("upload end");
//check if file is still open //check if file is still open
if(fsUploadFile) { if(fsUploadFile) {
//close it //close it
@ -109,7 +110,9 @@ void HTTP_Server::FSFileupload ()
uint32_t filesize = fsUploadFile.size(); uint32_t filesize = fsUploadFile.size();
_upload_status = UPLOAD_STATUS_SUCCESSFUL; _upload_status = UPLOAD_STATUS_SUCCESSFUL;
if (_webserver->hasArg (sizeargname.c_str()) ) { if (_webserver->hasArg (sizeargname.c_str()) ) {
log_esp3d("Size check: %s vs %s", _webserver->arg (sizeargname.c_str()).c_str(), String(filesize).c_str());
if (_webserver->arg (sizeargname.c_str()) != String(filesize)) { if (_webserver->arg (sizeargname.c_str()) != String(filesize)) {
log_esp3d("Size Error");
_upload_status = UPLOAD_STATUS_FAILED; _upload_status = UPLOAD_STATUS_FAILED;
pushError(ESP_ERROR_SIZE, "File upload failed"); pushError(ESP_ERROR_SIZE, "File upload failed");
} }
@ -119,6 +122,7 @@ void HTTP_Server::FSFileupload ()
} }
} else { } else {
//we have a problem set flag UPLOAD_STATUS_FAILED //we have a problem set flag UPLOAD_STATUS_FAILED
log_esp3d("Close Error");
_upload_status=UPLOAD_STATUS_FAILED; _upload_status=UPLOAD_STATUS_FAILED;
pushError(ESP_ERROR_FILE_CLOSE, "File close failed"); pushError(ESP_ERROR_FILE_CLOSE, "File close failed");
} }

View File

@ -88,7 +88,7 @@ bool TimeServer::begin()
} }
#endif //ETH_FEATURE #endif //ETH_FEATURE
if (!is_internet_time()) { if (!is_internet_time()) {
return false; return true;
} }
s1 = Settings_ESP3D::read_string (ESP_TIME_SERVER1); s1 = Settings_ESP3D::read_string (ESP_TIME_SERVER1);
s2 = Settings_ESP3D::read_string (ESP_TIME_SERVER2); s2 = Settings_ESP3D::read_string (ESP_TIME_SERVER2);
@ -125,13 +125,6 @@ const char * TimeServer::current_time(time_t t)
time(&now); time(&now);
localtime_r(&now, &tmstruct); localtime_r(&now, &tmstruct);
} else { } else {
/* struct tm * tmstructtmp = localtime(&t);
tmstruct.tm_year = tmstructtmp->tm_year;
tmstruct.tm_mon = tmstructtmp->tm_mon;
tmstruct.tm_mday = tmstructtmp->tm_mday;
tmstruct.tm_hour = tmstructtmp->tm_hour;
tmstruct.tm_min = tmstructtmp->tm_min;
tmstruct.tm_sec = tmstructtmp->tm_sec;*/
localtime_r(&t, &tmstruct); localtime_r(&t, &tmstruct);
} }
stmp = String((tmstruct.tm_year)+1900) + "-"; stmp = String((tmstruct.tm_year)+1900) + "-";
@ -231,8 +224,6 @@ bool TimeServer::setTime(const char* stime)
return false; return false;
} }
tmstruct.tm_isdst = 0; //ignore dst tmstruct.tm_isdst = 0; //ignore dst
//reset servers, time zone and dst
configTime (0, 0,"", "", "");
tmstruct.tm_sec = substmp.toInt(); tmstruct.tm_sec = substmp.toInt();
time_val.tv_sec = mktime (&tmstruct); time_val.tv_sec = mktime (&tmstruct);
if(settimeofday(&time_val,0) == -1) { if(settimeofday(&time_val,0) == -1) {