Skip to content

Commit f834eec

Browse files
Add mkDir rmDir utils
1 parent 76a1be2 commit f834eec

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

src/qt/utils.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,27 @@ bool fileExists(QString path) {
3838
return check_file.exists() && check_file.isFile();
3939
}
4040

41+
void rmDir(QString dirName) {
42+
QDir dir;
43+
QDir statsDir(dirName);
44+
45+
if (dir.exists(dirName)) {
46+
statsDir.removeRecursively();
47+
}
48+
}
49+
50+
void mkDir(QString dirName, bool setPermissions) {
51+
QDir dir;
52+
53+
if (dir.exists(dirName) || !dir.mkdir(dirName) || !setPermissions) return;
54+
55+
if (QFile::setPermissions(dirName, QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner)) {
56+
qDebug() << "Directory created successfully with 700 permissions.";
57+
} else {
58+
qDebug() << "Failed to set permissions.";
59+
}
60+
}
61+
4162
QByteArray fileGetContents(QString path)
4263
{
4364
QFile file(path);

src/qt/utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ QByteArray fileGetContents(QString path);
3838
QByteArray fileOpen(QString path);
3939
bool fileWrite(QString path, QString data);
4040
QString getAccountName();
41+
void mkDir(QString path, bool setPermissions = false);
42+
void rmDir(QString path);
4143
#ifdef Q_OS_LINUX
4244
QString xdgMime();
4345
void registerXdgMime();

0 commit comments

Comments
 (0)