Skip to content

Commit

Permalink
Display error message when trying to delete non-empty directory (#1321)
Browse files Browse the repository at this point in the history
* Non-empty directory check

* Non-empty directory check

* Display error when attempting to delete non-empty directory

* Clang

Delete white-space that the friggin editor added

* is_empty_directory

* is_empty_directory

* is_empty_directory

* Now need to check if it's a directory first
  • Loading branch information
NotherNgineer committed Jul 30, 2023
1 parent 411f6c0 commit 91c6e3f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions firmware/application/apps/ui_fileman.cpp
Expand Up @@ -440,6 +440,11 @@ void FileManagerView::on_rename(std::string_view hint) {
}

void FileManagerView::on_delete() {
if (is_directory(get_selected_full_path()) && !is_empty_directory(get_selected_full_path())) {
nav_.display_modal("Delete", "Directory not empty!");
return;
}

auto name = get_selected_entry().path.filename().string();
nav_.push<ModalMessageView>(
"Delete", "Delete " + name + "\nAre you sure?", YESNO,
Expand Down
11 changes: 11 additions & 0 deletions firmware/application/file.cpp
Expand Up @@ -568,6 +568,17 @@ bool is_directory(const path& file_path) {
return fr == FR_OK && is_directory(static_cast<file_status>(filinfo.fattrib));
}

bool is_empty_directory(const path& file_path) {
DIR dir;
FILINFO filinfo;

if (!is_directory(file_path))
return false;

auto result = f_findfirst(&dir, &filinfo, reinterpret_cast<const TCHAR*>(file_path.c_str()), (const TCHAR*)u"*");
return !((result == FR_OK) && (filinfo.fname[0] != (TCHAR)'\0'));
}

space_info space(const path& p) {
DWORD free_clusters{0};
FATFS* fs;
Expand Down
1 change: 1 addition & 0 deletions firmware/application/file.hpp
Expand Up @@ -248,6 +248,7 @@ bool is_directory(const file_status s);
bool is_regular_file(const file_status s);
bool file_exists(const path& file_path);
bool is_directory(const path& file_path);
bool is_empty_directory(const path& file_path);

space_info space(const path& p);

Expand Down

0 comments on commit 91c6e3f

Please sign in to comment.