Kea 2.7.6
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
69bool
70isSocket(const std::string& path);
71
73struct Path {
77 Path(std::string const& path);
78
84 std::string str() const;
85
91 std::string parentPath() const;
92
98 std::string stem() const;
99
105 std::string extension() const;
106
112 std::string filename() const;
113
125 Path& replaceExtension(std::string const& replacement = std::string());
126
136 Path& replaceParentPath(std::string const& replacement = std::string());
137
138private:
140 std::string parent_path_;
141
143 std::string stem_;
144
146 std::string extension_;
147};
148
152 std::string dirName();
153private:
154 std::string dir_name_;
155};
156
157} // namespace file
158} // namespace util
159} // namespace isc
160
161#endif // KEA_UTIL_FILESYSTEM_H
string getContent(string const &file_name)
Get the content of a regular file.
Definition filesystem.cc:29
bool isFile(string const &path)
Check if there is a file at the given path.
Definition filesystem.cc:61
bool exists(string const &path)
Check if there is a file or directory at the given path.
Definition filesystem.cc:46
bool isSocket(string const &path)
Definition filesystem.cc:78
bool isDir(string const &path)
Check if there is a directory at the given path.
Definition filesystem.cc:52
Defines the logger used by the top-level component of kea-lfc.
Paths on a filesystem.
Definition filesystem.h:73
Path(std::string const &path)
Constructor.
Definition filesystem.cc:86
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:69