Loading src/client/path.cpp +6 −8 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ #include <string> #include <cassert> #include <climits> #include <stack> extern "C" { #include <sys/stat.h> Loading Loading @@ -111,7 +112,8 @@ 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") string::size_type last_slash_pos = 0; // index of last slash in resolved path stack<string::size_type> slash_idx{}; slash_idx.push(0); // index of all slashes in resolved path (used for rollback due to `..`) resolved.clear(); resolved.reserve(path.size()); Loading Loading @@ -141,12 +143,8 @@ 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(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); resolved.erase(slash_idx.top()); slash_idx.pop(); } if (resolved_components > 0) { if (matched_components == resolved_components) { Loading @@ -159,7 +157,7 @@ bool resolve(const string& path, string& resolved, bool resolve_last_link) { // add `/<component>` to the reresolved path resolved.push_back(path::separator); last_slash_pos = resolved.size() - 1; slash_idx.push(resolved.size() - 1); resolved.append(path, start, comp_size); if (matched_components < mnt_components.size()) { Loading Loading
src/client/path.cpp +6 −8 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ #include <string> #include <cassert> #include <climits> #include <stack> extern "C" { #include <sys/stat.h> Loading Loading @@ -111,7 +112,8 @@ 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") string::size_type last_slash_pos = 0; // index of last slash in resolved path stack<string::size_type> slash_idx{}; slash_idx.push(0); // index of all slashes in resolved path (used for rollback due to `..`) resolved.clear(); resolved.reserve(path.size()); Loading Loading @@ -141,12 +143,8 @@ 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(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); resolved.erase(slash_idx.top()); slash_idx.pop(); } if (resolved_components > 0) { if (matched_components == resolved_components) { Loading @@ -159,7 +157,7 @@ bool resolve(const string& path, string& resolved, bool resolve_last_link) { // add `/<component>` to the reresolved path resolved.push_back(path::separator); last_slash_pos = resolved.size() - 1; slash_idx.push(resolved.size() - 1); resolved.append(path, start, comp_size); if (matched_components < mnt_components.size()) { Loading