| 34 | } |
| 35 | |
| 36 | bool State::setEntriesForPath(const std::string& path) { |
| 37 | LOGGER.info("Changing path: {} -> {}", current_path, path); |
| 38 | |
| 39 | auto lock = mutex.asScopedLock(); |
| 40 | if (!lock.lock(100)) { |
| 41 | LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "setEntriesForPath"); |
| 42 | return false; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * ESP32 does not have a root directory, so we have to create it manually. |
| 47 | * We'll add the NVS Flash partitions and the binding for the sdcard. |
| 48 | */ |
| 49 | bool show_custom_root = (kernel::getPlatform() == kernel::PlatformEsp) && (path == "/"); |
| 50 | if (show_custom_root) { |
| 51 | LOGGER.info("Setting custom root"); |
| 52 | dir_entries = file::getFileSystemDirents(); |
| 53 | current_path = path; |
| 54 | selected_child_entry = ""; |
| 55 | return true; |
| 56 | } else { |
| 57 | dir_entries.clear(); |
| 58 | int count = file::scandir(path, dir_entries, &file::direntFilterDotEntries, file::direntSortAlphaAndType); |
| 59 | if (count >= 0) { |
| 60 | LOGGER.info("{} has {} entries", path, count); |
| 61 | current_path = path; |
| 62 | selected_child_entry = ""; |
| 63 | return true; |
| 64 | } else { |
| 65 | LOGGER.error("Failed to fetch entries for {}", path); |
| 66 | return false; |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | bool State::setEntriesForChildPath(const std::string& childPath) { |
| 72 | auto path = file::getChildPath(current_path, childPath); |
no test coverage detected