This forum has been archived. All content is frozen. Please use KDE Discuss instead.

KArchiveFile data fails

Tags: None
(comma "," separated)
jandalheimer
Registered Member
Posts
3
Karma
0

KArchiveFile data fails

Sat Nov 17, 2012 6:51 pm
Hello,

I have the following code:
Code: Select all
qDebug() << root->entries();
const KArchiveFile* packageFile = static_cast<const KArchiveFile*>(root->entry("package.xml"));
qDebug() << packageFile->data();


The file package.xml exists, as it is outputed by the first line, but the third line generates this error:
Code: Select all
QIODevice::read: Called with maxSize < 0
QIODevice::seek: Invalid pos: -1024
test_archive(14744) KArchiveFile::data: Failed to sync to 2048 to read "package.xml"


I've also tried packageFile->createDevice()->readAll(), but I still got the first two errors.

Any ideas?

I'm on Ubuntu 12.04 (64 bit)

Jan
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: KArchiveFile data fails

Tue Nov 20, 2012 9:31 am
Can you please post as much of your complete code as possible, and upload the archive you are trying to read somewhere so people can look into this?


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
jandalheimer
Registered Member
Posts
3
Karma
0

Re: KArchiveFile data fails

Tue Nov 20, 2012 4:01 pm
Ok, here is a very simple code that compiles and creates the errors:

KArchiveTest.pro:
Code: Select all
QT       += core
QT       -= gui

LIBS += -lkdecore

TARGET = KArchiveTest
TEMPLATE = app
SOURCES += main.cpp
main.cpp:
Code: Select all
#include <karchive.h>
#include <kfilterdev.h>
#include <ktar.h>
#include <QBuffer>
#include <QFile>
#include <QDebug>

int main(int argc, char *argv[])
{
    QFile f("test.tar.gz");
    f.open(QFile::ReadOnly);

    KArchive* archive = new KTar(KFilterDev::device(&f, "application/x-gzip"));
    archive->open(QIODevice::ReadOnly);

    const KArchiveDirectory* root = archive->directory();
    qDebug() << root->entries(); //returns test.txt

    const KArchiveFile* file = static_cast<const KArchiveFile*>(root->entry("test.txt"));

    /*
     * The following line creates these errors:
QIODevice::read: Called with maxSize < 0
QIODevice::seek: Invalid pos: -1024
unnamed app(14317) KArchiveFile::data: Failed to sync to 512 to read "test.txt"
     */
    qDebug() << file->data();

    delete file;
    delete root;
    delete archive;
}


Jan

Edit: Here is the archive I used for testing: https://www.dropbox.com/s/zoaby1ksrhdy5v5/test.tar.gz
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: KArchiveFile data fails

Sat Nov 24, 2012 9:26 pm
I can confirm this using your test suite.
I got this backtrace:
Code: Select all
#0  0x0000000000000021 in ?? ()
#1  0x00007ffff79ff117 in qDeleteAll<QHash<QString, KArchiveEntry*>::const_iterator> (end=<optimized out>, begin=<optimized out>) at /opt/trunk-kde/qt/include/QtCore/qalgorithms.h:322
#2  qDeleteAll<QHash<QString, KArchiveEntry*> > (c=...) at /opt/trunk-kde/qt/include/QtCore/qalgorithms.h:330
#3  ~KArchiveDirectoryPrivate (this=0x629b70, __in_chrg=<optimized out>) at /home/ben/kdesvn/kde/kdelibs/kdecore/io/karchive.cpp:697
#4  KArchiveDirectory::~KArchiveDirectory (this=0x629b50, __in_chrg=<optimized out>) at /home/ben/kdesvn/kde/kdelibs/kdecore/io/karchive.cpp:713
#5  0x00007ffff79ff179 in KArchiveDirectory::~KArchiveDirectory (this=0x629b50, __in_chrg=<optimized out>) at /home/ben/kdesvn/kde/kdelibs/kdecore/io/karchive.cpp:714
#6  0x00000000004015bc in main (argc=1, argv=0x7fffffffd7b8) at main.cpp:30


I'll pass this information on to the appropriate person(s) to see if they may know what the issue is.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
jandalheimer
Registered Member
Posts
3
Karma
0

Re: KArchiveFile data fails

Sun Nov 25, 2012 9:30 am
Ok, thank you!

Jan
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: KArchiveFile data fails

Wed Dec 05, 2012 8:39 am
The maintainer of the KArchive code has let me know they will look into finding a solution to this issue this week (spare time permitting).
I'll update this topic when that happens.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
dfaure
KDE Developer
Posts
14
Karma
0
OS

Sun Mar 17, 2013 9:50 am
There are two issues with this testcase:
1) Your .tar.gz file is actually not gzipped, it's a wrongly named uncompressed tar file. See "file test.tar.gz" for proof.
2) The code, on the other hand, forces the use of a KFilterDev for gunzipping as input device. This is unnecessary -- even if the input file was really gzipped -- because KTar is perfectly capable of handling real .tar.gz files as input.
3) (Yeah I can't count). Deleting "file" and "root" is wrong, these are owned by KTar.

This leads to the following working code:
Code: Select all
#include <ktar.h>
#include <QFile>
#include <QDebug>

int main(int argc, char *argv[])
{
    // QCoreApplication app(argc, argv); missing here

    QFile f("test.tar.gz");
    if (!f.open(QFile::ReadOnly)) {
        return 1;
    }

    KArchive* archive = new KTar(&f);
    archive->open(QIODevice::ReadOnly);

    const KArchiveDirectory* root = archive->directory();
    qDebug() << root->entries(); //returns test.txt

    const KArchiveFile* file = static_cast<const KArchiveFile*>(root->entry("test.txt"));
    qDebug() << file->data(); // shows "some test text\n"

    delete archive;
}



Bookmarks



Who is online

Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]