diff --git a/mandatory/inc/FileContent.hpp b/mandatory/inc/FileContent.hpp index a240c36..7600eba 100644 --- a/mandatory/inc/FileContent.hpp +++ b/mandatory/inc/FileContent.hpp @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* FileContent.hpp :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: eavedill +#+ +:+ +#+ */ +/* By: eavedill +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/30 13:48:24 by eavedill #+# #+# */ -/* Updated: 2024/06/30 14:55:08 by eavedill ### ########.fr */ +/* Updated: 2024/07/02 23:16:02 by eavedill ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,7 +33,7 @@ class FileContent : public StatusCode { protected: - CGI *cgiModule; + CGI *cgiModule; private: std::string fileName; std::string indexName; diff --git a/mandatory/inc/ListDir.hpp b/mandatory/inc/ListDir.hpp index acb1ffa..d3b5ccd 100644 --- a/mandatory/inc/ListDir.hpp +++ b/mandatory/inc/ListDir.hpp @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* ListDir.hpp :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: eavedill +#+ +:+ +#+ */ +/* By: eavedill +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/07 19:03:57 by eavedill #+# #+# */ -/* Updated: 2024/06/30 14:47:57 by eavedill ### ########.fr */ +/* Updated: 2024/07/02 23:13:22 by eavedill ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,6 +32,7 @@ class ListDir std::size_t posToSend; std::map files; bool isSendComplete; + bool isFileOpen; public: ListDir(); @@ -48,5 +49,6 @@ class ListDir std::string getContentToSend(); size_t getSizeToSend(); void setSubdirectory(const std::string &); + bool getIsFileOpen(); }; diff --git a/mandatory/src/FileContent.cpp b/mandatory/src/FileContent.cpp index bbcaadf..5565d81 100644 --- a/mandatory/src/FileContent.cpp +++ b/mandatory/src/FileContent.cpp @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* FileContent.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: eavedill +#+ +:+ +#+ */ +/* By: eavedill +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/30 13:50:28 by eavedill #+# #+# */ -/* Updated: 2024/06/30 15:26:47 by eavedill ### ########.fr */ +/* Updated: 2024/07/02 23:25:35 by eavedill ### ########.fr */ /* */ /* ************************************************************************** */ @@ -49,10 +49,18 @@ std::string FileContent::getContent() { if (isAutoIndex && this->isInputDirectory()) { - isFileOpen = true; - content = listDir->getContentToSend(); - this->setCompleteContentSize(content.size()); - this->setIsSendComplete(listDir->getIsSendComlete()); + isFileOpen = listDir->getIsFileOpen(); + if (!isFileOpen) + { + content = this->getFileContentForStatusCode(NOT_FOUND_CODE); + this->setIsSendComplete(true); + } + else + { + content = listDir->getContentToSend(); + this->setCompleteContentSize(content.size()); + this->setIsSendComplete(listDir->getIsSendComlete()); + } return content; } else if (this->cgiModule->getIsCGI()) diff --git a/mandatory/src/ListDir.cpp b/mandatory/src/ListDir.cpp index e08e376..d1d5b75 100644 --- a/mandatory/src/ListDir.cpp +++ b/mandatory/src/ListDir.cpp @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* ListDir.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: eavedill +#+ +:+ +#+ */ +/* By: eavedill +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/30 13:51:56 by eavedill #+# #+# */ -/* Updated: 2024/06/30 15:25:36 by eavedill ### ########.fr */ +/* Updated: 2024/07/02 23:14:13 by eavedill ### ########.fr */ /* */ /* ************************************************************************** */ @@ -125,6 +125,12 @@ void ListDir::openMasterListFile() { std::string filename = TEMPLATE_LIST_DIR; file.open(filename.c_str(), std::ios::out | std::ios::binary); + if (!file.is_open()) + { + isFileOpen = false; + return; + } + isFileOpen = true; } std::string ListDir::getContentToSend() @@ -153,4 +159,9 @@ void ListDir::setSubdirectory(const std::string &subDir) } path += (path[path.size() -1] == '/') ? "" :"/"; this->setListOfFiles(); +} + +bool ListDir::getIsFileOpen() +{ + return isFileOpen; } \ No newline at end of file diff --git a/mandatory/src/ListeningSocket.cpp b/mandatory/src/ListeningSocket.cpp index 65a0caf..e660438 100644 --- a/mandatory/src/ListeningSocket.cpp +++ b/mandatory/src/ListeningSocket.cpp @@ -6,7 +6,7 @@ /* By: eavedill +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/30 13:51:47 by eavedill #+# #+# */ -/* Updated: 2024/06/30 15:38:42 by eavedill ### ########.fr */ +/* Updated: 2024/06/30 16:25:05 by eavedill ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/mandatory/src/LocationParser.cpp b/mandatory/src/LocationParser.cpp index cf21659..575c59b 100644 --- a/mandatory/src/LocationParser.cpp +++ b/mandatory/src/LocationParser.cpp @@ -112,7 +112,7 @@ int LocationParser::matchingLocation() return NO_LOCATION; } -off_t getFileSize(const std::string &filename) +long long getFileSize(const std::string &filename) { struct stat stat_buf; int rc = stat(filename.c_str(), &stat_buf);