Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions components/file_system/example/main/file_system_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,16 @@ extern "C" void app_main(void) {
logger.info("\t{}", f);
}

// attempt to delete an etry that doesn't exist
fs::path nonexistent = sandbox / "does_not_exist.txt";
if (!espp_fs.remove(nonexistent, ec)) {
logger.info("Properly returned error when trying to remove nonexistent file {} - {}",
nonexistent.string(), ec.message());
ec.clear();
} else {
logger.error("Removed nonexistent file {} - this should not happen!", nonexistent.string());
}

// cleanup, use convenience functions
// NOTE: cannot use fs::remove since it seems POSIX remove() doesn't work
// We'll use espp::FileSystem::remove, which works for both files and
Expand Down
4 changes: 4 additions & 0 deletions components/file_system/src/file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ bool FileSystem::remove(const std::filesystem::path &path, std::error_code &ec)
logger_.debug("Removing path: {}", path.string());
namespace fs = std::filesystem;
auto file_status = fs::status(path, ec);
if (ec) {
logger_.info("Failed to get status for file: {}", path.string());
return false;
}
if (std::filesystem::is_directory(file_status)) {
if (!remove_contents(path, ec)) {
logger_.error("Failed to remove contents of directory: {}", path.string());
Expand Down
Loading