summaryrefslogtreecommitdiffstats
path: root/sinksh/syntax_modules
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-02-13 22:13:05 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-02-13 22:13:05 +0100
commit1f799ce1800c685937718a94adf476698da00bc2 (patch)
tree4c5cb1d5c88406c305c2057c06af6409ff576616 /sinksh/syntax_modules
parenta5ade5c9a485183bbd9e0d90088bee1b93ad4eb5 (diff)
downloadsink-1f799ce1800c685937718a94adf476698da00bc2.tar.gz
sink-1f799ce1800c685937718a94adf476698da00bc2.zip
sinksh drop to drop the cache
Diffstat (limited to 'sinksh/syntax_modules')
-rw-r--r--sinksh/syntax_modules/sink_drop.cpp70
1 files changed, 70 insertions, 0 deletions
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}