Fix archive / directory decryption move

When moving accross partitions we need to recursively
copy and then delete the original. Add path-helper funcs
for this.
GnuPG-Bug-Id: 3547
parent 96360b07
......@@ -201,8 +201,7 @@ void AutoDecryptVerifyFilesController::Private::exec()
suffix = QStringLiteral("_%1").arg(++i);
} while (i < 1000);
if (!QFile::rename(inpath, ofi.absoluteFilePath())) {
if (!moveDir(inpath, ofi.absoluteFilePath())) {
reportError(makeGnuPGError(GPG_ERR_GENERAL),
xi18n("Failed to move <filename>%1</filename> to <filename>%2</filename>.",
inpath, ofi.absoluteFilePath()));
......
......@@ -43,6 +43,7 @@
#include <QString>
#include <QStringList>
#include <QStorageInfo>
#include <QFileInfo>
#include <QDir>
......@@ -122,3 +123,51 @@ void Kleo::recursivelyRemovePath(const QString &path)
}
}
}
bool Kleo::recursivelyCopy(const QString &src,const QString &dest)
{
QDir srcDir(src);
if(!srcDir.exists()) {
return false;
}
QDir destDir(dest);
if(!destDir.exists() && !destDir.mkdir(dest)) {
return false;
}
for(const auto file: srcDir.entryList(QDir::Files)) {
const QString srcName = src + QDir::separator() + file;
const QString destName = dest + QDir::separator() + file;
if(!QFile::copy(srcName, destName)) {
return false;
}
}
for (const auto dir: srcDir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot)) {
const QString srcName = src + QDir::separator() + dir;
const QString destName = dest + QDir::separator() + dir;
if (!recursivelyCopy(srcName, destName)) {
return false;
}
}
return true;
}
bool Kleo::moveDir(const QString &src, const QString &dest)
{
if (QStorageInfo(src).device() == QStorageInfo(dest).device()) {
// Easy same partition we can use qt.
return QFile::rename(src, dest);
}
// first copy
if (!recursivelyCopy(src, dest)) {
return false;
}
// Then delete original
recursivelyRemovePath(src);
return true;
}
......@@ -45,6 +45,8 @@ QStringList makeRelativeTo(const QDir &dir, const QStringList &files);
QStringList makeRelativeTo(const QString &dir, const QStringList &files);
void recursivelyRemovePath(const QString &path);
bool recursivelyCopy(const QString &src, const QString &dest);
bool moveDir(const QString &src, const QString &dest);
}
#endif /* __KLEOPATRA_UTILS_PATH_HELPER_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment