Loading src/client/path.cpp +8 −6 Original line number Diff line number Diff line Loading @@ -22,7 +22,6 @@ #include <string> #include <cassert> #include <climits> #include <stack> extern "C" { #include <sys/stat.h> Loading Loading @@ -112,8 +111,7 @@ bool resolve(const string& path, string& resolved, bool resolve_last_link) { string::size_type comp_size = 0; // size of current component string::size_type start = 0; // start index of curr component string::size_type end = 0; // end index of curr component (last processed Path Separator "separator") stack<string::size_type> slash_idx{}; slash_idx.push(0); // index of all slashes in resolved path (used for rollback due to `..`) string::size_type last_slash_pos = 0; // index of last slash in resolved path resolved.clear(); resolved.reserve(path.size()); Loading Loading @@ -143,8 +141,12 @@ bool resolve(const string& path, string& resolved, bool resolve_last_link) { if (comp_size == 2 && path.at(start) == '.' && path.at(start + 1) == '.') { // component is '..' we need to rollback resolved path if (!resolved.empty()) { resolved.erase(slash_idx.top()); slash_idx.pop(); resolved.erase(last_slash_pos); /* TODO Optimization * the previous slash position should be stored. * The following search could be avoided. */ last_slash_pos = resolved.find_last_of(path::separator); } if (resolved_components > 0) { if (matched_components == resolved_components) { Loading @@ -157,7 +159,7 @@ bool resolve(const string& path, string& resolved, bool resolve_last_link) { // add `/<component>` to the reresolved path resolved.push_back(path::separator); slash_idx.push(resolved.size() - 1); last_slash_pos = resolved.size() - 1; resolved.append(path, start, comp_size); if (matched_components < mnt_components.size()) { Loading Loading
src/client/path.cpp +8 −6 Original line number Diff line number Diff line Loading @@ -22,7 +22,6 @@ #include <string> #include <cassert> #include <climits> #include <stack> extern "C" { #include <sys/stat.h> Loading Loading @@ -112,8 +111,7 @@ bool resolve(const string& path, string& resolved, bool resolve_last_link) { string::size_type comp_size = 0; // size of current component string::size_type start = 0; // start index of curr component string::size_type end = 0; // end index of curr component (last processed Path Separator "separator") stack<string::size_type> slash_idx{}; slash_idx.push(0); // index of all slashes in resolved path (used for rollback due to `..`) string::size_type last_slash_pos = 0; // index of last slash in resolved path resolved.clear(); resolved.reserve(path.size()); Loading Loading @@ -143,8 +141,12 @@ bool resolve(const string& path, string& resolved, bool resolve_last_link) { if (comp_size == 2 && path.at(start) == '.' && path.at(start + 1) == '.') { // component is '..' we need to rollback resolved path if (!resolved.empty()) { resolved.erase(slash_idx.top()); slash_idx.pop(); resolved.erase(last_slash_pos); /* TODO Optimization * the previous slash position should be stored. * The following search could be avoided. */ last_slash_pos = resolved.find_last_of(path::separator); } if (resolved_components > 0) { if (matched_components == resolved_components) { Loading @@ -157,7 +159,7 @@ bool resolve(const string& path, string& resolved, bool resolve_last_link) { // add `/<component>` to the reresolved path resolved.push_back(path::separator); slash_idx.push(resolved.size() - 1); last_slash_pos = resolved.size() - 1; resolved.append(path, start, comp_size); if (matched_components < mnt_components.size()) { Loading