Skip to content

Commit

Permalink
use the simple solution
Browse files Browse the repository at this point in the history
  • Loading branch information
antony-jr committed Nov 17, 2023
1 parent b1a5a6c commit c27aa2a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 51 deletions.
1 change: 0 additions & 1 deletion include/qarchiveextractor_p.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ class ExtractorPrivate : public QObject {
QString m_RawOutputFilename;
QIODevice* m_Archive = nullptr;
archive_entry* m_CurrentArchiveEntry = nullptr;
QString m_CurrentEntryOrigName;
MutableMemoryFile m_CurrentMemoryFile;
QSharedPointer<struct archive> m_ArchiveRead;
QSharedPointer<struct archive> m_ArchiveWrite;
Expand Down
1 change: 0 additions & 1 deletion include/qarchiveutils_p.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ int archiveWriteOpenQIODevice(struct archive* archive, QIODevice* device);
char* concat(const char*, const char*);
QString getDirectoryFileName(const QString&);
bool isUTF8(const char *);
QString generateRandomString(int);
#endif // QARCHIVE_UTILS_PRIVATE_HPP_INCLUDED
44 changes: 9 additions & 35 deletions src/qarchiveextractor_p.cc
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ void ExtractorPrivate::clear() {
m_Archive = nullptr;
}
m_CurrentArchiveEntry = nullptr;
m_CurrentEntryOrigName.clear();
b_QIODeviceOwned = false;
}

Expand Down Expand Up @@ -888,34 +887,19 @@ short ExtractorPrivate::writeData(struct archive_entry* entry) {
#endif
if (m_CurrentArchiveEntry != entry) {
if (!b_MemoryMode) {
// UTF-8 filename in archive gets messed up,
// we fix that by temporarily renaming the archive entry to ASCII
// random string then extract, finally rename it back to it's
// original name.

// UTF-8 in archive entry messes up when extracting under Windows
// when UTF-8 is not set, to fix this we first get the archive
// entry pathname in raw bytes then convert it to wide characters
// and set it has the new pathname which should make libarchive
// handle it better.

// Get current pathname
auto ptname_cstr = archive_entry_pathname(entry);
auto ptname = QString::fromUtf8(ptname_cstr);
auto fileInfo = QFileInfo(ptname);

// Check if UTF-8
if(ptname != QString::fromLatin1(ptname_cstr)) {
/*
m_CurrentEntryOrigName = fileInfo.fileName();
m_CurrentEntryPath = fileInfo.path();
QString randomFile;
if(!m_CurrentEntryOrigName.isEmpty()) {
QString rnd = generateRandomString(7) + ".temp";
randomFile = fileInfo.path() + QString::fromUtf8("/") + rnd;
} else {
QString rnd = generateRandomString(7);
randomFile = fileInfo.
}
auto wstr = randomFile.toStdWString();
*/

if(isUTF8(ptname_cstr)) {
auto ptname = QString::fromUtf8(ptname_cstr);

auto wstr = ptname.toStdWString();
archive_entry_copy_pathname_w(entry, wstr.c_str());
}
Expand Down Expand Up @@ -1005,16 +989,6 @@ short ExtractorPrivate::writeData(struct archive_entry* entry) {
if (ret == ARCHIVE_FATAL) {
return ArchiveHeaderWriteError;
}

// Rename back to original if renamed.
/*
if(!m_CurrentEntryOrigName.isEmpty()) {
auto tempName = QString::fromUtf8(archive_entry_pathname(entry));
auto fileInfo = QFileInfo(tempName);
QFile::rename(tempName, fileInfo.path() + "/" + m_CurrentEntryOrigName);
m_CurrentEntryOrigName.clear();
}
*/
} else {
currentNode.getBuffer()->close();
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
Expand Down
13 changes: 0 additions & 13 deletions src/qarchiveutils_p.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <QIODevice>
#include <QRandomGenerator>
#include <QString>
#include <qarchiveioreader_p.hpp>
#include <qarchiveutils_p.hpp>
Expand Down Expand Up @@ -217,15 +216,3 @@ bool isUTF8(const char *src) {
// utf8 characters
return s != latin1;
}

QString generateRandomString(int length) {
const QString possibleCharacters("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");

QString randomString;
for (int i = 0; i < length; ++i) {
int index = QRandomGenerator::global()->bounded(possibleCharacters.length());
randomString.append(possibleCharacters.at(index));
}

return randomString;
}
1 change: 0 additions & 1 deletion tests/QArchiveDiskExtractorTests.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <QArchiveDiskExtractorTests.hpp>
#include <unistd.h>

void QArchiveDiskExtractorTests::initTestCase() {
QDir cases(TestCasesDir);
Expand Down

0 comments on commit c27aa2a

Please sign in to comment.