MantisBase v0.4.9
Loading...
Searching...
No Matches
files.h
Go to the documentation of this file.
1
8
9#ifndef MB_FILES_H
10#define MB_FILES_H
11
12#include <optional>
13#include <string>
14#include <vector>
15#include "../utils/utils.h"
17#ifdef MB_SCRIPTING_ENABLED
19#endif
20
21namespace mb {
53 public:
54 explicit MbFilesMgr(const MantisBase &app);
55
65 void createDir(const std::string &entity_name) const;
66
77 void renameDir(const std::string &old_entity_name, const std::string &new_entity_name) const;
78
84 void deleteDir(const std::string &entity_name) const;
85
97 [[nodiscard]] std::string dirPath(const std::string &entity_name, bool create_if_missing = false) const;
98
110 [[nodiscard]] std::string filePath(const std::string &entity_name, const std::string &filename) const;
111
123 std::optional<std::string> getFilePath(const std::string &entity_name, const std::string &filename);
124
125#ifdef MB_SCRIPTING_ENABLED
126 [[nodiscard]] std::string getFilePathString(const std::string &entity_name,
127 const std::string &filename);
129 void removeFilesJson(const std::string &entity_name, const MbScriptJson &files) const;
130 [[nodiscard]] std::string canonicalPathString(const std::string &path) const;
131 [[nodiscard]] bool isCanonicalPathString(const std::string &path) const;
132 [[nodiscard]] std::string filesBaseDirString() const;
133#endif
134
142 [[nodiscard]] bool removeFile(const std::string &entity_name, const std::string &filename) const;
143
150 void removeFiles(const std::string &entity_name, const std::vector<std::string> &files) const;
151
159 [[nodiscard]] bool fileExists(const std::string &entity_name, const std::string &filename) const;
160
171 [[nodiscard]] fs::path getCanonicalPath(const fs::path &path) const;
172
182 [[nodiscard]] bool isCanonicalPath(const fs::path &path) const;
183
191 [[nodiscard]] fs::path filesBaseDir() const;
192 };
193} // mb
194
195#endif // MB_FILES_H
MantisBase entry point.
Definition mantisbase.h:54
MbAppMixin(const MantisBase &app)
Constrictor for instantiating this interface.
Definition types.cpp:5
std::optional< std::string > getFilePath(const std::string &entity_name, const std::string &filename)
Get file path only if the file exists.
Definition files.cpp:68
bool fileExists(const std::string &entity_name, const std::string &filename) const
Check if a file exists in an entity's directory.
Definition files.cpp:184
bool removeFile(const std::string &entity_name, const std::string &filename) const
Remove a file from an entity's directory.
Definition files.cpp:159
void removeFiles(const std::string &entity_name, const std::vector< std::string > &files) const
Remove multiple files from an entity's directory.
Definition files.cpp:177
MbFilesMgr(const MantisBase &app)
Definition files.cpp:15
bool isCanonicalPath(const fs::path &path) const
Check if a path is canonical and within the files base directory.
Definition files.cpp:239
fs::path filesBaseDir() const
Get the base directory for all entity files.
Definition files.cpp:282
void renameDir(const std::string &old_entity_name, const std::string &new_entity_name) const
Rename an entity directory.
Definition files.cpp:36
std::string dirPath(const std::string &entity_name, bool create_if_missing=false) const
Get the directory path for an entity.
Definition files.cpp:117
void deleteDir(const std::string &entity_name) const
Delete an entity directory and all its contents.
Definition files.cpp:62
void createDir(const std::string &entity_name) const
Create a directory for the given entity.
Definition files.cpp:19
fs::path getCanonicalPath(const fs::path &path) const
Get canonical path and verify it's within the files base directory.
Definition files.cpp:194
std::string filePath(const std::string &entity_name, const std::string &filename) const
Get the absolute file path for an entity and filename.
Definition files.cpp:143
#define MANTISBASE_API
Definition export.h:31
The main application for mantisbase.
Definition api_keys.h:35
JSON value carried into a Duktape method without going through nlohmann::json.
Definition script_json.h:19
Collection of utility functions that are re-used across different files.