summaryrefslogtreecommitdiffstats
path: root/examples/maildirresource/tests/utils.h
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-09-20 17:18:21 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-09-20 17:18:21 +0200
commitebc5c48c03b6145e604da7c313b35321d0a71142 (patch)
tree1cee00a9fa4faa4995c0a50f01703ac5672c8797 /examples/maildirresource/tests/utils.h
parent4a14a6fade947aa830d3f21598a4a6ba7316b933 (diff)
downloadsink-ebc5c48c03b6145e604da7c313b35321d0a71142.tar.gz
sink-ebc5c48c03b6145e604da7c313b35321d0a71142.zip
A first draft of the threading algorithm.
Diffstat (limited to 'examples/maildirresource/tests/utils.h')
-rw-r--r--examples/maildirresource/tests/utils.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/examples/maildirresource/tests/utils.h b/examples/maildirresource/tests/utils.h
new file mode 100644
index 0000000..6e25353
--- /dev/null
+++ b/examples/maildirresource/tests/utils.h
@@ -0,0 +1,50 @@
1/*
2 * Copyright (C) 2016 Christian Mollekopf <chrigi_1@fastmail.fm>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19#pragma once
20
21#include <QFileInfo>
22#include <QDir>
23#include <QDebug>
24
25static bool copyRecursively(const QString &srcFilePath, const QString &tgtFilePath)
26{
27 QFileInfo srcFileInfo(srcFilePath);
28 if (srcFileInfo.isDir()) {
29 QDir targetDir(tgtFilePath);
30 targetDir.cdUp();
31 if (!targetDir.mkdir(QFileInfo(srcFilePath).fileName())) {
32 qWarning() << "Failed to create directory " << tgtFilePath;
33 return false;
34 }
35 QDir sourceDir(srcFilePath);
36 QStringList fileNames = sourceDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System);
37 foreach (const QString &fileName, fileNames) {
38 const QString newSrcFilePath = srcFilePath + QLatin1Char('/') + fileName;
39 const QString newTgtFilePath = tgtFilePath + QLatin1Char('/') + fileName;
40 if (!copyRecursively(newSrcFilePath, newTgtFilePath))
41 return false;
42 }
43 } else {
44 if (!QFile::copy(srcFilePath, tgtFilePath)) {
45 qWarning() << "Failed to copy file " << tgtFilePath;
46 return false;
47 }
48 }
49 return true;
50}