summaryrefslogtreecommitdiffstats
path: root/tests/manual/filetest/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/manual/filetest/main.cpp')
-rw-r--r--tests/manual/filetest/main.cpp62
1 files changed, 28 insertions, 34 deletions
diff --git a/tests/manual/filetest/main.cpp b/tests/manual/filetest/main.cpp
index 7a19599858..d30b6c62c2 100644
--- a/tests/manual/filetest/main.cpp
+++ b/tests/manual/filetest/main.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2021 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QDateTime>
#include <QDebug>
@@ -41,12 +16,14 @@ static const char usage1[] =
"Usage: ";
static const char usage2[] =" [KEYWORD] [ARGUMENTS]\n\n"
"Keywords: ls FILES list file information\n"
+" find FILES list file information recursively\n"
" stat FILES print detailed file information\n"
" mv SOURCE TARGET rename files using QFile::rename\n"
" cp SOURCE TARGET copy files using QFile::copy\n"
" rm FILE remove file using QFile::remove\n"
" rmr DIR remove directory recursively\n"
-" using QDir::removeRecursively\n";
+" using QDir::removeRecursively\n"
+" trash FILES moves the file or directory to trash\n";
std::ostream &operator<<(std::ostream &o, const QString &str)
{
@@ -94,7 +71,7 @@ static inline std::string permissions(const QFileInfo &fi)
return result;
}
-static int ls(int argCount, const char **args, bool recursive = false)
+static int ls(int argCount, const char **args, int depth = 0, int maxDepth = 1)
{
for (int i = 0 ; i < argCount; ++i) {
const QFileInfo fi(QString::fromLocal8Bit(args[i]));
@@ -113,13 +90,13 @@ static int ls(int argCount, const char **args, bool recursive = false)
std::cout << std::endl;
- if (recursive && fi.isDir()) {
- QDir dir(fi.fileName());
+ if (depth < maxDepth && fi.isDir()) {
+ QDir dir(fi.absoluteFilePath());
const QStringList entries = dir.entryList(QDir::AllEntries | QDir::NoDotAndDotDot);
for (const QString &s : entries) {
- QByteArray encoded = QFile::encodeName(s);
+ QByteArray encoded = QFile::encodeName(dir.filePath(s));
const char *ptr = encoded.constData();
- ls(1, &ptr, false);
+ ls(1, &ptr, depth + 1, maxDepth);
}
}
}
@@ -205,12 +182,26 @@ static int rmr(const char *dirName)
return 0;
}
+static int trash(const char *filename)
+{
+ QFile f(QString::fromLocal8Bit(filename));
+ if (!f.moveToTrash()) {
+ qWarning().nospace() << "Failed to trash " << f.fileName()
+ << ": " << f.errorString();
+ return -1;
+ }
+ return 0;
+}
+
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Q_UNUSED(a);
if (argc >= 3 && !qstrcmp(argv[1], "ls"))
- return ls(argc -2, const_cast<const char **>(argv + 2), true);
+ return ls(argc -2, const_cast<const char **>(argv + 2));
+
+ if (argc >= 3 && !qstrcmp(argv[1], "find"))
+ return ls(argc -2, const_cast<const char **>(argv + 2), 0, std::numeric_limits<int>::max());
if (argc >= 3 && !qstrcmp(argv[1], "stat"))
return stat(argc -2, argv + 2);
@@ -227,6 +218,9 @@ int main(int argc, char *argv[])
if (argc == 3 && !qstrcmp(argv[1], "rmr"))
return rmr(argv[2]);
+ if (argc == 3 && !qstrcmp(argv[1], "trash"))
+ return trash(argv[2]);
+
std::cerr << usage1 << argv[0] << usage2;
return 0;
}