little delete fix in main.cpp

This commit is contained in:
lperrey
2022-08-17 20:55:58 +02:00
parent e537e9bb78
commit 2613ca2e1a
3 changed files with 18 additions and 34 deletions

View File

@@ -1,12 +1,11 @@
#include "Webserv.hpp"
void Webserv::_post(Client *client, const std::string &path)
{
/*
https://www.rfc-editor.org/rfc/rfc9110.html#name-post
*/
void Webserv::_post(Client *client, const std::string &path)
{
(void)path; // unused, we use "assigned_location->upload_dir" instead
std::cout << "_post()\n";
std::cerr << "upload_dir = " << client->assigned_location->upload_dir << "\n";
@@ -26,8 +25,8 @@ void Webserv::_post(Client *client, const std::string &path)
_upload_files(client);
}
// #include <ctime> // could add date to DEFAULT_NAME to avoid overwriting files
#define DEFAULT_NAME "unnamed_file"
// TODO : Loop for multi body
void Webserv::_upload_files(Client *client)
{
std::cout << "_upload_files()\n";
@@ -37,6 +36,7 @@ void Webserv::_upload_files(Client *client)
std::string filename;
size_t pos;
bool file_existed = false;
static int i_name = 0;
client->status = ::eval_file_access(client->assigned_location->upload_dir, W_OK);
if (client->status)
@@ -64,13 +64,10 @@ void Webserv::_upload_files(Client *client)
filename.erase(filename.size()-1, 1);
std::cerr << "filename ="<< filename << "\n";
std::cerr << "filename ="<< filename << "\n";
if (filename.empty())
filename = DEFAULT_NAME;
}
else
{
filename = DEFAULT_NAME;
}
if (pos == NPOS || filename.empty())
filename = DEFAULT_NAME + ::itos(i_name++);
std::cerr << "filename ="<< filename << "\n";
path = client->assigned_location->upload_dir; // Assume there a final '/'
path.append(filename);