File indexing completed on 2024-04-21 03:52:34

0001 /*
0002  *  SPDX-FileCopyrightText: 2002-2014 David Faure <faure@kde.org>
0003  *
0004  *  SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #include "krcc.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=%07o %s %s %s%s %lld isdir=%d\n",
0021                entry->permissions(),
0022                entry->user().toLatin1().constData(),
0023                entry->group().toLatin1().constData(),
0024                path.toLatin1().constData(),
0025                (*it).toLatin1().constData(),
0026                entry->isFile() ? static_cast<const KArchiveFile *>(entry)->size() : 0,
0027                entry->isDirectory());
0028         if (!entry->symLinkTarget().isEmpty()) {
0029             printf("  (symlink to %s)\n", qPrintable(entry->symLinkTarget()));
0030         }
0031         if (entry->isDirectory()) {
0032             recursive_print((KArchiveDirectory *)entry, path + (*it) + '/');
0033         }
0034     }
0035 }
0036 
0037 // See karchivetest.cpp for the unittest that covers KTar.
0038 
0039 int main(int argc, char **argv)
0040 {
0041     if (argc != 2) {
0042         printf(
0043             "\n"
0044             " Usage :\n"
0045             " ./ktartest /path/to/existing_file.tar.gz       tests listing an existing tar.gz\n");
0046         return 1;
0047     }
0048 
0049     KRcc rcc(argv[1]);
0050 
0051     if (!rcc.open(QIODevice::ReadOnly)) {
0052         printf("Could not open %s for reading\n", argv[1]);
0053         return 1;
0054     }
0055 
0056     const KArchiveDirectory *dir = rcc.directory();
0057 
0058     // printf("calling recursive_print\n");
0059     recursive_print(dir, QLatin1String(""));
0060     // printf("recursive_print called\n");
0061 
0062     rcc.close();
0063 
0064     return 0;
0065 }