File: tarziparchive.cpp

package info (click to toggle)
qflipper 1.3.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 12,320 kB
  • sloc: cpp: 18,500; sh: 247; ansic: 191; xml: 38; python: 14; makefile: 5
file content (81 lines) | stat: -rw-r--r-- 2,507 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "tarziparchive.h"

#include <QDir>
#include <QFile>

#include "tararchive.h"
#include "gzipcompressor.h"
#include "gzipuncompressor.h"
#include "tempdirectories.h"

TarZipArchive::TarZipArchive(QFile *inputFile, QObject *parent):
    QObject(parent),
    m_tarArchive(nullptr)
{
    const QFileInfo tzFileInfo(*inputFile);
    const auto tzFileDir = tzFileInfo.absoluteDir();
    const auto fileName = tzFileInfo.baseName() + QStringLiteral(".tar");

    m_tarFile = new QFile(tzFileDir.absoluteFilePath(fileName), this);

    auto *uncompressor = new GZipUncompressor(inputFile, m_tarFile, this);

    if(uncompressor->isError()) {
        setError(uncompressor->error(), QStringLiteral("Failed to uncompress *tar.gz file: %1").arg(uncompressor->errorString()));
        return;
    }

    connect(uncompressor, &GZipUncompressor::finished, this, [=]() {
        if(uncompressor->isError()) {
            setError(uncompressor->error(), QStringLiteral("Failed to uncompress *tar.gz file: %1").arg(uncompressor->errorString()));

        } else {
            m_tarArchive = new TarArchive(m_tarFile, this);

            if(m_tarArchive->isError()) {
                setError(m_tarArchive->error(), QStringLiteral("Failed to build archive index: %1").arg(m_tarArchive->errorString()));
            }
        }

        emit ready();
    });
}

TarZipArchive::TarZipArchive(const QDir &inputDir, QFile *outputFile, QObject *parent):
    QObject(parent),
    m_tarFile(globalTempDirs->createTempFile(this)),
    m_tarArchive(new TarArchive(inputDir, m_tarFile, this))
{
    if(m_tarArchive->isError()) {
        setError(m_tarArchive->error(), m_tarArchive->errorString());
        return;
    }

    connect(m_tarArchive, &TarArchive::ready, this, [=]() {
        auto *compressor = new GZipCompressor(m_tarFile, outputFile, this);

        if(compressor->isError()) {
            setError(compressor->error(), QStringLiteral("Failed to compress *tar.gz file: %1").arg(compressor->errorString()));
            emit ready();
            return;
        }

        connect(compressor, &GZipCompressor::finished, this, [=]() {
            if(compressor->isError()) {
                setError(compressor->error(), QStringLiteral("Failed to compress *tar.gz file: %1").arg(compressor->errorString()));
            }

            emit ready();
        });
    });
}

TarZipArchive::~TarZipArchive()
{
    m_tarFile->remove();
}

TarArchive *TarZipArchive::archiveIndex() const
{
    return m_tarArchive;
}