MCPcopy Create free account
hub / github.com/andysworkshop/stm32plus / deleteDirectory

Method deleteDirectory

lib/src/filesystem/fat/FatFileSystem.cpp:433–470  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

431 */
432
433 bool FatFileSystem::deleteDirectory(const char *dirname_) {
434
435 FatDirectoryIterator *it;
436 bool retval,hasContent;
437
438 // cannot have content
439
440 if(!directoryHasContent(dirname_,hasContent))
441 return false;
442
443 if(hasContent)
444 return errorProvider.set(ErrorProvider::ERROR_PROVIDER_FILESYSTEM,E_DIRECTORY_NOT_EMPTY);
445
446 // tokenise the path. can't delete the root directory
447
448 TokenisedPathname tp(dirname_);
449 if(tp.getNumTokens() == 0)
450 return errorProvider.set(ErrorProvider::ERROR_PROVIDER_FILESYSTEM,E_INVALID_PATHNAME);
451
452 // get the directory entry for the file
453
454 if(!getDirectoryIteratorPointingToFile(tp,it))
455 return false;
456
457 // it must be a file
458
459 DirectoryEntryWithLocation& dirent=it->getDirectoryEntryWithLocation();
460
461 if(!dirent.isDirectory())
462 retval=errorProvider.set(ErrorProvider::ERROR_PROVIDER_FILESYSTEM,E_NOT_A_DIRECTORY);
463 else if(it->isParentDirectory() || it->isCurrentDirectory())
464 retval=errorProvider.set(ErrorProvider::ERROR_PROVIDER_FILESYSTEM,E_INVALID_PATHNAME);
465 else
466 retval=fullyDelete(*it);
467
468 delete it;
469 return retval;
470 }
471
472 /**
473 * Delete a file.

Callers 1

removeDirectoryMethod · 0.80

Calls 5

getNumTokensMethod · 0.80
isDirectoryMethod · 0.80
isParentDirectoryMethod · 0.80
isCurrentDirectoryMethod · 0.80
setMethod · 0.45

Tested by

no test coverage detected