Commit 3083d1ab authored by Marc Vef's avatar Marc Vef
Browse files

Renaming gkfs::path_util namespace to gkfs::path; indent fixes

parent 2fd6c14b
Loading
Loading
Loading
Loading
+13 −12
Original line number Diff line number Diff line
@@ -33,5 +33,6 @@ namespace gkfs {
void init_cwd();

void set_cwd(const std::string& path, bool internal);
    }
}

} // namespace path
} // namespace gkfs
+13 −12
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@
#include <vector>

namespace gkfs {
    namespace path_util {
namespace path {

constexpr unsigned int max_length = 4096; // 4k chars

@@ -37,7 +37,8 @@ namespace gkfs {
std::string dirname(const std::string& path);

std::vector<std::string> split_path(const std::string& path);
    }
}

} // namespace gkfs
} // namespace path

#endif //GEKKOFS_PATH_UTIL_HPP
+3 −3
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ std::shared_ptr<Metadata> gkfs::func::metadata(const string& path, bool follow_l

int gkfs::func::check_parent_dir(const std::string& path) {
#if CREATE_CHECK_PARENTS
    auto p_comp = gkfs::path_util::dirname(path);
    auto p_comp = path::dirname(path);
    auto md = gkfs::func::metadata(p_comp);
    if (!md) {
        if (errno == ENOENT) {
@@ -232,7 +232,7 @@ int gkfs::func::statfs(sys_statfs* buf) {
    buf->f_files = 0;
    buf->f_ffree = 0;
    buf->f_fsid = {0, 0};
    buf->f_namelen = gkfs::path_util::max_length;
    buf->f_namelen = path::max_length;
    buf->f_frsize = 0;
    buf->f_flags =
            ST_NOATIME | ST_NODIRATIME | ST_NOSUID | ST_NODEV | ST_SYNCHRONOUS;
@@ -250,7 +250,7 @@ int gkfs::func::statvfs(sys_statvfs* buf) {
    buf->f_ffree = 0;
    buf->f_favail = 0;
    buf->f_fsid = 0;
    buf->f_namemax = gkfs::path_util::max_length;
    buf->f_namemax = path::max_length;
    buf->f_frsize = 0;
    buf->f_flag =
            ST_NOATIME | ST_NODIRATIME | ST_NOSUID | ST_NODEV | ST_SYNCHRONOUS;
+2 −2
Original line number Diff line number Diff line
@@ -515,7 +515,7 @@ int hook_chdir(const char* path) {
        //TODO get complete path from relativize_path instead of
        // removing mountdir and then adding again here
        rel_path.insert(0, CTX->mountdir());
        if (gkfs::path_util::has_trailing_slash(rel_path)) {
        if (gkfs::path::has_trailing_slash(rel_path)) {
            // open_dir is '/'
            rel_path.pop_back();
        }
@@ -543,7 +543,7 @@ int hook_fchdir(unsigned int fd) {
        }

        std::string new_path = CTX->mountdir() + open_dir->path();
        if (gkfs::path_util::has_trailing_slash(new_path)) {
        if (gkfs::path::has_trailing_slash(new_path)) {
            // open_dir is '/'
            new_path.pop_back();
        }
+31 −27
Original line number Diff line number Diff line
@@ -30,9 +30,10 @@ extern "C" {

using namespace std;

static const string excluded_paths[2] = {"sys/", "proc/"};
namespace gkfs {
namespace path {

namespace p_util = gkfs::path_util;
static const string excluded_paths[2] = {"sys/", "proc/"};

/** Match components in path
 *
@@ -42,13 +43,13 @@ namespace p_util = gkfs::path_util;
 * `path_components` will be set to the total number of components found in `path`
 *
 * Example:
 * ```
 * ```ÏÏ
 *  unsigned int tot_comp;
 *  path_match_components("/matched/head/with/tail", &tot_comp, ["matched", "head", "no"]) == 2;
 *  tot_comp == 4;
 * ```
 */
unsigned int gkfs::path::match_components(const string& path, unsigned int& path_components,
unsigned int match_components(const string& path, unsigned int& path_components,
                              const ::vector<string>& components) {
    unsigned int matched = 0;
    unsigned int processed_components = 0;
@@ -60,7 +61,7 @@ unsigned int gkfs::path::match_components(const string& path, unsigned int& path
        start = end;

        // Find next component
        end = path.find(p_util::separator, start);
        end = path.find(path::separator, start);
        if (end == string::npos) {
            end = path.size();
        }
@@ -88,12 +89,12 @@ unsigned int gkfs::path::match_components(const string& path, unsigned int& path
 * returns true if the resolved path fall inside GekkoFS namespace,
 * and false otherwise.
 */
bool gkfs::path::resolve(const string& path, string& resolved, bool resolve_last_link) {
bool resolve(const string& path, string& resolved, bool resolve_last_link) {

    LOG(DEBUG, "path: \"{}\", resolved: \"{}\", resolve_last_link: {}",
        path, resolved, resolve_last_link);

    assert(p_util::is_absolute(path));
    assert(path::is_absolute(path));

    for (auto& excl_path: excluded_paths) {
        if (path.compare(1, excl_path.length(), excl_path) == 0) {
@@ -118,12 +119,12 @@ bool gkfs::path::resolve(const string& path, string& resolved, bool resolve_last
        start = end;

        /* Skip sequence of multiple path-separators. */
        while (start < path.size() && path[start] == p_util::separator) {
        while (start < path.size() && path[start] == path::separator) {
            ++start;
        }

        // Find next component
        end = path.find(p_util::separator, start);
        end = path.find(path::separator, start);
        if (end == string::npos) {
            end = path.size();
        }
@@ -145,7 +146,7 @@ bool gkfs::path::resolve(const string& path, string& resolved, bool resolve_last
                 * the previous slash position should be stored.
                 * The following search could be avoided.
                 */
                last_slash_pos = resolved.find_last_of(p_util::separator);
                last_slash_pos = resolved.find_last_of(path::separator);
            }
            if (resolved_components > 0) {
                if (matched_components == resolved_components) {
@@ -157,7 +158,7 @@ bool gkfs::path::resolve(const string& path, string& resolved, bool resolve_last
        }

        // add `/<component>` to the reresolved path
        resolved.push_back(p_util::separator);
        resolved.push_back(path::separator);
        last_slash_pos = resolved.size() - 1;
        resolved.append(path, start, comp_size);

@@ -191,7 +192,7 @@ bool gkfs::path::resolve(const string& path, string& resolved, bool resolve_last
                resolved = link_resolved.get();
                matched_components = match_components(resolved, resolved_components, mnt_components);
                // set matched counter to value coherent with the new path
                last_slash_pos = resolved.find_last_of(p_util::separator);
                last_slash_pos = resolved.find_last_of(path::separator);
                continue;
            } else if ((!S_ISDIR(st.st_mode)) && (end != path.size())) {
                resolved.append(path, end, string::npos);
@@ -211,28 +212,28 @@ bool gkfs::path::resolve(const string& path, string& resolved, bool resolve_last
    }

    if (resolved.empty()) {
        resolved.push_back(p_util::separator);
        resolved.push_back(path::separator);
    }
    LOG(DEBUG, "external: \"{}\"", resolved);
    return false;
}

string gkfs::path::get_sys_cwd() {
    char temp[p_util::max_length];
    if (long ret = syscall_no_intercept(SYS_getcwd, temp, p_util::max_length) < 0) {
string get_sys_cwd() {
    char temp[path::max_length];
    if (long ret = syscall_no_intercept(SYS_getcwd, temp, path::max_length) < 0) {
        throw ::system_error(syscall_error_code(ret),
                             ::system_category(),
                             "Failed to retrieve current working directory");
    }
    // getcwd could return "(unreachable)<PATH>" in some cases
    if (temp[0] != p_util::separator) {
    if (temp[0] != path::separator) {
        throw ::runtime_error(
                "Current working directory is unreachable");
    }
    return {temp};
}

void gkfs::path::set_sys_cwd(const string& path) {
void set_sys_cwd(const string& path) {

    LOG(DEBUG, "Changing working directory to \"{}\"", path);

@@ -245,7 +246,7 @@ void gkfs::path::set_sys_cwd(const string& path) {
    }
}

void gkfs::path::set_env_cwd(const string& path) {
void set_env_cwd(const string& path) {

    LOG(DEBUG, "Setting {} to \"{}\"", gkfs::env::CWD, path);

@@ -258,7 +259,7 @@ void gkfs::path::set_env_cwd(const string& path) {
    }
}

void gkfs::path::unset_env_cwd() {
void unset_env_cwd() {

    LOG(DEBUG, "Clearing {}()", gkfs::env::CWD);

@@ -273,7 +274,7 @@ void gkfs::path::unset_env_cwd() {
    }
}

void gkfs::path::init_cwd() {
void init_cwd() {
    const char* env_cwd = ::getenv(gkfs::env::CWD);
    if (env_cwd != nullptr) {
        CTX->cwd(env_cwd);
@@ -282,7 +283,7 @@ void gkfs::path::init_cwd() {
    }
}

void gkfs::path::set_cwd(const string& path, bool internal) {
void set_cwd(const string& path, bool internal) {
    if (internal) {
        set_sys_cwd(CTX->mountdir());
        set_env_cwd(path);
@@ -292,3 +293,6 @@ void gkfs::path::set_cwd(const string& path, bool internal) {
    }
    CTX->cwd(path);
}

} // namespace path
} // namespace gkfs
 No newline at end of file
Loading