mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-09 13:06:54 +03:00
speed up deletion of files (#2389)
* speed up deletion of files * . * . * . * . * . --------- Co-authored-by: CaCO3 <caco@ruinelli.ch>
This commit is contained in:
@@ -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 */
|
||||||
|
|||||||
Reference in New Issue
Block a user