From 1a501cd9146907e187899287d49ac57b90d36245 Mon Sep 17 00:00:00 2001 From: Angelo Mantellini Date: Fri, 15 Mar 2019 18:41:01 +0100 Subject: [HICN-119] Error when hicn-http-test tries to create tree of folders Change-Id: Iab3f9d03296c4185467ae08aa2fa4c35a19b6708 Signed-off-by: Angelo Mantellini --- apps/src/http-server/http-server.cc | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'apps/src/http-server/http-server.cc') diff --git a/apps/src/http-server/http-server.cc b/apps/src/http-server/http-server.cc index 7f6f8a3e8..0a224088d 100644 --- a/apps/src/http-server/http-server.cc +++ b/apps/src/http-server/http-server.cc @@ -56,6 +56,35 @@ string getFileName(const string &strPath) { #endif } +int _mkdir(const char *dir) { + std::cout << dir << std::endl; + char tmp[PATH_MAX]; + char *p = NULL; + size_t len; + + snprintf(tmp, sizeof(tmp), "%s", dir); + len = strlen(tmp); + if (tmp[len - 1] == '/') + tmp[len - 1] = 0; + for (p = tmp + 1; *p; p++) { + if (*p == '/') { + *p = 0; + if (!(std::ifstream(tmp).good())) { + if (mkdir(tmp, S_IRWXU) == -1) + return -1; + } + *p = '/'; + } + } + + if (!(std::ifstream(tmp).good())) { + if (mkdir(tmp, S_IRWXU) == -1) + return -1; + } + + return 0; +} + string getExtension(const string &strPath) { size_t iLastSeparator = 0; return strPath.substr((iLastSeparator = strPath.find_last_of(".")) != @@ -157,8 +186,7 @@ int main(int argc, char **argv) { } } if (!(std::ifstream(root_folder).good())) { - if (mkdir(root_folder.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == - -1) { + if (_mkdir(root_folder.c_str()) == -1) { std::cerr << "The web root folder " << root_folder << " does not exist and its creation failed. Exiting.." << std::endl; -- cgit 1.2.3-korg