diff --git a/kutils/karchive/karchive.cpp b/kutils/karchive/karchive.cpp index a1f74fac..16c5cab8 100644 --- a/kutils/karchive/karchive.cpp +++ b/kutils/karchive/karchive.cpp @@ -190,6 +190,7 @@ public: QString m_error; QByteArray m_readpass; QByteArray m_writepass; + QString m_tempprefix; #if defined(HAVE_LIBARCHIVE) struct archive* openRead(const QByteArray &path); @@ -200,6 +201,8 @@ public: bool copyData(struct archive* readarchive, struct archive* writearchive); bool copyData(struct archive* readarchive, QByteArray *buffer); + + QString tempFilePath() const; #endif }; @@ -403,6 +406,15 @@ bool KArchivePrivate::copyData(struct archive* readarchive, QByteArray *buffer) return true; } + +QString KArchivePrivate::tempFilePath() const +{ + QFileInfo fileinfo(m_path); + QString tmptemplate = m_tempprefix; + tmptemplate.append(QLatin1String("XXXXXXXXXX.")); + tmptemplate.append(fileinfo.completeSuffix()); + return KTemporaryFile::filePath(tmptemplate); +} #endif // HAVE_LIBARCHIVE KArchive::KArchive(const QString &path, QObject *parent) @@ -467,9 +479,7 @@ bool KArchive::add(const QStringList &paths, const QByteArray &strip, const QByt return result; } - QFileInfo fileinfo(d->m_path); - const QString tmptemplate = QString::fromLatin1("XXXXXXXXXX.%1").arg(fileinfo.completeSuffix()); - const QString tmpfile = KTemporaryFile::filePath(tmptemplate); + const QString tmpfile = d->tempFilePath(); struct archive* writearchive = d->openWrite(QFile::encodeName(tmpfile)); if (!writearchive) { @@ -718,9 +728,7 @@ bool KArchive::remove(const QStringList &paths) const return result; } - QFileInfo fileinfo(d->m_path); - const QString tmptemplate = QString::fromLatin1("XXXXXXXXXX.%1").arg(fileinfo.completeSuffix()); - const QString tmpfile = KTemporaryFile::filePath(tmptemplate); + const QString tmpfile = d->tempFilePath(); struct archive* writearchive = d->openWrite(QFile::encodeName(tmpfile)); if (!writearchive) { @@ -1137,14 +1145,12 @@ bool KArchive::requiresPassphrase() const { bool result = false; -#if defined(HAVE_LIBARCHIVE) foreach (const KArchiveEntry &karchiveentry, KArchive::list()) { if (karchiveentry.encrypted == true) { result = true; break; } } -#endif return result; } @@ -1159,6 +1165,16 @@ void KArchive::setWritePassphrase(const QString &passphrase) d->m_writepass = passphrase.toUtf8(); } +QString KArchive::tempPrefix() const +{ + return d->m_tempprefix; +} + +void KArchive::setTempPrefix(const QString &prefix) +{ + d->m_tempprefix = prefix; +} + QString KArchive::errorString() const { return d->m_error; diff --git a/kutils/karchive/karchive.h b/kutils/karchive/karchive.h index f6099b9d..28900665 100644 --- a/kutils/karchive/karchive.h +++ b/kutils/karchive/karchive.h @@ -152,6 +152,16 @@ public: //! @brief Sets the passphrase to be used when writing archive void setWritePassphrase(const QString &passphrase); + /*! + @brief Returns if temporary file path prefix, may be empty + @note The default (which is empty) means the temporary file will be placed in /tmp + (usually), if large files are compressed and there is not enough space write error may + occurr + */ + QString tempPrefix() const; + //! @brief Sets the temporary file path prefix to @p prefix + void setTempPrefix(const QString &prefix); + //! @brief Returns human-readable description of the error that occured QString errorString() const;