diff --git a/src/upm/Context.cpp b/src/upm/Context.cpp index e438d6b..01e8a23 100644 --- a/src/upm/Context.cpp +++ b/src/upm/Context.cpp @@ -165,8 +165,8 @@ See GitHub for the full license. return -1; } - if (!fs::is_directory(Constants::UPM_ROOT)) { - fs::create_directories(Constants::UPM_ROOT); + if (!std::filesystem::is_directory(Constants::UPM_ROOT)) { + std::filesystem::create_directories(Constants::UPM_ROOT); } resolvePackageContext(input[0]); @@ -284,10 +284,10 @@ void Context::disable() { } for (auto& sourceDest : *it) { auto symlinkDest = sourceDest.at("target"); - fs::path castPath = fs::path(symlinkDest.get()); + std::filesystem::path castPath = std::filesystem::path(symlinkDest.get()); if (isGoodSymlink(castPath)) { spdlog::info("Unlinking {}", castPath.string()); - fs::remove(castPath); + std::filesystem::remove(castPath); } else { spdlog::error("Skipped bad entry: {}", castPath.string()); } @@ -325,7 +325,7 @@ std::string Context::locateFile(const std::string& packageName) { for (auto& dir : dirs) { // TODO: this is where alias cache lookup goes auto path = dir / (packageName + ".lua"); - if (fs::is_regular_file(path)) { + if (std::filesystem::is_regular_file(path)) { return path; } } @@ -334,13 +334,13 @@ std::string Context::locateFile(const std::string& packageName) { bool Context::checkInstalled() { auto prefix = getPrefix(); - bool isInstalled = fs::is_directory(prefix); + bool isInstalled = std::filesystem::is_directory(prefix); // TODO: use isInstalled + config to check whether or not the existing directory should be removed return isInstalled; } std::string Context::getPrefix() { - fs::path root = Constants::UPM_ROOT / "packages"; + std::filesystem::path root = Constants::UPM_ROOT / "packages"; root /= package + "-" + ( resolvedPackageVersion.empty() ? packageVersion : resolvedPackageVersion @@ -348,8 +348,8 @@ std::string Context::getPrefix() { return root.string(); } -std::vector Context::getLuaLookupDirectory() { - std::vector res; +std::vector Context::getLuaLookupDirectory() { + std::vector res; #ifdef UPM_DEBUG // If built as debug, make sure ./lua is included first in the search path. res.push_back("./lua/upm"); diff --git a/src/upm/Context.hpp b/src/upm/Context.hpp index fc597a0..ec1516f 100644 --- a/src/upm/Context.hpp +++ b/src/upm/Context.hpp @@ -124,7 +124,7 @@ class Context { bool checkInstalled(); std::string getPrefix(); - std::vector getLuaLookupDirectory(); + std::vector getLuaLookupDirectory(); std::string locateFile(const std::string& packageName); diff --git a/src/upm/api/Filesystem.cpp b/src/upm/api/Filesystem.cpp index ea8f5b3..5e02a13 100644 --- a/src/upm/api/Filesystem.cpp +++ b/src/upm/api/Filesystem.cpp @@ -9,7 +9,6 @@ #include #include -#include #include #include @@ -23,34 +22,34 @@ int upmfilesystem_exists(lua_State* state) { auto type = luaL_optinteger(state, 2, upm::filesystem::TYPE_ANY); - auto path = fs::path(luaL_checklstring(state, 1, nullptr)); + auto path = std::filesystem::path(luaL_checklstring(state, 1, nullptr)); switch (type) { case upm::filesystem::TYPE_ANY: lua_pushboolean(state, - static_cast(fs::exists(path))); + static_cast(std::filesystem::exists(path))); break; case upm::filesystem::TYPE_DIRECTORY: lua_pushboolean(state, - static_cast(fs::is_directory(path))); + static_cast(std::filesystem::is_directory(path))); break; case upm::filesystem::TYPE_FILE: // Not sure if is_regular_file is good enough. Using exists && !is_directory _might_ be better, but // I'm not sure lua_pushboolean(state, - static_cast(fs::is_regular_file(path))); + static_cast(std::filesystem::is_regular_file(path))); break; default: return luaL_error(state, "You supplied an invalid value for the type. Please use fs.TYPE_ANY, fs.TYPE_DIRECTORY, or fs.TYPE_FILE"); } lua_pushboolean(state, - static_cast(fs::exists(fs::path(luaL_checklstring(state, 1, nullptr)))) + static_cast(std::filesystem::exists(std::filesystem::path(luaL_checklstring(state, 1, nullptr)))) ); return 1; } int upmfilesystem_pwd(lua_State* L) { - lua_pushstring(L, fs::current_path().string().c_str());; + lua_pushstring(L, std::filesystem::current_path().string().c_str());; return 1; } @@ -94,13 +93,13 @@ int upmfilesystem_sharedLibInstalled(lua_State* state) { } int upmfilesystem_installCopy(lua_State* state) { - fs::path source = luaL_checkstring(state, 1); - fs::path dest = upm::Context::inst->getPrefix(); - if (!fs::is_directory(dest)) { fs::create_directories(dest); + std::filesystem::path source = luaL_checkstring(state, 1); + std::filesystem::path dest = upm::Context::inst->getPrefix(); + if (!std::filesystem::is_directory(dest)) { std::filesystem::create_directories(dest); } // At least recursive copying is easy now - fs::copy(source, dest, fs::copy_options::recursive | fs::copy_options::overwrite_existing | fs::copy_options::copy_symlinks); + std::filesystem::copy(source, dest, std::filesystem::copy_options::recursive | std::filesystem::copy_options::overwrite_existing | std::filesystem::copy_options::copy_symlinks); return 0; } @@ -235,7 +234,7 @@ int upmfilesystem_makeInstallOnly(lua_State *state) { // TODO: Replace with libarchive int upmfilesystem_untar(lua_State* state) { - fs::path source = luaL_checkstring(state, 1); + std::filesystem::path source = luaL_checkstring(state, 1); if (auto pos = source.string().find("/tmp/"); pos != 0) { throw std::runtime_error("Invalid path; must be a path to /tmp/"); } @@ -255,7 +254,7 @@ int upmfilesystem_untar(lua_State* state) { tarArg += " -C " + dest.string(); upm::filesystem::logger->info("Unpacking {} to {}...", source.string(), dest.string()); - fs::create_directories(dest); + std::filesystem::create_directories(dest); auto res = std::system(("tar " + tarArg).c_str()); if (res != 0) { return luaL_error(state, "Failed to untar"); diff --git a/src/upm/api/Git.cpp b/src/upm/api/Git.cpp index 2b09330..154040e 100644 --- a/src/upm/api/Git.cpp +++ b/src/upm/api/Git.cpp @@ -1,6 +1,5 @@ #include "Git.hpp" -#include #include #include @@ -15,12 +14,12 @@ int git_clone(lua_State* state) { std::string dest = luaL_checklstring(state, 2, nullptr); bool clean = (lua_gettop(state) >= 3 ? lua_toboolean(state, 3) : 0) != 0; bool absPath = (lua_gettop(state) >= 4 ? lua_toboolean(state, 4) : 0) != 0; - fs::path p = absPath ? dest : ("/tmp/upm/" + dest); + std::filesystem::path p = absPath ? dest : ("/tmp/upm/" + dest); - if (fs::exists(p)) { + if (std::filesystem::exists(p)) { if (clean) { spdlog::info("Already cloned. Reset policy forces cache deletion..."); - if (fs::remove_all(p) == 0u) { + if (std::filesystem::remove_all(p) == 0u) { return luaL_error(state, ("Failed to delete " + p.string()).c_str()); } } else { diff --git a/src/upm/api/LuaHelper.cpp b/src/upm/api/LuaHelper.cpp index 1dffa99..d9d128f 100644 --- a/src/upm/api/LuaHelper.cpp +++ b/src/upm/api/LuaHelper.cpp @@ -13,7 +13,7 @@ #include "stdfunc/Activators.hpp" #include "stdfunc/VersionResolvers.hpp" -#include +#include #include @@ -26,7 +26,7 @@ LuaHelper::LuaHelper() { // but I'll eventually make a lock-based system for execution, similar // to how apt does it, to prevent this from happening. // Not sure how I'd go about it, however. - fs::create_directory("/tmp/upm"); + std::filesystem::create_directory("/tmp/upm"); state = luaL_newstate(); } diff --git a/src/upm/api/Network.cpp b/src/upm/api/Network.cpp index 50d9f61..9046003 100644 --- a/src/upm/api/Network.cpp +++ b/src/upm/api/Network.cpp @@ -3,8 +3,7 @@ #include "lua.h" #include "lua.hpp" -#include -#include +#include #include // Do I really need this twice? @@ -44,9 +43,9 @@ int upmnetwork_download(lua_State* state) { auto name = url.substr(url.rfind('/') + 1); - fs::path tmpDir = fs::temp_directory_path(); - fs::path p = tmpDir / ("upm/" + name); - if (fs::exists(p)) { + std::filesystem::path tmpDir = std::filesystem::temp_directory_path(); + std::filesystem::path p = tmpDir / ("upm/" + name); + if (std::filesystem::exists(p)) { spdlog::info("Cache entry found at {}.", p.string()); lua_pushinteger(state, 200); lua_pushstring(state, p.string().c_str()); diff --git a/src/upm/api/stdfunc/Activators.cpp b/src/upm/api/stdfunc/Activators.cpp index fb4404c..c5d6eed 100644 --- a/src/upm/api/stdfunc/Activators.cpp +++ b/src/upm/api/stdfunc/Activators.cpp @@ -38,7 +38,7 @@ int activators_activateSingle(lua_State *L) { std::string qualifiedDest = dest[0] != '/' ? "/usr/local/" + dest : dest; - if (!fs::exists(src)) { + if (!std::filesystem::exists(src)) { return luaL_error(L, (src + "doesn't exist").c_str()); } spdlog::info("Linking {} -> {}", src, qualifiedDest); @@ -50,11 +50,11 @@ int activators_activateSingle(lua_State *L) { } ); - if (fs::exists(qualifiedDest)) { - fs::remove_all(qualifiedDest); + if (std::filesystem::exists(qualifiedDest)) { + std::filesystem::remove_all(qualifiedDest); } - fs::create_symlink(src, qualifiedDest); + std::filesystem::create_symlink(src, qualifiedDest); ctx.cfg.save(); diff --git a/src/upm/conf/Config.cpp b/src/upm/conf/Config.cpp index fd2a845..2a403cd 100644 --- a/src/upm/conf/Config.cpp +++ b/src/upm/conf/Config.cpp @@ -12,7 +12,7 @@ namespace upm { Config::Config(Context* ctx) : ctx(ctx) { confPath = Constants::UPM_ROOT / ".upmrc"; - if (!fs::exists(confPath)) { + if (!std::filesystem::exists(confPath)) { spdlog::debug("No config found at " + confPath.string()); return; } @@ -28,7 +28,7 @@ Config::~Config() { } void Config::save() { - if (this->confPath.empty() || fs::is_directory(this->confPath)) { + if (this->confPath.empty() || std::filesystem::is_directory(this->confPath)) { spdlog::warn("No confPath set; cannot save"); return; } diff --git a/src/upm/conf/Config.hpp b/src/upm/conf/Config.hpp index 04b82ea..cae073d 100644 --- a/src/upm/conf/Config.hpp +++ b/src/upm/conf/Config.hpp @@ -1,7 +1,7 @@ #pragma once #include "nlohmann/json.hpp" -#include "stc/Environment.hpp" +#include namespace upm { @@ -9,7 +9,7 @@ class Context; class Config { private: Context* ctx; - fs::path confPath; + std::filesystem::path confPath; void setup(); public: diff --git a/src/upm/conf/Constants.hpp b/src/upm/conf/Constants.hpp index 1688f6a..5870043 100644 --- a/src/upm/conf/Constants.hpp +++ b/src/upm/conf/Constants.hpp @@ -1,11 +1,11 @@ #pragma once +#include #include #include #include #include #include -#include "stc/FS.hpp" namespace upm::Constants { static inline std::vector sinks = { @@ -15,7 +15,7 @@ static inline std::vector sinks = { const static auto inline logger = std::make_shared("upm", sinks.begin(), sinks.end()); -const static fs::path UPM_ROOT("/opt/upm/"); -const static fs::path APPLY_ROOT("/usr/local/"); +const static std::filesystem::path UPM_ROOT("/opt/upm/"); +const static std::filesystem::path APPLY_ROOT("/usr/local/"); } diff --git a/src/upm/package/Activators.cpp b/src/upm/package/Activators.cpp index 4090a92..9857bb7 100644 --- a/src/upm/package/Activators.cpp +++ b/src/upm/package/Activators.cpp @@ -3,7 +3,6 @@ #include "upm/Context.hpp" #include "upm/conf/Constants.hpp" #include -#include #include #include @@ -21,8 +20,8 @@ bool Activators::recursiveUniversalUNIXLink(std::vector& safeDirNam auto& ctx = *Context::inst; safeDirNames.push_back(ctx.package); - auto prefix = fs::path(ctx.getPrefix()); - if (!fs::exists(prefix)) { + auto prefix = std::filesystem::path(ctx.getPrefix()); + if (!std::filesystem::exists(prefix)) { spdlog::error("Folder {} does not exist.", prefix.string()); return false; } @@ -30,19 +29,19 @@ bool Activators::recursiveUniversalUNIXLink(std::vector& safeDirNam spdlog::info("Found match in {}", prefix.string()); - std::vector> links; + std::vector> links; for (const auto& dir : directories) { - fs::path sourcePath = prefix / dir; - if (!fs::exists(sourcePath)) { + std::filesystem::path sourcePath = prefix / dir; + if (!std::filesystem::exists(sourcePath)) { // Skip non-existent folders. These are just part of the standard, but not all the // folders are required continue; } - fs::path destPath = Constants::APPLY_ROOT / dir; - if (!fs::exists(destPath)) { - fs::create_directories(destPath); + std::filesystem::path destPath = Constants::APPLY_ROOT / dir; + if (!std::filesystem::exists(destPath)) { + std::filesystem::create_directories(destPath); } - for (const auto& path : fs::directory_iterator(sourcePath)) { + for (const auto& path : std::filesystem::directory_iterator(sourcePath)) { // returns the path relative to sourcePath // TODO: see if calling .path() is unnecessary std::string fn = path.path().lexically_relative(sourcePath); @@ -55,16 +54,16 @@ bool Activators::recursiveUniversalUNIXLink(std::vector& safeDirNam spdlog::info("Built symlink tree. Checking for conflicts..."); bool good = true; for (auto& [source, target] : links) { - if (fs::exists(target)) { - auto allowOverwrite = fs::is_directory(target) && ( - fs::is_empty(target) + if (std::filesystem::exists(target)) { + auto allowOverwrite = std::filesystem::is_directory(target) && ( + std::filesystem::is_empty(target) || std::find(safeDirNames.begin(), safeDirNames.end(), target.filename()) != safeDirNames.end() ); - if (!fs::is_symlink(target) + if (!std::filesystem::is_symlink(target) && ( !allowOverwrite - || !fs::is_directory(target) + || !std::filesystem::is_directory(target) ) ) { spdlog::warn("Found existing file or non-symlinked directory at {}", target.string()); @@ -72,7 +71,7 @@ bool Activators::recursiveUniversalUNIXLink(std::vector& safeDirNam continue; } if (!allowOverwrite) { - auto str = fs::read_symlink(target).string(); + auto str = std::filesystem::read_symlink(target).string(); // TODO: link in context to make this dynamic if (str.find(Constants::UPM_ROOT.string()) == std::string::npos) { spdlog::warn("Found existing symlink at {}, but that points to a non-upm directory ({}).", @@ -102,12 +101,12 @@ bool Activators::recursiveUniversalUNIXLink(std::vector& safeDirNam // TODO: use package..files instead, and add // a package..version ctx.cfg.data["package"][ctx.package].push_back({{"target", target.string()}, {"source", source.string()}}); - if (fs::exists(target)) { + if (std::filesystem::exists(target)) { // This is semi-temporary 'til we get uninstallation in place - fs::remove_all(target); + std::filesystem::remove_all(target); } - fs::create_directories(target.parent_path()); - fs::create_symlink(source, target); + std::filesystem::create_directories(target.parent_path()); + std::filesystem::create_symlink(source, target); } ctx.cfg.save(); @@ -115,17 +114,17 @@ bool Activators::recursiveUniversalUNIXLink(std::vector& safeDirNam } // Util defs {{{ -std::vector> Activators::Utils::recursiveLink( - const fs::path &source, - const fs::path &dest, +std::vector> Activators::Utils::recursiveLink( + const std::filesystem::path &source, + const std::filesystem::path &dest, const std::string& fileName, const std::vector& safeDirNames, const std::vector& ignoreFiles ) { - if (fs::is_directory(source / fileName) && std::find(safeDirNames.begin(), safeDirNames.end(), fileName) == safeDirNames.end()) { - std::vector> result; - for (const auto& path : fs::directory_iterator(source / fileName)) { + if (std::filesystem::is_directory(source / fileName) && std::find(safeDirNames.begin(), safeDirNames.end(), fileName) == safeDirNames.end()) { + std::vector> result; + for (const auto& path : std::filesystem::directory_iterator(source / fileName)) { std::string fn = path.path().lexically_relative(source / fileName); if (std::find(ignoreFiles.begin(), ignoreFiles.end(), fn) != ignoreFiles.end()) { spdlog::debug("{} is ignored and will not be linked", fn); diff --git a/src/upm/package/Activators.hpp b/src/upm/package/Activators.hpp index 85ef3df..addf0b8 100644 --- a/src/upm/package/Activators.hpp +++ b/src/upm/package/Activators.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include #include @@ -14,9 +14,9 @@ namespace upm { namespace Activators { namespace Utils { -extern std::vector> recursiveLink( - const fs::path &source, - const fs::path &dest, +extern std::vector> recursiveLink( + const std::filesystem::path &source, + const std::filesystem::path &dest, const std::string& fileName, const std::vector& safeDirNames, const std::vector& ignoredFiles = {} diff --git a/src/upm/util/PathUtils.hpp b/src/upm/util/PathUtils.hpp index 9aeea9c..8e87315 100644 --- a/src/upm/util/PathUtils.hpp +++ b/src/upm/util/PathUtils.hpp @@ -1,15 +1,15 @@ #pragma once -#include "stc/FS.hpp" +#include namespace upm { /** * returns whether or not a path is a symlink, and points to a upm directory. */ -inline bool isGoodSymlink(const fs::path& link) { - return fs::is_symlink(link) - && fs::read_symlink(link).string().find("/upm") != std::string::npos; +inline bool isGoodSymlink(const std::filesystem::path& link) { + return std::filesystem::is_symlink(link) + && std::filesystem::read_symlink(link).string().find("/upm") != std::string::npos; } }