1 /* This file is part of the KDE project
2 SPDX-FileCopyrightText: 2002-2019 David Faure <faure@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7 #include "kar.h"
8
9 #include <QDebug>
10
11 #include <stdio.h>
12
recursive_print(const KArchiveDirectory * dir,const QString & path)13 void recursive_print(const KArchiveDirectory *dir, const QString &path)
14 {
15 QStringList l = dir->entries();
16 l.sort();
17 QStringList::ConstIterator it = l.constBegin();
18 for (; it != l.constEnd(); ++it) {
19 const KArchiveEntry *entry = dir->entry((*it));
20 printf("mode=%7o path=%s type=%s size=%lld\n",
21 entry->permissions(),
22 qPrintable(path + (*it)),
23 entry->isFile() ? "file" : "dir",
24 entry->isFile() ? static_cast<const KArchiveFile *>(entry)->size() : 0);
25 if (!entry->symLinkTarget().isEmpty()) {
26 printf(" (symlink to %s)\n", qPrintable(entry->symLinkTarget()));
27 }
28 if (entry->isDirectory()) {
29 recursive_print((KArchiveDirectory *)entry, path + (*it) + '/');
30 }
31 }
32 }
33
34 // See karchivetest.cpp for the unittest that covers KAr.
35
main(int argc,char ** argv)36 int main(int argc, char **argv)
37 {
38 if (argc != 2) {
39 printf(
40 "\n"
41 " Usage :\n"
42 " ./kartest /path/to/existing_file.a tests listing an existing archive\n");
43 return 1;
44 }
45
46 KAr archive(argv[1]);
47
48 if (!archive.open(QIODevice::ReadOnly)) {
49 printf("Could not open %s for reading\n", argv[1]);
50 return 1;
51 }
52
53 const KArchiveDirectory *dir = archive.directory();
54
55 // printf("calling recursive_print\n");
56 recursive_print(dir, QLatin1String(""));
57 // printf("recursive_print called\n");
58
59 archive.close();
60
61 return 0;
62 }
63