Kea 2.7.1
filesystem.h
Go to the documentation of this file.
1// Copyright (C) 2021-2024 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef KEA_UTIL_FILESYSTEM_H
8#define KEA_UTIL_FILESYSTEM_H
9
10#include <sys/stat.h>
11#include <string>
12
13namespace isc {
14namespace util {
15namespace file {
16
23std::string
24getContent(const std::string& file_name);
25
31bool
32exists(const std::string& path);
33
40bool
41isDir(const std::string& path);
42
49bool
50isFile(const std::string& path);
51
53struct Umask {
57 Umask(mode_t mask);
58
62 ~Umask();
63
64private:
66 mode_t orig_umask_;
67};
68
70struct Path {
74 Path(std::string const& path);
75
81 std::string str() const;
82
88 std::string parentPath() const;
89
95 std::string stem() const;
96
102 std::string extension() const;
103
109 std::string filename() const;
110
122 Path& replaceExtension(std::string const& replacement = std::string());
123
133 Path& replaceParentPath(std::string const& replacement = std::string());
134
135private:
137 std::string parent_path_;
138
140 std::string stem_;
141
143 std::string extension_;
144};
145
146} // namespace file
147} // namespace util
148} // namespace isc
149
150#endif // KEA_UTIL_FILESYSTEM_H
string getContent(string const &file_name)
Get the content of a regular file.
Definition filesystem.cc:31
bool isFile(string const &path)
Check if there is a file at the given path.
Definition filesystem.cc:63
bool exists(string const &path)
Check if there is a file or directory at the given path.
Definition filesystem.cc:48
bool isDir(string const &path)
Check if there is a directory at the given path.
Definition filesystem.cc:54
Defines the logger used by the top-level component of kea-lfc.
Paths on a filesystem.
Definition filesystem.h:70
Path(std::string const &path)
Constructor.
Definition filesystem.cc:79
Path & replaceParentPath(std::string const &replacement=std::string())
Trims {replacement} and replaces this instance's parent path with it.
std::string extension() const
Get the extension of the file.
Path & replaceExtension(std::string const &replacement=std::string())
Identifies the extension in {replacement}, trims it, and replaces this instance's extension with it.
std::string stem() const
Get the base name of the file without the extension.
std::string parentPath() const
Get the parent path.
std::string filename() const
Get the name of the file, extension included.
std::string str() const
Get the path in textual format.
RAII device to limit access of created files.
Definition filesystem.h:53
Umask(mode_t mask)
Constructor.
Definition filesystem.cc:71