diff options
author | David Crocker <dcrocker@eschertech.com> | 2018-03-30 20:39:09 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2018-03-30 20:39:09 +0300 |
commit | de270d2a00fd83cc3961a749432bff940601f1dd (patch) | |
tree | 7a9f781a99def2ffa10734c1053d94e0cb3651d4 /src/Storage/FileStore.cpp | |
parent | 22e0ac40dd0f7fb5a362476d054bfbb6e8aa4293 (diff) |
Thread safe file system
Various changes to maske the filesystem thread safe
Diffstat (limited to 'src/Storage/FileStore.cpp')
-rw-r--r-- | src/Storage/FileStore.cpp | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/Storage/FileStore.cpp b/src/Storage/FileStore.cpp index 86c24893..4b386f7e 100644 --- a/src/Storage/FileStore.cpp +++ b/src/Storage/FileStore.cpp @@ -55,16 +55,15 @@ bool FileStore::IsOpenOn(const FATFS *fs) const // This is protected - only Platform can access it. bool FileStore::Open(const char* directory, const char* fileName, OpenMode mode) { - const char* const location = (directory != nullptr) - ? reprap.GetPlatform().GetMassStorage()->CombineName(directory, fileName) - : fileName; + String<MaxFilenameLength> location; + MassStorage::CombineName(location.GetRef(), directory, fileName); writing = (mode == OpenMode::write || mode == OpenMode::append); if (writing) { // Try to create the path of this file if we want to write to it String<MaxFilenameLength> filePath; - filePath.copy(location); + filePath.copy(location.c_str()); size_t i = (isdigit(filePath[0]) && filePath[1] == ':') ? 2 : 0; if (filePath[i] == '/') @@ -77,9 +76,9 @@ bool FileStore::Open(const char* directory, const char* fileName, OpenMode mode) if (filePath[i] == '/') { filePath[i] = 0; - if (!reprap.GetPlatform().GetMassStorage()->DirectoryExists(filePath.Pointer()) && !reprap.GetPlatform().GetMassStorage()->MakeDirectory(filePath.Pointer())) + if (!reprap.GetPlatform().GetMassStorage()->DirectoryExists(filePath.c_str()) && !reprap.GetPlatform().GetMassStorage()->MakeDirectory(filePath.c_str())) { - reprap.GetPlatform().MessageF(ErrorMessage, "Failed to create directory %s while trying to open file %s\n", filePath.Pointer(), location); + reprap.GetPlatform().MessageF(ErrorMessage, "Failed to create directory %s while trying to open file %s\n", filePath.c_str(), location.c_str()); return false; } filePath[i] = '/'; @@ -94,7 +93,7 @@ bool FileStore::Open(const char* directory, const char* fileName, OpenMode mode) writeBuffer = (mode == OpenMode::write) ? reprap.GetPlatform().GetMassStorage()->AllocateWriteBuffer() : nullptr; } - const FRESULT openReturn = f_open(&file, location, + const FRESULT openReturn = f_open(&file, location.c_str(), (mode == OpenMode::write) ? FA_CREATE_ALWAYS | FA_WRITE : (mode == OpenMode::append) ? FA_WRITE | FA_OPEN_ALWAYS : FA_OPEN_EXISTING | FA_READ); @@ -104,7 +103,7 @@ bool FileStore::Open(const char* directory, const char* fileName, OpenMode mode) // It is up to the caller to report an error if necessary. if (reprap.Debug(modulePlatform)) { - reprap.GetPlatform().MessageF(ErrorMessage, "Can't open %s to %s, error code %d\n", location, (writing) ? "write" : "read", openReturn); + reprap.GetPlatform().MessageF(ErrorMessage, "Can't open %s to %s, error code %d\n", location.c_str(), (writing) ? "write" : "read", openReturn); } return false; } |