summaryrefslogtreecommitdiffstats
path: root/sinksh
diff options
context:
space:
mode:
Diffstat (limited to 'sinksh')
-rw-r--r--sinksh/CMakeLists.txt1
-rw-r--r--sinksh/syntax_modules/sink_drop.cpp70
2 files changed, 71 insertions, 0 deletions
diff --git a/sinksh/CMakeLists.txt b/sinksh/CMakeLists.txt
index 9a4c948..82839ab 100644
--- a/sinksh/CMakeLists.txt
+++ b/sinksh/CMakeLists.txt
@@ -17,6 +17,7 @@ set(sink_cli_SRCS
17 syntax_modules/sink_show.cpp 17 syntax_modules/sink_show.cpp
18 syntax_modules/sink_trace.cpp 18 syntax_modules/sink_trace.cpp
19 syntax_modules/sink_inspect.cpp 19 syntax_modules/sink_inspect.cpp
20 syntax_modules/sink_drop.cpp
20 sinksh_utils.cpp 21 sinksh_utils.cpp
21 repl/repl.cpp 22 repl/repl.cpp
22 repl/replStates.cpp 23 repl/replStates.cpp
diff --git a/sinksh/syntax_modules/sink_drop.cpp b/sinksh/syntax_modules/sink_drop.cpp
new file mode 100644
index 0000000..ce468de
--- /dev/null
+++ b/sinksh/syntax_modules/sink_drop.cpp
@@ -0,0 +1,70 @@
1/*
2 * Copyright (C) 2014 Aaron Seigo <aseigo@kde.org>
3 * Copyright (C) 2016 Christian Mollekopf <mollekopf@kolabsys.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the
17 * Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#include <QCoreApplication>
22#include <QDebug>
23#include <QObject> // tr()
24#include <QDir>
25#include <QDirIterator>
26
27#include "common/log.h"
28#include "common/storage.h"
29#include "common/definitions.h"
30
31#include "sinksh_utils.h"
32#include "state.h"
33#include "syntaxtree.h"
34
35namespace SinkDrop
36{
37
38bool drop(const QStringList &args, State &state)
39{
40 if (args.isEmpty()) {
41 state.printError(QObject::tr("Please provide at least one resource to drop."));
42 return false;
43 }
44
45 auto argList = args;
46 auto resource = argList.takeFirst();
47
48 QDirIterator it(Sink::storageLocation(), QStringList() << resource + "*", QDir::Dirs);
49 while (it.hasNext()) {
50 auto path = it.next();
51 QDir dir(path);
52 state.printLine("Removing: " + path, 1);
53 if (!dir.removeRecursively()) {
54 state.printError(QObject::tr("Failed to remove: ") + dir.path());
55 }
56 }
57
58 return false;
59}
60
61Syntax::List syntax()
62{
63 Syntax drop("drop", QObject::tr("Drop all caches of a resource."), &SinkDrop::drop, Syntax::NotInteractive);
64 drop.completer = &SinkshUtils::resourceOrTypeCompleter;
65 return Syntax::List() << drop;
66}
67
68REGISTER_SYNTAX(SinkDrop)
69
70}