diff options
author | Angelo Mantellini <manangel@cisco.com> | 2019-03-15 18:41:01 +0100 |
---|---|---|
committer | Angelo Mantellini <manangel@cisco.com> | 2019-03-15 18:41:01 +0100 |
commit | 1a501cd9146907e187899287d49ac57b90d36245 (patch) | |
tree | fe188e41d26cd455697f7b0c29d458c6d1edb9a9 /apps/src/http-server/http-server.cc | |
parent | a1e949253043fe1a644f71cef0572ede30b752be (diff) |
[HICN-119] Error when hicn-http-test tries to create tree of folders
Change-Id: Iab3f9d03296c4185467ae08aa2fa4c35a19b6708
Signed-off-by: Angelo Mantellini <manangel@cisco.com>
Diffstat (limited to 'apps/src/http-server/http-server.cc')
-rw-r--r-- | apps/src/http-server/http-server.cc | 32 |
1 files changed, 30 insertions, 2 deletions
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; |