MCPcopy Create free account
hub / github.com/MarlinFirmware/Marlin / rmRfStar

Method rmRfStar

Marlin/src/sd/SdBaseFile.cpp:1850–1892  ·  view source on GitHub ↗

* Recursively delete a directory and all contained files. * * This is like the Unix/Linux 'rm -rf *' if called with the root directory * hence the name. * * Warning - This will remove all contents of the directory including * subdirectories. The directory will then be removed if it is not root. * The read-only attribute for files will be ignored. * * \note This function should not be use

Source from the content-addressed store, hash-verified

1848 * \return true for success, false for failure.
1849 */
1850bool SdBaseFile::rmRfStar() {
1851 if (ENABLED(SDCARD_READONLY)) return false;
1852
1853 uint32_t index;
1854 SdBaseFile f;
1855 rewind();
1856 while (curPosition_ < fileSize_) {
1857 // remember position
1858 index = curPosition_ / 32;
1859
1860 dir_t *p = readDirCache();
1861 if (!p) return false;
1862
1863 // done if past last entry
1864 if (p->name[0] == DIR_NAME_FREE) break;
1865
1866 // skip empty slot or '.' or '..'
1867 if (p->name[0] == DIR_NAME_DELETED || p->name[0] == '.') continue;
1868
1869 // skip if part of long file name or volume label in root
1870 if (!DIR_IS_FILE_OR_SUBDIR(p)) continue;
1871
1872 if (!f.open(this, index, O_READ)) return false;
1873 if (f.isSubDir()) {
1874 // recursively delete
1875 if (!f.rmRfStar()) return false;
1876 }
1877 else {
1878 // ignore read-only
1879 f.flags_ |= O_WRITE;
1880 if (!f.remove()) return false;
1881 }
1882 // position to next entry if required
1883 if (curPosition_ != (32 * (index + 1))) {
1884 if (!seekSet(32 * (index + 1))) return false;
1885 }
1886 }
1887 // don't try to delete root
1888 if (!isRoot()) {
1889 if (!rmdir()) return false;
1890 }
1891 return true;
1892}
1893
1894/**
1895 * Create a file object and open it in the current working directory.

Callers

nothing calls this directly

Calls 4

DIR_IS_FILE_OR_SUBDIRFunction · 0.85
isSubDirMethod · 0.80
removeMethod · 0.80
openMethod · 0.45

Tested by

no test coverage detected