Commit 4e34ac00 authored by Marc Vef's avatar Marc Vef
Browse files

add namespaces: gkfs::path, gkfs::path_util. Unify: gkfs::logging, gkfs::env

parent 77eadb1c
Loading
Loading
Loading
Loading
+16 −7
Original line number Diff line number Diff line
@@ -12,8 +12,15 @@
*/

#include <string>
#include <vector>

bool resolve_path(const std::string& path, std::string& resolved, bool resolve_last_link = true);
namespace gkfs {
    namespace path {

        unsigned int match_components(const std::string& path, unsigned int& path_components,
                                      const std::vector<std::string>& components);

        bool resolve(const std::string& path, std::string& resolved, bool resolve_last_link = true);

        std::string get_sys_cwd();

@@ -26,3 +33,5 @@ void unset_env_cwd();
        void init_cwd();

        void set_cwd(const std::string& path, bool internal);
    }
}
+3 −5
Original line number Diff line number Diff line
@@ -19,9 +19,7 @@
namespace gkfs {
    namespace env {

std::string
get_var(const std::string& name, 
        const std::string& default_value = "");
        std::string get_var(const std::string& name, const std::string& default_value = "");

    } // namespace env
} // namespace gkfs
+8 −4
Original line number Diff line number Diff line
@@ -16,11 +16,15 @@

#include <spdlog/spdlog.h>

spdlog::level::level_enum get_spdlog_level(std::string level_str);
namespace gkfs {
    namespace logging {

spdlog::level::level_enum get_spdlog_level(unsigned long level);
        spdlog::level::level_enum get_level(std::string level_str);

void setup_loggers(const std::vector<std::string>& loggers,
                   spdlog::level::level_enum level, const std::string& path);
        spdlog::level::level_enum get_level(unsigned long level);

        void setup(const std::vector<std::string>& loggers, spdlog::level::level_enum level, const std::string& path);
    }
}

#endif
+15 −8
Original line number Diff line number Diff line
@@ -17,20 +17,27 @@
#include <string>
#include <vector>

constexpr unsigned int PATH_MAX_LEN = 4096; // 4k chars
namespace gkfs {
    namespace path_util {

constexpr char PSP = '/'; // PATH SEPARATOR
        constexpr unsigned int max_length = 4096; // 4k chars

bool is_relative_path(const std::string& path);
        constexpr char separator = '/'; // PATH SEPARATOR

bool is_absolute_path(const std::string& path);
        bool is_relative(const std::string& path);

        bool is_absolute(const std::string& path);

        bool has_trailing_slash(const std::string& path);

        std::string prepend_path(const std::string& path, const char* raw_path);

        std::string absolute_to_relative(const std::string& root_path, const std::string& absolute_path); // unused ATM

        std::string dirname(const std::string& path);

        std::vector<std::string> split_path(const std::string& 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 = dirname(path);
    auto p_comp = gkfs::path_util::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 = PATH_MAX_LEN;
    buf->f_namelen = gkfs::path_util::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 = PATH_MAX_LEN;
    buf->f_namemax = gkfs::path_util::max_length;
    buf->f_frsize = 0;
    buf->f_flag =
            ST_NOATIME | ST_NODIRATIME | ST_NOSUID | ST_NODEV | ST_SYNCHRONOUS;
Loading