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

0001 /* This file is part of the KDE libraries
0002    SPDX-FileCopyrightText: 2002 Laurence Anderson <l.d.anderson@warwick.ac.uk>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 #ifndef KAR_H
0007 #define KAR_H
0008 
0009 #include <karchive.h>
0010 
0011 /**
0012  * @class KAr kar.h KAr
0013  *
0014  * KAr is a class for reading archives in ar format. Writing
0015  * is not supported. Reading archives that contain files bigger than
0016  * INT_MAX - 32 bytes is not supported.
0017  * @short A class for reading ar archives.
0018  * @author Laurence Anderson <l.d.anderson@warwick.ac.uk>
0019  */
0020 class KARCHIVE_EXPORT KAr : public KArchive
0021 {
0022     Q_DECLARE_TR_FUNCTIONS(KAr)
0023 
0024 public:
0025     /**
0026      * Creates an instance that operates on the given filename.
0027      *
0028      * @param filename is a local path (e.g. "/home/holger/myfile.ar")
0029      */
0030     explicit KAr(const QString &filename);
0031 
0032     /**
0033      * Creates an instance that operates on the given device.
0034      * The device can be compressed (KCompressionDevice) or not (QFile, etc.).
0035      * @param dev the device to read from
0036      */
0037     explicit KAr(QIODevice *dev);
0038 
0039     /**
0040      * If the ar file is still opened, then it will be
0041      * closed automatically by the destructor.
0042      */
0043     ~KAr() override;
0044 
0045 protected:
0046     /*
0047      * Writing is not supported by this class, will always fail.
0048      * @return always false
0049      */
0050     bool doPrepareWriting(const QString &name,
0051                           const QString &user,
0052                           const QString &group,
0053                           qint64 size,
0054                           mode_t perm,
0055                           const QDateTime &atime,
0056                           const QDateTime &mtime,
0057                           const QDateTime &ctime) override;
0058 
0059     /*
0060      * Writing is not supported by this class, will always fail.
0061      * @return always false
0062      */
0063     bool doFinishWriting(qint64 size) override;
0064 
0065     /*
0066      * Writing is not supported by this class, will always fail.
0067      * @return always false
0068      */
0069     bool doWriteDir(const QString &name,
0070                     const QString &user,
0071                     const QString &group,
0072                     mode_t perm,
0073                     const QDateTime &atime,
0074                     const QDateTime &mtime,
0075                     const QDateTime &ctime) override;
0076 
0077     bool doWriteSymLink(const QString &name,
0078                         const QString &target,
0079                         const QString &user,
0080                         const QString &group,
0081                         mode_t perm,
0082                         const QDateTime &atime,
0083                         const QDateTime &mtime,
0084                         const QDateTime &ctime) override;
0085 
0086     /**
0087      * Opens the archive for reading.
0088      * Parses the directory listing of the archive
0089      * and creates the KArchiveDirectory/KArchiveFile entries.
0090      *
0091      */
0092     bool openArchive(QIODevice::OpenMode mode) override;
0093     bool closeArchive() override;
0094 
0095 protected:
0096     void virtual_hook(int id, void *data) override;
0097 
0098 private:
0099     class KArPrivate;
0100     KArPrivate *const d;
0101 };
0102 
0103 #endif