From 1af590f88a92a8f4b737afcd1d3024b87283e28b Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Sun, 5 Oct 2014 23:51:39 -0500 Subject: [PATCH] Support writing empty directories to ZIP files. (cherry picked from commit ddbe23e90d6684548fe9a952b01b3d6cbaf60a7c) --- kio/kio/kzip.cpp | 15 +++++++++++++++ kio/kio/kzip.h | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/kio/kio/kzip.cpp b/kio/kio/kzip.cpp index a0bad4492..4a3a46ab5 100644 --- a/kio/kio/kzip.cpp +++ b/kio/kio/kzip.cpp @@ -1051,6 +1051,21 @@ bool KZip::closeArchive() return true; } +bool KZip::writeDir(const TQString& name, const TQString& user, const TQString& group) +{ + // Zip files have no explicit directories, they are implicitly created during extraction time + // when file entries have paths in them. + // However, to support empty directories, we must create a dummy file entry which ends with '/'. + TQString dirName = name; + if (!name.endsWith("/")) { + dirName = dirName.append('/'); + } + + mode_t perm = 040755; + time_t the_time = time(0); + return writeFile(dirName, user, group, 0, perm, the_time, the_time, the_time, 0); +} + // Doesn't need to be reimplemented anymore. Remove for KDE-4.0 bool KZip::writeFile( const TQString& name, const TQString& user, const TQString& group, uint size, const char* data ) { diff --git a/kio/kio/kzip.h b/kio/kio/kzip.h index 26bfc71d3..30311f65d 100644 --- a/kio/kio/kzip.h +++ b/kio/kio/kzip.h @@ -194,7 +194,7 @@ protected: /** * @internal Not needed for zip */ - virtual bool writeDir( const TQString& name, const TQString& user, const TQString& group) { Q_UNUSED(name); Q_UNUSED(user); Q_UNUSED(group); return true; } + virtual bool writeDir( const TQString& name, const TQString& user, const TQString& group); // TODO(BIC) uncomment and make virtual for KDE 4. // bool writeDir( const TQString& name, const TQString& user, const TQString& group, // mode_t perm, time_t atime, time_t mtime, time_t ctime );