File indexing completed on 2024-06-16 05:01:12
0001 /* 0002 * Copyright (C) 2014 Aaron Seigo <aseigo@kde.org> 0003 * Copyright (C) 2016 Christian Mollekopf <mollekopf@kolabsys.com> 0004 * 0005 * This program is free software; you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation; either version 2 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with this program; if not, write to the 0017 * Free Software Foundation, Inc., 0018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 0019 */ 0020 0021 #include <QCoreApplication> 0022 #include <QDebug> 0023 #include <QObject> // tr() 0024 #include <QDir> 0025 #include <QDirIterator> 0026 0027 #include "common/log.h" 0028 #include "common/storage.h" 0029 #include "common/definitions.h" 0030 0031 #include "sinksh_utils.h" 0032 #include "state.h" 0033 #include "syntaxtree.h" 0034 0035 namespace SinkDrop 0036 { 0037 0038 Syntax::List syntax(); 0039 0040 bool drop(const QStringList &args, State &state) 0041 { 0042 if (args.isEmpty()) { 0043 state.printError(syntax()[0].usage()); 0044 return false; 0045 } 0046 0047 auto argList = args; 0048 auto resource = argList.takeFirst(); 0049 QDirIterator it(Sink::storageLocation(), QStringList() << SinkshUtils::parseUid(resource.toLatin1()) + "*", QDir::Dirs); 0050 while (it.hasNext()) { 0051 auto path = it.next(); 0052 QDir dir(path); 0053 state.printLine("Removing: " + path, 1); 0054 if (!dir.removeRecursively()) { 0055 state.printError(QObject::tr("Failed to remove: ") + dir.path()); 0056 } 0057 } 0058 0059 return false; 0060 } 0061 0062 Syntax::List syntax() 0063 { 0064 Syntax drop("drop", QObject::tr("Drop all caches of a resource."), &SinkDrop::drop, Syntax::NotInteractive); 0065 drop.addPositionalArgument({"resource", "Id(s) of the resource(s) to drop", true, true}); 0066 0067 drop.completer = &SinkshUtils::resourceOrTypeCompleter; 0068 return Syntax::List() << drop; 0069 } 0070 0071 REGISTER_SYNTAX(SinkDrop) 0072 0073 }