File indexing completed on 2024-04-14 03:50:30

0001 /* This file is part of the KDE project
0002    SPDX-FileCopyrightText: 2002-2019 David Faure <faure@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "kar.h"
0008 
0009 #include <QDebug>
0010 
0011 #include <stdio.h>
0012 
0013 void recursive_print(const KArchiveDirectory *dir, const QString &path)
0014 {
0015     QStringList l = dir->entries();
0016     l.sort();
0017     QStringList::ConstIterator it = l.constBegin();
0018     for (; it != l.constEnd(); ++it) {
0019         const KArchiveEntry *entry = dir->entry((*it));
0020         printf("mode=%7o path=%s type=%s size=%lld\n",
0021                entry->permissions(),
0022                qPrintable(path + (*it)),
0023                entry->isFile() ? "file" : "dir",
0024                entry->isFile() ? static_cast<const KArchiveFile *>(entry)->size() : 0);
0025         if (!entry->symLinkTarget().isEmpty()) {
0026             printf("  (symlink to %s)\n", qPrintable(entry->symLinkTarget()));
0027         }
0028         if (entry->isDirectory()) {
0029             recursive_print((KArchiveDirectory *)entry, path + (*it) + '/');
0030         }
0031     }
0032 }
0033 
0034 // See karchivetest.cpp for the unittest that covers KAr.
0035 
0036 int main(int argc, char **argv)
0037 {
0038     if (argc != 2) {
0039         printf(
0040             "\n"
0041             " Usage :\n"
0042             " ./kartest /path/to/existing_file.a       tests listing an existing archive\n");
0043         return 1;
0044     }
0045 
0046     KAr archive(argv[1]);
0047 
0048     if (!archive.open(QIODevice::ReadOnly)) {
0049         printf("Could not open %s for reading\n", argv[1]);
0050         return 1;
0051     }
0052 
0053     const KArchiveDirectory *dir = archive.directory();
0054 
0055     // printf("calling recursive_print\n");
0056     recursive_print(dir, QLatin1String(""));
0057     // printf("recursive_print called\n");
0058 
0059     archive.close();
0060 
0061     return 0;
0062 }