1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-23 08:45:22 +03:00

Revert "Allman now (#6080)" (#6090)

This reverts commit 98125f8860.
This commit is contained in:
Allman-astyler
2019-05-14 00:09:54 +02:00
committed by david gauchard
parent 98125f8860
commit eea9999dc5
255 changed files with 42650 additions and 50904 deletions

View File

@ -1,29 +1,29 @@
/*
SDFS.cpp - file system wrapper for SdFat
Copyright (c) 2019 Earle F. Philhower, III. All rights reserved.
SDFS.cpp - file system wrapper for SdFat
Copyright (c) 2019 Earle F. Philhower, III. All rights reserved.
Based on spiffs_api.cpp which is:
| Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
Based on spiffs_api.cpp which is:
| Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
This code was influenced by NodeMCU and Sming libraries, and first version of
Arduino wrapper written by Hristo Gochkov.
This code was influenced by NodeMCU and Sming libraries, and first version of
Arduino wrapper written by Hristo Gochkov.
This file is part of the esp8266 core for Arduino environment.
This file is part of the esp8266 core for Arduino environment.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "SDFS.h"
#include "SDFSFormatter.h"
#include <FS.h>
@ -35,34 +35,28 @@ using namespace fs;
FS SDFS = FS(FSImplPtr(new sdfs::SDFSImpl()));
#endif
namespace sdfs
{
namespace sdfs {
FileImplPtr SDFSImpl::open(const char* path, OpenMode openMode, AccessMode accessMode)
{
if (!_mounted)
{
if (!_mounted) {
DEBUGV("SDFSImpl::open() called on unmounted FS\n");
return FileImplPtr();
}
if (!path || !path[0])
{
if (!path || !path[0]) {
DEBUGV("SDFSImpl::open() called with invalid filename\n");
return FileImplPtr();
}
int flags = _getFlags(openMode, accessMode);
if ((openMode && OM_CREATE) && strchr(path, '/'))
{
if ((openMode && OM_CREATE) && strchr(path, '/')) {
// For file creation, silently make subdirs as needed. If any fail,
// it will be caught by the real file open later on
char *pathStr = strdup(path);
if (pathStr)
{
if (pathStr) {
// Make dirs up to the final fnamepart
char *ptr = strrchr(pathStr, '/');
if (ptr && ptr != pathStr) // Don't try to make root dir!
{
if (ptr && ptr != pathStr) { // Don't try to make root dir!
*ptr = 0;
_fs.mkdir(pathStr, true);
}
@ -70,8 +64,7 @@ FileImplPtr SDFSImpl::open(const char* path, OpenMode openMode, AccessMode acces
free(pathStr);
}
sdfat::File fd = _fs.open(path, flags);
if (!fd)
{
if (!fd) {
DEBUGV("SDFSImpl::openFile: fd=%p path=`%s` openMode=%d accessMode=%d",
&fd, path, openMode, accessMode);
return FileImplPtr();
@ -82,80 +75,62 @@ FileImplPtr SDFSImpl::open(const char* path, OpenMode openMode, AccessMode acces
DirImplPtr SDFSImpl::openDir(const char* path)
{
if (!_mounted)
{
if (!_mounted) {
return DirImplPtr();
}
char *pathStr = strdup(path); // Allow edits on our scratch copy
if (!pathStr)
{
if (!pathStr) {
// OOM
return DirImplPtr();
}
// Get rid of any trailing slashes
while (strlen(pathStr) && (pathStr[strlen(pathStr) - 1] == '/'))
{
pathStr[strlen(pathStr) - 1] = 0;
while (strlen(pathStr) && (pathStr[strlen(pathStr)-1]=='/')) {
pathStr[strlen(pathStr)-1] = 0;
}
// At this point we have a name of "/blah/blah/blah" or "blah" or ""
// If that references a directory, just open it and we're done.
sdfat::File dirFile;
const char *filter = "";
if (!pathStr[0])
{
if (!pathStr[0]) {
// openDir("") === openDir("/")
dirFile = _fs.open("/", sdfat::O_RDONLY);
filter = "";
}
else if (_fs.exists(pathStr))
{
} else if (_fs.exists(pathStr)) {
dirFile = _fs.open(pathStr, sdfat::O_RDONLY);
if (dirFile.isDir())
{
if (dirFile.isDir()) {
// Easy peasy, path specifies an existing dir!
filter = "";
}
else
{
} else {
dirFile.close();
// This is a file, so open the containing dir
char *ptr = strrchr(pathStr, '/');
if (!ptr)
{
if (!ptr) {
// No slashes, open the root dir
dirFile = _fs.open("/", sdfat::O_RDONLY);
filter = pathStr;
}
else
{
} else {
// We've got slashes, open the dir one up
*ptr = 0; // Remove slash, truncare string
dirFile = _fs.open(pathStr, sdfat::O_RDONLY);
filter = ptr + 1;
}
}
}
else
{
} else {
// Name doesn't exist, so use the parent dir of whatever was sent in
// This is a file, so open the containing dir
char *ptr = strrchr(pathStr, '/');
if (!ptr)
{
if (!ptr) {
// No slashes, open the root dir
dirFile = _fs.open("/", sdfat::O_RDONLY);
filter = pathStr;
}
else
{
} else {
// We've got slashes, open the dir one up
*ptr = 0; // Remove slash, truncare string
dirFile = _fs.open(pathStr, sdfat::O_RDONLY);
filter = ptr + 1;
}
}
if (!dirFile)
{
if (!dirFile) {
DEBUGV("SDFSImpl::openDir: path=`%s`\n", path);
return DirImplPtr();
}
@ -165,10 +140,8 @@ DirImplPtr SDFSImpl::openDir(const char* path)
return ret;
}
bool SDFSImpl::format()
{
if (_mounted)
{
bool SDFSImpl::format() {
if (_mounted) {
return false;
}
SDFSFormatter formatter;