aboutsummaryrefslogtreecommitdiffstats
path: root/src/core/utils/FilesystemUtils.cpp
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2024-01-12 15:08:38 +0000
committersaturneric <[email protected]>2024-01-12 15:08:38 +0000
commit6983b5c1dd82d159236ebd06cf17f071cc9c1ee9 (patch)
treefc53f790e33546320b2ecd306a1a9ade6fbdfe7a /src/core/utils/FilesystemUtils.cpp
parentfix: slove a heap-use-after-free issue (diff)
downloadGpgFrontend-6983b5c1dd82d159236ebd06cf17f071cc9c1ee9.tar.gz
GpgFrontend-6983b5c1dd82d159236ebd06cf17f071cc9c1ee9.zip
refactor: remove boost and use QString instead of std::filesystem::path
Diffstat (limited to 'src/core/utils/FilesystemUtils.cpp')
-rw-r--r--src/core/utils/FilesystemUtils.cpp27
1 files changed, 9 insertions, 18 deletions
diff --git a/src/core/utils/FilesystemUtils.cpp b/src/core/utils/FilesystemUtils.cpp
index 0d878759..9e531955 100644
--- a/src/core/utils/FilesystemUtils.cpp
+++ b/src/core/utils/FilesystemUtils.cpp
@@ -32,36 +32,27 @@ namespace GpgFrontend {
auto GetOnlyFileNameWithPath(const QString &path) -> QString {
// Create a path object from given string
- std::filesystem::path path_obj(path.toStdString());
+ QFileInfo file_info(path);
// Check if file name in the path object has extension
- if (path_obj.has_filename()) {
+ if (!file_info.fileName().isEmpty()) {
// Fetch the extension from path object and return
- return (path_obj.parent_path() / path_obj.stem()).c_str();
+ return file_info.path() + "/" + file_info.baseName();
}
// In case of no extension return empty string
return {};
}
auto GetFileExtension(const QString &path) -> QString {
- // Create a path object from given string
- std::filesystem::path path_obj(path.toStdString());
-
- // Check if file name in the path object has extension
- if (path_obj.has_extension()) {
- // Fetch the extension from path object and return
- return path_obj.extension().c_str();
- }
- // In case of no extension return empty string
- return {};
+ return QFileInfo(path).suffix();
}
/**
* @brief
*
*/
-auto GetFileSizeByPath(const std::filesystem::path &path,
- const QString &filename_pattern) -> int64_t {
- auto dir = QDir(QString::fromStdString(path.u8string()));
+auto GetFileSizeByPath(const QString &path, const QString &filename_pattern)
+ -> int64_t {
+ auto dir = QDir(path);
QFileInfoList const file_list =
dir.entryInfoList(QStringList() << filename_pattern, QDir::Files);
qint64 total_size = 0;
@@ -98,9 +89,9 @@ auto GetHumanFriendlyFileSize(int64_t size) -> QString {
* @brief
*
*/
-void DeleteAllFilesByPattern(const std::filesystem::path &path,
+void DeleteAllFilesByPattern(const QString &path,
const QString &filename_pattern) {
- auto dir = QDir(QString::fromStdString(path.u8string()));
+ auto dir = QDir(path);
QStringList const log_files =
dir.entryList(QStringList() << filename_pattern, QDir::Files);