1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-18 07:52:14 +01:00

Adding SD.rmdir(). Returning success / failure from SD functions.

This commit is contained in:
David A. Mellis 2010-11-20 14:49:20 -05:00
parent d05a57af19
commit a6f3f27d35
2 changed files with 34 additions and 11 deletions

View File

@ -182,6 +182,10 @@ boolean walkPath(char *filepath, SdFile& parentDir,
return false;
}
if (!moreComponents) {
break;
}
boolean exists = (*p_child).open(*p_parent, buffer, O_RDONLY);
// If it's one we've created then we
@ -204,14 +208,11 @@ boolean walkPath(char *filepath, SdFile& parentDir,
} else {
return false;
}
if (!moreComponents) {
// TODO: Check if this check should be earlier.
break;
}
}
(*p_parent).close(); // TODO: Return/ handle different?
if (p_parent != &parentDir) {
(*p_parent).close(); // TODO: Return/ handle different?
}
return true;
}
@ -307,8 +308,17 @@ boolean callback_openPath(SdFile& parentDir, char *filePathComponent,
boolean callback_remove(SdFile& parentDir, char *filePathComponent,
boolean isLastComponent, void *object) {
if (isLastComponent) {
SdFile::remove(parentDir, filePathComponent);
return false;
return SdFile::remove(parentDir, filePathComponent);
}
return true;
}
boolean callback_rmdir(SdFile& parentDir, char *filePathComponent,
boolean isLastComponent, void *object) {
if (isLastComponent) {
SdFile f;
if (!f.open(parentDir, filePathComponent, O_READ)) return false;
return f.rmDir();
}
return true;
}
@ -420,8 +430,19 @@ boolean SDClass::mkdir(char *filepath) {
return walkPath(filepath, root, callback_makeDirPath);
}
void SDClass::remove(char *filepath) {
walkPath(filepath, root, callback_remove);
boolean SDClass::rmdir(char *filepath) {
/*
Makes a single directory or a heirarchy of directories.
A rough equivalent to `mkdir -p`.
*/
return walkPath(filepath, root, callback_rmdir);
}
boolean SDClass::remove(char *filepath) {
return walkPath(filepath, root, callback_remove);
}
SDClass SD;

View File

@ -59,7 +59,9 @@ public:
boolean mkdir(char *filepath);
// Delete the file.
void remove(char *filepath);
boolean remove(char *filepath);
boolean rmdir(char *filepath);
private:
SdFile file;