Allow (empty) directory removal
This commit is contained in:
@@ -230,19 +230,21 @@ void FileBrowserActivity::loop() {
|
|||||||
|
|
||||||
const std::string& entry = files[selectorIndex];
|
const std::string& entry = files[selectorIndex];
|
||||||
const bool isDirectory = (entry.back() == '/');
|
const bool isDirectory = (entry.back() == '/');
|
||||||
|
std::string entryName = entry;
|
||||||
if (isDirectory) {
|
if (isDirectory) {
|
||||||
return;
|
entryName.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string cleanBase = basepath;
|
std::string cleanBase = basepath;
|
||||||
if (cleanBase.back() != '/') cleanBase += "/";
|
if (cleanBase.back() != '/') cleanBase += "/";
|
||||||
const std::string fullPath = cleanBase + entry;
|
const std::string fullPath = cleanBase + entryName;
|
||||||
|
|
||||||
auto handler = [this, fullPath](const ActivityResult& res) {
|
auto handler = [this, fullPath, isDirectory](const ActivityResult& res) {
|
||||||
if (!res.isCancelled) {
|
if (!res.isCancelled) {
|
||||||
LOG_DBG("FileBrowser", "Attempting to delete: %s", fullPath.c_str());
|
LOG_DBG("FileBrowser", "Attempting to delete: %s", fullPath.c_str());
|
||||||
clearFileMetadata(fullPath);
|
clearFileMetadata(fullPath);
|
||||||
if (Storage.remove(fullPath.c_str())) {
|
const bool deleted = isDirectory ? Storage.removeDir(fullPath.c_str()) : Storage.remove(fullPath.c_str());
|
||||||
|
if (deleted) {
|
||||||
LOG_DBG("FileBrowser", "Deleted successfully");
|
LOG_DBG("FileBrowser", "Deleted successfully");
|
||||||
loadFiles();
|
loadFiles();
|
||||||
if (files.empty()) {
|
if (files.empty()) {
|
||||||
@@ -252,7 +254,7 @@ void FileBrowserActivity::loop() {
|
|||||||
}
|
}
|
||||||
requestUpdate(true);
|
requestUpdate(true);
|
||||||
} else {
|
} else {
|
||||||
LOG_ERR("FileBrowser", "Failed to delete file: %s", fullPath.c_str());
|
LOG_ERR("FileBrowser", "Failed to delete: %s", fullPath.c_str());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG_DBG("FileBrowser", "Delete cancelled by user");
|
LOG_DBG("FileBrowser", "Delete cancelled by user");
|
||||||
|
|||||||
Reference in New Issue
Block a user