Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Crocker <dcrocker@eschertech.com>2020-01-13 01:59:32 +0300
committerDavid Crocker <dcrocker@eschertech.com>2020-01-13 01:59:32 +0300
commit13084f6566c536df08430cce6c584f5e5c06b5a8 (patch)
tree44765c911f8a5850ee3d18147658b29b0eba0726 /src/Storage/MassStorage.cpp
parentd935cc8c828e44430f6a4dc2eacf53c04268fe96 (diff)
Various
Refactored how GCode blocks and indentation are tracked Fixed lack of motor movement on Duet 3 Create path recursively if needed when creating a directory or renaming a file
Diffstat (limited to 'src/Storage/MassStorage.cpp')
-rw-r--r--src/Storage/MassStorage.cpp48
1 files changed, 38 insertions, 10 deletions
diff --git a/src/Storage/MassStorage.cpp b/src/Storage/MassStorage.cpp
index e3d8e6b9..52a94e0b 100644
--- a/src/Storage/MassStorage.cpp
+++ b/src/Storage/MassStorage.cpp
@@ -374,27 +374,51 @@ bool MassStorage::Delete(const char* filePath) noexcept
return true;
}
-// Create a new directory
-bool MassStorage::MakeDirectory(const char *parentDir, const char *dirName) noexcept
+// Ensure that the path up to the last '/' (excluding trailing '/' characters) in filePath exists, returning true if successful
+bool MassStorage::EnsurePath(const char* filePath) noexcept
{
- String<MaxFilenameLength> location;
- if (!CombineName(location.GetRef(), parentDir, dirName))
+ // Try to create the path of this file if we want to write to it
+ String<MaxFilenameLength> filePathCopy;
+ filePathCopy.copy(filePath);
+
+ size_t i = (isdigit(filePathCopy[0]) && filePathCopy[1] == ':') ? 2 : 0;
+ if (filePathCopy[i] == '/')
{
- return false;
+ ++i;
}
- if (f_mkdir(location.c_str()) != FR_OK)
+
+ size_t limit = filePathCopy.strlen();
+ while (limit != 0 && filePath[limit - 1] == '/')
{
- reprap.GetPlatform().MessageF(ErrorMessage, "Failed to create directory %s\n", location.c_str());
- return false;
+ --limit;
+ }
+ while (i < limit)
+ {
+ if (filePathCopy[i] == '/')
+ {
+ filePathCopy[i] = 0;
+ if (!MassStorage::DirectoryExists(filePathCopy.GetRef()) && f_mkdir(filePathCopy.c_str()) != FR_OK)
+ {
+ reprap.GetPlatform().MessageF(ErrorMessage, "Failed to create folder %s in path %s\n", filePathCopy.c_str(), filePath);
+ return false;
+ }
+ filePathCopy[i] = '/';
+ }
+ ++i;
}
return true;
}
+// Create a new directory
bool MassStorage::MakeDirectory(const char *directory) noexcept
{
+ if (!EnsurePath(directory))
+ {
+ return false;
+ }
if (f_mkdir(directory) != FR_OK)
{
- reprap.GetPlatform().MessageF(ErrorMessage, "Failed to create directory %s\n", directory);
+ reprap.GetPlatform().MessageF(ErrorMessage, "Failed to create folder %s\n", directory);
return false;
}
return true;
@@ -405,11 +429,15 @@ bool MassStorage::Rename(const char *oldFilename, const char *newFilename) noexc
{
if (newFilename[0] >= '0' && newFilename[0] <= '9' && newFilename[1] == ':')
{
- // Workaround for DWC 1.13 which send a volume specification at the start of the new path.
+ // Workaround for DWC 1.13 which sends a volume specification at the start of the new path.
// f_rename can't handle this, so skip past the volume specification.
// We are assuming that the user isn't really trying to rename across volumes. This is a safe assumption when the client is DWC.
newFilename += 2;
}
+ if (!EnsurePath(newFilename))
+ {
+ return false;
+ }
if (f_rename(oldFilename, newFilename) != FR_OK)
{
reprap.GetPlatform().MessageF(ErrorMessage, "Failed to rename file or directory %s to %s\n", oldFilename, newFilename);