mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Fix failure when trying to open empty file (#1126)
This commit is contained in:
parent
053de36223
commit
f7bbea407e
@ -410,6 +410,17 @@ protected:
|
||||
FileImplPtr SPIFFSImpl::open(const char* path, OpenMode openMode, AccessMode accessMode) {
|
||||
int mode = getSpiffsMode(openMode, accessMode);
|
||||
int fd = SPIFFS_open(&_fs, path, mode, 0);
|
||||
if (fd < 0 && _fs.err_code == SPIFFS_ERR_DELETED && (openMode & OM_CREATE)) {
|
||||
DEBUGV("SPIFFSImpl::open: fd=%d path=`%s` openMode=%d accessMode=%d err=%d, trying to remove\r\n",
|
||||
fd, path, openMode, accessMode, _fs.err_code);
|
||||
auto rc = SPIFFS_remove(&_fs, path);
|
||||
if (rc != SPIFFS_OK) {
|
||||
DEBUGV("SPIFFSImpl::open: SPIFFS_ERR_DELETED, but failed to remove path=`%s` openMode=%d accessMode=%d err=%d\r\n",
|
||||
path, openMode, accessMode, _fs.err_code);
|
||||
return FileImplPtr();
|
||||
}
|
||||
fd = SPIFFS_open(&_fs, path, mode, 0);
|
||||
}
|
||||
if (fd < 0) {
|
||||
DEBUGV("SPIFFSImpl::open: fd=%d path=`%s` openMode=%d accessMode=%d err=%d\r\n",
|
||||
fd, path, openMode, accessMode, _fs.err_code);
|
||||
|
@ -139,7 +139,15 @@ void setup() {
|
||||
fail("some files left after format");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
File tmp = SPIFFS.open("/tmp.txt", "w");
|
||||
}
|
||||
{
|
||||
File tmp = SPIFFS.open("/tmp.txt", "w");
|
||||
if (!tmp) {
|
||||
fail("failed to re-open empty file");
|
||||
}
|
||||
}
|
||||
Serial.println("success");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user