Well we learned a lot from Nginx, starting to incorporate some, but hoping for feedback before i do most of that, instead worked on improving the location sorter and checking that locations paths are valid, close but not quite done

This commit is contained in:
Me
2022-08-05 03:42:42 +02:00
parent f7e6b61811
commit 9ac14aa1aa
5 changed files with 90 additions and 53 deletions

View File

@@ -17,6 +17,10 @@
# include <vector>
# include <string>
# include <iostream>
# include <sys/stat.h> // stat()
# include <stdio.h> // printf(), gotta go
# include "utils.hpp"
@@ -99,6 +103,38 @@ public:
if (rhs.path[rhs.path.find_last_of("/") + 1] != '\0')
++comp_rhs;
// ok now we need to add a thing where we check for files vs folders
if (comp_lhs == comp_rhs)
{
std::cout << "locations are equal\n";
std::string tmp_path_lhs = root + path;
std::cout << "root + path: " << tmp_path_lhs << '\n';
// const char *c_path_lhs = (root + path).substr(1).c_str();
// could the problem be that i'm in the .hpp ?
const char *c_path_lhs = tmp_path_lhs.substr(1).c_str();
const char *c_path_rhs = (rhs.root + rhs.path).substr(1).c_str();
printf("lhs path: %s\n", c_path_lhs);
printf("rhs path: %s\n", c_path_rhs);
struct stat sl;
struct stat sr;
if (stat(c_path_lhs, &sl) == 0 && S_ISREG(sl.st_mode))
{
std::cout << "lhs is a file\n";
--comp_lhs;
}
if (stat(c_path_rhs, &sr) == 0 && S_ISREG(sr.st_mode))
{
std::cout << "rhs is a file\n";
--comp_rhs;
}
// do i need to free c_path's ???
}
std::cout << "comp_lhs: " << comp_lhs << " comp_rhs: " << comp_rhs \
<< " bool res: " << (comp_lhs > comp_rhs) << "\n";
// i honestly can't tell you how or why but using > rather than <