speed up deletion of files (#2389)

* speed up deletion of files

* .

* .

* .

* .

* .

---------

Co-authored-by: CaCO3 <caco@ruinelli.ch>
This commit is contained in:
CaCO3
2023-05-05 18:43:46 +02:00
committed by GitHub
parent ba7d6b3621
commit 431551fb45

View File

@@ -837,38 +837,22 @@ static esp_err_t delete_post_handler(httpd_req_t *req)
return ESP_FAIL; return ESP_FAIL;
} }
if (stat(filepath, &file_stat) == -1) { if (stat(filepath, &file_stat) == -1) { // File does not exist
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "File does not exist: " + string(filename)); /* This is ok, we would delete it anyway */
/* Respond with 400 Bad Request */ LogFile.WriteToFile(ESP_LOG_INFO, TAG, "File does not exist: " + string(filename));
httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST, "File does not exist"); }
return ESP_FAIL; else {
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Deleting file: " + string(filename));
/* Delete file */
unlink(filepath);
} }
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Deleting file: " + string(filename)); char *pos = strrchr(filename, '/');
/* Delete file */ *pos = '\0'; // Cut off filename
unlink(filepath); directory = std::string(filename);
directory = "/fileserver" + directory + "/";
directory = std::string(filepath);
size_t zw = directory.find("/");
size_t found = zw;
while (zw != std::string::npos)
{
zw = directory.find("/", found+1);
if (zw != std::string::npos)
found = zw;
}
int start_fn = strlen(((struct file_server_data *)req->user_ctx)->base_path);
ESP_LOGD(TAG, "Directory: %s, start_fn: %d, found: %d", directory.c_str(), start_fn, found);
directory = directory.substr(start_fn, found - start_fn + 1);
directory = "/fileserver" + directory;
ESP_LOGD(TAG, "Directory danach 4: %s", directory.c_str());
} }
////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////
/* Redirect onto root to see the updated file list */ /* Redirect onto root to see the updated file list */