diff options
Diffstat (limited to 'src/base/fs_util.hh')
-rw-r--r-- | src/base/fs_util.hh | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/src/base/fs_util.hh b/src/base/fs_util.hh index b9253ff..7553075 100644 --- a/src/base/fs_util.hh +++ b/src/base/fs_util.hh @@ -30,6 +30,7 @@ #ifndef lnav_fs_util_hh #define lnav_fs_util_hh +#include <set> #include <string> #include <vector> @@ -41,6 +42,14 @@ namespace lnav { namespace filesystem { +inline bool +is_glob(const std::string& fn) +{ + return (fn.find('*') != std::string::npos + || fn.find('?') != std::string::npos + || fn.find('[') != std::string::npos); +} + inline int statp(const ghc::filesystem::path& path, struct stat* buf) { @@ -59,6 +68,9 @@ openp(const ghc::filesystem::path& path, int flags, mode_t mode) return open(path.c_str(), flags, mode); } +Result<ghc::filesystem::path, std::string> realpath( + const ghc::filesystem::path& path); + Result<auto_fd, std::string> create_file(const ghc::filesystem::path& path, int flags, mode_t mode); @@ -73,8 +85,18 @@ Result<std::pair<ghc::filesystem::path, auto_fd>, std::string> open_temp_file( Result<std::string, std::string> read_file(const ghc::filesystem::path& path); -Result<void, std::string> write_file(const ghc::filesystem::path& path, - const string_fragment& content); +enum class write_file_options { + backup_existing, +}; + +struct write_file_result { + nonstd::optional<ghc::filesystem::path> wfr_backup_path; +}; + +Result<write_file_result, std::string> write_file( + const ghc::filesystem::path& path, + const string_fragment& content, + std::set<write_file_options> options = {}); std::string build_path(const std::vector<ghc::filesystem::path>& paths); @@ -119,4 +141,12 @@ public: } // namespace filesystem } // namespace lnav +namespace fmt { +template<> +struct formatter<ghc::filesystem::path> : formatter<string_view> { + auto format(const ghc::filesystem::path& p, format_context& ctx) + -> decltype(ctx.out()) const; +}; +} // namespace fmt + #endif |