Moved emptyDirectory() into dbcorelib
This commit is contained in:
@@ -9,4 +9,4 @@ set(SOURCES
|
|||||||
|
|
||||||
add_executable(picsync ${HEADERS} ${SOURCES})
|
add_executable(picsync ${HEADERS} ${SOURCES})
|
||||||
|
|
||||||
target_link_libraries(picsync Qt5::Core)
|
target_link_libraries(picsync Qt5::Core dbcorelib)
|
||||||
|
42
main.cpp
42
main.cpp
@@ -11,11 +11,12 @@
|
|||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QCommandLineParser>
|
#include <QCommandLineParser>
|
||||||
#include <QCommandLineOption>
|
#include <QCommandLineOption>
|
||||||
#include <QDirIterator>
|
|
||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
|
||||||
|
#include "utils/fileutils.h"
|
||||||
|
|
||||||
bool writeBitmap(const QString &filename, const QByteArray &content)
|
bool writeBitmap(const QString &filename, const QByteArray &content)
|
||||||
{
|
{
|
||||||
qDebug() << "writeBitmap" << filename;
|
qDebug() << "writeBitmap" << filename;
|
||||||
@@ -131,45 +132,6 @@ bool readBitmap(const QString &filename, QByteArray &content)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool emptyDirectory(const QString &path)
|
|
||||||
{
|
|
||||||
QDir dir(path);
|
|
||||||
|
|
||||||
if(!dir.exists())
|
|
||||||
{
|
|
||||||
qWarning() << "tried to empty non-existant dir" << path;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool success = true;
|
|
||||||
// not empty -- we must empty it first
|
|
||||||
QDirIterator di(dir.absolutePath(), QDir::AllEntries | QDir::Hidden | QDir::System | QDir::NoDotAndDotDot);
|
|
||||||
while (di.hasNext()) {
|
|
||||||
di.next();
|
|
||||||
const QFileInfo& fi = di.fileInfo();
|
|
||||||
const QString &filePath = di.filePath();
|
|
||||||
bool ok;
|
|
||||||
if (fi.isDir() && !fi.isSymLink()) {
|
|
||||||
ok = QDir(filePath).removeRecursively(); // recursive
|
|
||||||
} else {
|
|
||||||
ok = QFile::remove(filePath);
|
|
||||||
if (!ok) { // Read-only files prevent directory deletion on Windows, retry with Write permission.
|
|
||||||
const QFile::Permissions permissions = QFile::permissions(filePath);
|
|
||||||
if (!(permissions & QFile::WriteUser))
|
|
||||||
ok = QFile::setPermissions(filePath, permissions | QFile::WriteUser)
|
|
||||||
&& QFile::remove(filePath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!ok)
|
|
||||||
success = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!success)
|
|
||||||
qWarning() << "could not empty" << path;
|
|
||||||
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool spread(const QString &sourcePath, const QString &targetPath)
|
bool spread(const QString &sourcePath, const QString &targetPath)
|
||||||
{
|
{
|
||||||
qDebug() << "spread" << sourcePath << targetPath;
|
qDebug() << "spread" << sourcePath << targetPath;
|
||||||
|
Reference in New Issue
Block a user