<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en_US" xml:lang="en_US"> <head> <title>kio/kio: karchive.cpp Source File (kio/kio)</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <meta http-equiv="pics-label" content='(pics-1.1 "http://www.icra.org/ratingsv02.html" comment "ICRAonline DE v2.0" l gen true for "http://www.kde.org" r (nz 1 vz 1 lz 1 oz 1 cb 1) "http://www.rsac.org/ratingsv01.html" l gen true for "http://www.kde.org" r (n 0 s 0 v 0 l 0))' /> <meta name="trademark" content="KDE e.V." /> <meta name="description" content="K Desktop Environment Homepage, KDE.org" /> <meta name="MSSmartTagsPreventParsing" content="true" /> <meta name="robots" content="all" /> <link rel="shortcut icon" href="../../../favicon.ico" /> <link rel="stylesheet" media="screen" type="text/css" title="APIDOX" href="doxygen.css" /> </head> <body> <div id="nav_header_top" align="right"> <a href="#content" class="doNotDisplay" accesskey="2">Skip to main content ::</a> <a href="../../.."><img id="nav_header_logo" alt="Home" align="left" src="../../../kde_gear_64.png" border="0" /></a> <span class="doNotDisplay">::</span> <div id="nav_header_title" align="left">KDE API Reference</div> </div> <div id="nav_header_bottom" align="right"> <span class="doNotDisplay">:: <a href="#navigation" accesskey="5">Skip to Link Menu</a><br/></span> <div id="nav_header_bottom_right" style="text-align: left;"> / <a href="../../..">API Reference</a> / <a href="../../html/index.html">kio</a> / <a href=".">kio</a> </div> </div> <table id="main" border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td valign="top" class="menuheader" height="0"></td> <td id="contentcolumn" valign="top" rowspan="2" > <div id="content" style="padding-top: 0px;"><div style="width:100%; margin: 0px; padding: 0px;"> <a name="content"></a> <!-- Generated by Doxygen 1.7.4 --> <div class="header"> <div class="headertitle"> <div class="title">karchive.cpp</div> </div> </div> <div class="contents"> <div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* This file is part of the KDE libraries</span> <a name="l00002"></a>00002 <span class="comment"> Copyright (C) 2000 David Faure <faure@kde.org></span> <a name="l00003"></a>00003 <span class="comment"> Copyright (C) 2003 Leo Savernik <l.savernik@aon.at></span> <a name="l00004"></a>00004 <span class="comment"></span> <a name="l00005"></a>00005 <span class="comment"> Moved from ktar.cpp by Roberto Teixeira <maragato@kde.org></span> <a name="l00006"></a>00006 <span class="comment"></span> <a name="l00007"></a>00007 <span class="comment"> This library is free software; you can redistribute it and/or</span> <a name="l00008"></a>00008 <span class="comment"> modify it under the terms of the GNU Library General Public</span> <a name="l00009"></a>00009 <span class="comment"> License version 2 as published by the Free Software Foundation.</span> <a name="l00010"></a>00010 <span class="comment"></span> <a name="l00011"></a>00011 <span class="comment"> This library is distributed in the hope that it will be useful,</span> <a name="l00012"></a>00012 <span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span> <a name="l00013"></a>00013 <span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span> <a name="l00014"></a>00014 <span class="comment"> Library General Public License for more details.</span> <a name="l00015"></a>00015 <span class="comment"></span> <a name="l00016"></a>00016 <span class="comment"> You should have received a copy of the GNU Library General Public License</span> <a name="l00017"></a>00017 <span class="comment"> along with this library; see the file COPYING.LIB. If not, write to</span> <a name="l00018"></a>00018 <span class="comment"> the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,</span> <a name="l00019"></a>00019 <span class="comment"> Boston, MA 02110-1301, USA.</span> <a name="l00020"></a>00020 <span class="comment">*/</span> <a name="l00021"></a>00021 <a name="l00022"></a>00022 <span class="preprocessor">#include <stdio.h></span> <a name="l00023"></a>00023 <span class="preprocessor">#include <stdlib.h></span> <a name="l00024"></a>00024 <span class="preprocessor">#include <time.h></span> <a name="l00025"></a>00025 <span class="preprocessor">#include <unistd.h></span> <a name="l00026"></a>00026 <span class="preprocessor">#include <errno.h></span> <a name="l00027"></a>00027 <span class="preprocessor">#include <grp.h></span> <a name="l00028"></a>00028 <span class="preprocessor">#include <pwd.h></span> <a name="l00029"></a>00029 <span class="preprocessor">#include <assert.h></span> <a name="l00030"></a>00030 <span class="preprocessor">#include <sys/types.h></span> <a name="l00031"></a>00031 <span class="preprocessor">#include <sys/stat.h></span> <a name="l00032"></a>00032 <a name="l00033"></a>00033 <span class="preprocessor">#include <qptrlist.h></span> <a name="l00034"></a>00034 <span class="preprocessor">#include <qptrstack.h></span> <a name="l00035"></a>00035 <span class="preprocessor">#include <qvaluestack.h></span> <a name="l00036"></a>00036 <span class="preprocessor">#include <qmap.h></span> <a name="l00037"></a>00037 <span class="preprocessor">#include <qcstring.h></span> <a name="l00038"></a>00038 <span class="preprocessor">#include <qdir.h></span> <a name="l00039"></a>00039 <span class="preprocessor">#include <qfile.h></span> <a name="l00040"></a>00040 <a name="l00041"></a>00041 <span class="preprocessor">#include <kdebug.h></span> <a name="l00042"></a>00042 <span class="preprocessor">#include <kfilterdev.h></span> <a name="l00043"></a>00043 <span class="preprocessor">#include <kfilterbase.h></span> <a name="l00044"></a>00044 <span class="preprocessor">#include <kde_file.h></span> <a name="l00045"></a>00045 <a name="l00046"></a>00046 <span class="preprocessor">#include "karchive.h"</span> <a name="l00047"></a>00047 <span class="preprocessor">#include "klimitediodevice.h"</span> <a name="l00048"></a>00048 <a name="l00049"></a>00049 <span class="keyword">template</span> <span class="keyword">class </span><a class="codeRef" href="qdict.html">QDict<KArchiveEntry></a>; <a name="l00050"></a>00050 <a name="l00051"></a>00051 <a name="l00052"></a>00052 <span class="keyword">class </span>KArchive::KArchivePrivate <a name="l00053"></a>00053 { <a name="l00054"></a>00054 <span class="keyword">public</span>: <a name="l00055"></a>00055 <a class="code" href="classKArchiveDirectory.html" title="Represents a directory entry in a KArchive.">KArchiveDirectory</a>* rootDir; <a name="l00056"></a>00056 <span class="keywordtype">bool</span> closeSucceeded; <a name="l00057"></a>00057 }; <a name="l00058"></a>00058 <a name="l00059"></a>00059 <span class="keyword">class </span>PosSortedPtrList : <span class="keyword">public</span> <a class="codeRef" href="qptrlist.html">QPtrList<KArchiveFile></a> { <a name="l00060"></a>00060 <span class="keyword">protected</span>: <a name="l00061"></a>00061 <span class="keywordtype">int</span> compareItems( <a class="codeRef" href="qptrcollection.html#Item">QPtrCollection::Item</a> i1, <a name="l00062"></a>00062 <a class="codeRef" href="qptrcollection.html#Item">QPtrCollection::Item</a> i2 ) <a name="l00063"></a>00063 { <a name="l00064"></a>00064 <span class="keywordtype">int</span> pos1 = <span class="keyword">static_cast<</span><a class="code" href="classKArchiveFile.html" title="Represents a file entry in a KArchive.">KArchiveFile</a>*<span class="keyword">></span>( i1 )->position(); <a name="l00065"></a>00065 <span class="keywordtype">int</span> pos2 = <span class="keyword">static_cast<</span><a class="code" href="classKArchiveFile.html" title="Represents a file entry in a KArchive.">KArchiveFile</a>*<span class="keyword">></span>( i2 )->position(); <a name="l00066"></a>00066 <span class="keywordflow">return</span> ( pos1 - pos2 ); <a name="l00067"></a>00067 } <a name="l00068"></a>00068 }; <a name="l00069"></a>00069 <a name="l00070"></a>00070 <a name="l00074"></a>00074 <a name="l00075"></a><a class="code" href="classKArchive.html#a3efbb71ada0630d90c5af53fedce9b19">00075</a> <a class="code" href="classKArchive.html#a3efbb71ada0630d90c5af53fedce9b19" title="Base constructor (protected since this is a pure virtual class).">KArchive::KArchive</a>( <a class="codeRef" href="qiodevice.html">QIODevice</a> * dev ) <a name="l00076"></a>00076 { <a name="l00077"></a>00077 d = <span class="keyword">new</span> KArchivePrivate; <a name="l00078"></a>00078 d->rootDir = 0; <a name="l00079"></a>00079 m_dev = dev; <a name="l00080"></a>00080 m_open = <span class="keyword">false</span>; <a name="l00081"></a>00081 } <a name="l00082"></a>00082 <a name="l00083"></a>00083 KArchive::~KArchive() <a name="l00084"></a>00084 { <a name="l00085"></a>00085 <span class="keywordflow">if</span> ( m_open ) <a name="l00086"></a>00086 <a class="code" href="classKArchive.html#a434df272f32f3c9ca69134488804e9c9" title="Closes the archive.">close</a>(); <a name="l00087"></a>00087 <span class="keyword">delete</span> d->rootDir; <a name="l00088"></a>00088 <span class="keyword">delete</span> d; <a name="l00089"></a>00089 } <a name="l00090"></a>00090 <a name="l00091"></a><a class="code" href="classKArchive.html#a2b7e12eb39e9aad18d696ecfa31af969">00091</a> <span class="keywordtype">bool</span> <a class="code" href="classKArchive.html#a2b7e12eb39e9aad18d696ecfa31af969" title="Opens the archive for reading or writing.">KArchive::open</a>( <span class="keywordtype">int</span> mode ) <a name="l00092"></a>00092 { <a name="l00093"></a>00093 <span class="keywordflow">if</span> ( m_dev && !m_dev-><a class="codeRef" href="qiodevice.html#open">open</a>( mode ) ) <a name="l00094"></a>00094 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00095"></a>00095 <a name="l00096"></a>00096 <span class="keywordflow">if</span> ( m_open ) <a name="l00097"></a>00097 <a class="code" href="classKArchive.html#a434df272f32f3c9ca69134488804e9c9" title="Closes the archive.">close</a>(); <a name="l00098"></a>00098 <a name="l00099"></a>00099 m_mode = <a class="code" href="classKArchive.html#a8b33f0b89ed4dbc81d03bb5498b91048" title="Returns the mode in which the archive was opened.">mode</a>; <a name="l00100"></a>00100 m_open = <span class="keyword">true</span>; <a name="l00101"></a>00101 <a name="l00102"></a>00102 Q_ASSERT( d->rootDir == 0L ); <a name="l00103"></a>00103 d->rootDir = 0L; <a name="l00104"></a>00104 <a name="l00105"></a>00105 <span class="keywordflow">return</span> <a class="code" href="classKArchive.html#aa31f2331fa3be7abe14811eca7f2e54b" title="Opens an archive for reading or writing.">openArchive</a>( mode ); <a name="l00106"></a>00106 } <a name="l00107"></a>00107 <a name="l00108"></a><a class="code" href="classKArchive.html#a434df272f32f3c9ca69134488804e9c9">00108</a> <span class="keywordtype">void</span> <a class="code" href="classKArchive.html#a434df272f32f3c9ca69134488804e9c9" title="Closes the archive.">KArchive::close</a>() <a name="l00109"></a>00109 { <a name="l00110"></a>00110 <span class="keywordflow">if</span> ( !m_open ) <a name="l00111"></a>00111 <span class="keywordflow">return</span>; <a name="l00112"></a>00112 <span class="comment">// moved by holger to allow kzip to write the zip central dir</span> <a name="l00113"></a>00113 <span class="comment">// to the file in closeArchive()</span> <a name="l00114"></a>00114 d->closeSucceeded = <a class="code" href="classKArchive.html#a52fa0982c4acaf9dcca8df09749e99a0" title="Closes the archive.">closeArchive</a>(); <a name="l00115"></a>00115 <a name="l00116"></a>00116 <span class="keywordflow">if</span> ( m_dev ) <a name="l00117"></a>00117 m_dev-><a class="codeRef" href="qiodevice.html#close">close</a>(); <a name="l00118"></a>00118 <a name="l00119"></a>00119 <span class="keyword">delete</span> d->rootDir; <a name="l00120"></a>00120 d->rootDir = 0; <a name="l00121"></a>00121 m_open = <span class="keyword">false</span>; <a name="l00122"></a>00122 } <a name="l00123"></a>00123 <a name="l00124"></a><a class="code" href="classKArchive.html#a32a576bf8c461db02f582966e8c9edc3">00124</a> <span class="keywordtype">bool</span> <a class="code" href="classKArchive.html#a32a576bf8c461db02f582966e8c9edc3" title="Use to check if close had any problem.">KArchive::closeSucceeded</a>()<span class="keyword"> const</span> <a name="l00125"></a>00125 <span class="keyword"></span>{ <a name="l00126"></a>00126 <span class="keywordflow">return</span> d->closeSucceeded; <a name="l00127"></a>00127 } <a name="l00128"></a>00128 <a name="l00129"></a><a class="code" href="classKArchive.html#a2fde221a994b790f0dad3799bdad24ad">00129</a> <span class="keyword">const</span> <a class="code" href="classKArchiveDirectory.html" title="Represents a directory entry in a KArchive.">KArchiveDirectory</a>* <a class="code" href="classKArchive.html#a2fde221a994b790f0dad3799bdad24ad" title="If an archive is opened for reading, then the contents of the archive can be accessed via this functi...">KArchive::directory</a>()<span class="keyword"> const</span> <a name="l00130"></a>00130 <span class="keyword"></span>{ <a name="l00131"></a>00131 <span class="comment">// rootDir isn't const so that parsing-on-demand is possible</span> <a name="l00132"></a>00132 <span class="keywordflow">return</span> <span class="keyword">const_cast<</span><a class="code" href="classKArchive.html" title="KArchive is a base class for reading and writing archives.">KArchive</a> *<span class="keyword">></span>(<span class="keyword">this</span>)-><a class="code" href="classKArchive.html#a218da40618b5ea5623656d3dbf3d9ecc" title="Retrieves or create the root directory.">rootDir</a>(); <a name="l00133"></a>00133 } <a name="l00134"></a>00134 <a name="l00135"></a>00135 <a name="l00136"></a><a class="code" href="classKArchive.html#a1e3b4d361c4b57fe8cb956a9b49a85e4">00136</a> <span class="keywordtype">bool</span> <a class="code" href="classKArchive.html#a1e3b4d361c4b57fe8cb956a9b49a85e4" title="Writes a local file into the archive.">KArchive::addLocalFile</a>( <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& fileName, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& destName ) <a name="l00137"></a>00137 { <a name="l00138"></a>00138 <a class="codeRef" href="qfileinfo.html">QFileInfo</a> fileInfo( fileName ); <a name="l00139"></a>00139 <span class="keywordflow">if</span> ( !fileInfo.<a class="codeRef" href="qfileinfo.html#isFile">isFile</a>() && !fileInfo.<a class="codeRef" href="qfileinfo.html#isSymLink">isSymLink</a>() ) <a name="l00140"></a>00140 { <a name="l00141"></a>00141 kdWarning() << <span class="stringliteral">"KArchive::addLocalFile "</span> << fileName << <span class="stringliteral">" doesn't exist or is not a regular file."</span> << endl; <a name="l00142"></a>00142 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00143"></a>00143 } <a name="l00144"></a>00144 <a name="l00145"></a>00145 KDE_struct_stat fi; <a name="l00146"></a>00146 <span class="keywordflow">if</span> (KDE_lstat(<a class="codeRef" href="qfile.html#encodeName">QFile::encodeName</a>(fileName),&fi) == -1) { <a name="l00147"></a>00147 kdWarning() << <span class="stringliteral">"KArchive::addLocalFile stating "</span> << fileName <a name="l00148"></a>00148 << <span class="stringliteral">" failed: "</span> << strerror(errno) << endl; <a name="l00149"></a>00149 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00150"></a>00150 } <a name="l00151"></a>00151 <a name="l00152"></a>00152 <span class="keywordflow">if</span> (fileInfo.<a class="codeRef" href="qfileinfo.html#isSymLink">isSymLink</a>()) { <a name="l00153"></a>00153 <span class="keywordflow">return</span> <a class="code" href="classKArchive.html#a3798b8058f9f0639a2102e12722c95bb" title="Writes a symbolic link to the archive if the archive must be opened for writing.">writeSymLink</a>(destName, fileInfo.<a class="codeRef" href="qfileinfo.html#readLink">readLink</a>(), fileInfo.<a class="codeRef" href="qfileinfo.html#owner">owner</a>(), <a name="l00154"></a>00154 fileInfo.<a class="codeRef" href="qfileinfo.html#group">group</a>(), fi.st_mode, fi.st_atime, fi.st_mtime, <a name="l00155"></a>00155 fi.st_ctime); <a name="l00156"></a>00156 }<span class="comment">/*end if*/</span> <a name="l00157"></a>00157 <a name="l00158"></a>00158 uint size = fileInfo.<a class="codeRef" href="qfileinfo.html#size">size</a>(); <a name="l00159"></a>00159 <a name="l00160"></a>00160 <span class="comment">// the file must be opened before prepareWriting is called, otherwise</span> <a name="l00161"></a>00161 <span class="comment">// if the opening fails, no content will follow the already written</span> <a name="l00162"></a>00162 <span class="comment">// header and the tar file is effectively f*cked up</span> <a name="l00163"></a>00163 <a class="codeRef" href="qfile.html">QFile</a> file( fileName ); <a name="l00164"></a>00164 <span class="keywordflow">if</span> ( !file.<a class="codeRef" href="qfile.html#open">open</a>( IO_ReadOnly ) ) <a name="l00165"></a>00165 { <a name="l00166"></a>00166 kdWarning() << <span class="stringliteral">"KArchive::addLocalFile couldn't open file "</span> << fileName << endl; <a name="l00167"></a>00167 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00168"></a>00168 } <a name="l00169"></a>00169 <a name="l00170"></a>00170 <span class="keywordflow">if</span> ( !<a class="code" href="classKArchive.html#a60b42cc93e203295157d6cff896dc225" title="Here's another way of writing a file into an archive: Call prepareWriting, then call writeData() as m...">prepareWriting</a>( destName, fileInfo.<a class="codeRef" href="qfileinfo.html#owner">owner</a>(), fileInfo.<a class="codeRef" href="qfileinfo.html#group">group</a>(), size, <a name="l00171"></a>00171 fi.st_mode, fi.st_atime, fi.st_mtime, fi.st_ctime ) ) <a name="l00172"></a>00172 { <a name="l00173"></a>00173 kdWarning() << <span class="stringliteral">"KArchive::addLocalFile prepareWriting "</span> << destName << <span class="stringliteral">" failed"</span> << endl; <a name="l00174"></a>00174 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00175"></a>00175 } <a name="l00176"></a>00176 <a name="l00177"></a>00177 <span class="comment">// Read and write data in chunks to minimize memory usage</span> <a name="l00178"></a>00178 <a class="codeRef" href="qbytearray.html">QByteArray</a> array(8*1024); <a name="l00179"></a>00179 <span class="keywordtype">int</span> n; <a name="l00180"></a>00180 uint total = 0; <a name="l00181"></a>00181 <span class="keywordflow">while</span> ( ( n = file.readBlock( array.data(), array.size() ) ) > 0 ) <a name="l00182"></a>00182 { <a name="l00183"></a>00183 <span class="keywordflow">if</span> ( !<a class="code" href="classKArchive.html#ac6cc6eb9cf66e19de86fc8b7631a35f3" title="Write data into the current file - to be called after calling prepareWriting.">writeData</a>( array.data(), n ) ) <a name="l00184"></a>00184 { <a name="l00185"></a>00185 kdWarning() << <span class="stringliteral">"KArchive::addLocalFile writeData failed"</span> << endl; <a name="l00186"></a>00186 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00187"></a>00187 } <a name="l00188"></a>00188 total += n; <a name="l00189"></a>00189 } <a name="l00190"></a>00190 Q_ASSERT( total == size ); <a name="l00191"></a>00191 <a name="l00192"></a>00192 <span class="keywordflow">if</span> ( !<a class="code" href="classKArchive.html#aa25a334b408e743c4ac928597777a5d0" title="Call doneWriting after writing the data.">doneWriting</a>( size ) ) <a name="l00193"></a>00193 { <a name="l00194"></a>00194 kdWarning() << <span class="stringliteral">"KArchive::addLocalFile doneWriting failed"</span> << endl; <a name="l00195"></a>00195 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00196"></a>00196 } <a name="l00197"></a>00197 <span class="keywordflow">return</span> <span class="keyword">true</span>; <a name="l00198"></a>00198 } <a name="l00199"></a>00199 <a name="l00200"></a><a class="code" href="classKArchive.html#ab5a2f90d4003664127e744d078162c34">00200</a> <span class="keywordtype">bool</span> <a class="code" href="classKArchive.html#ab5a2f90d4003664127e744d078162c34" title="Writes a local directory into the archive, including all its contents, recursively.">KArchive::addLocalDirectory</a>( <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& path, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& destName ) <a name="l00201"></a>00201 { <a name="l00202"></a>00202 <a class="codeRef" href="qstring.html">QString</a> dot = <span class="stringliteral">"."</span>; <a name="l00203"></a>00203 <a class="codeRef" href="qstring.html">QString</a> dotdot = <span class="stringliteral">".."</span>; <a name="l00204"></a>00204 <a class="codeRef" href="qdir.html">QDir</a> dir( path ); <a name="l00205"></a>00205 <span class="keywordflow">if</span> ( !dir.<a class="codeRef" href="qdir.html#exists">exists</a>() ) <a name="l00206"></a>00206 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00207"></a>00207 dir.<a class="codeRef" href="qdir.html#setFilter">setFilter</a>(dir.<a class="codeRef" href="qdir.html#filter">filter</a>() | QDir::Hidden); <a name="l00208"></a>00208 <a class="codeRef" href="qstringlist.html">QStringList</a> files = dir.<a class="codeRef" href="qdir.html#entryList">entryList</a>(); <a name="l00209"></a>00209 <span class="keywordflow">for</span> ( QStringList::Iterator it = files.begin(); it != files.end(); ++it ) <a name="l00210"></a>00210 { <a name="l00211"></a>00211 <span class="keywordflow">if</span> ( *it != dot && *it != dotdot ) <a name="l00212"></a>00212 { <a name="l00213"></a>00213 <a class="codeRef" href="qstring.html">QString</a> fileName = path + <span class="stringliteral">"/"</span> + *it; <a name="l00214"></a>00214 <span class="comment">// kdDebug() << "storing " << fileName << endl;</span> <a name="l00215"></a>00215 <a class="codeRef" href="qstring.html">QString</a> dest = destName.<a class="codeRef" href="qstring.html#isEmpty">isEmpty</a>() ? *it : (destName + <span class="stringliteral">"/"</span> + *it); <a name="l00216"></a>00216 <a class="codeRef" href="qfileinfo.html">QFileInfo</a> fileInfo( fileName ); <a name="l00217"></a>00217 <a name="l00218"></a>00218 <span class="keywordflow">if</span> ( fileInfo.<a class="codeRef" href="qfileinfo.html#isFile">isFile</a>() || fileInfo.<a class="codeRef" href="qfileinfo.html#isSymLink">isSymLink</a>() ) <a name="l00219"></a>00219 <a class="code" href="classKArchive.html#a1e3b4d361c4b57fe8cb956a9b49a85e4" title="Writes a local file into the archive.">addLocalFile</a>( fileName, dest ); <a name="l00220"></a>00220 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( fileInfo.<a class="codeRef" href="qfileinfo.html#isDir">isDir</a>() ) <a name="l00221"></a>00221 <a class="code" href="classKArchive.html#ab5a2f90d4003664127e744d078162c34" title="Writes a local directory into the archive, including all its contents, recursively.">addLocalDirectory</a>( fileName, dest ); <a name="l00222"></a>00222 <span class="comment">// We omit sockets</span> <a name="l00223"></a>00223 } <a name="l00224"></a>00224 } <a name="l00225"></a>00225 <span class="keywordflow">return</span> <span class="keyword">true</span>; <a name="l00226"></a>00226 } <a name="l00227"></a>00227 <a name="l00228"></a><a class="code" href="classKArchive.html#a11a0ccee850c26cfcd835ec14c5c3d96">00228</a> <span class="keywordtype">bool</span> <a class="code" href="classKArchive.html#a11a0ccee850c26cfcd835ec14c5c3d96" title="If an archive is opened for writing then you can add a new file using this function.">KArchive::writeFile</a>( <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& name, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& user, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& group, uint size, <span class="keyword">const</span> <span class="keywordtype">char</span>* data ) <a name="l00229"></a>00229 { <a name="l00230"></a>00230 mode_t perm = 0100644; <a name="l00231"></a>00231 time_t the_time = time(0); <a name="l00232"></a>00232 <span class="keywordflow">return</span> <a class="code" href="classKArchive.html#a11a0ccee850c26cfcd835ec14c5c3d96" title="If an archive is opened for writing then you can add a new file using this function.">writeFile</a>(name,user,group,size,perm,the_time,the_time,the_time,data); <a name="l00233"></a>00233 } <a name="l00234"></a>00234 <a name="l00235"></a><a class="code" href="classKArchive.html#a2a44d91c957af94cd80111df993d022a">00235</a> <span class="keywordtype">bool</span> <a class="code" href="classKArchive.html#a60b42cc93e203295157d6cff896dc225" title="Here's another way of writing a file into an archive: Call prepareWriting, then call writeData() as m...">KArchive::prepareWriting</a>( <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& name, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& user, <a name="l00236"></a>00236 <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& group, uint size, mode_t perm, <a name="l00237"></a>00237 time_t atime, time_t mtime, time_t ctime ) { <a name="l00238"></a>00238 PrepareWritingParams params; <a name="l00239"></a>00239 params.name = &name; <a name="l00240"></a>00240 params.user = &user; <a name="l00241"></a>00241 params.group = &group; <a name="l00242"></a>00242 params.size = size; <a name="l00243"></a>00243 params.perm = perm; <a name="l00244"></a>00244 params.atime = atime; <a name="l00245"></a>00245 params.mtime = mtime; <a name="l00246"></a>00246 params.ctime = ctime; <a name="l00247"></a>00247 virtual_hook(VIRTUAL_PREPARE_WRITING,&params); <a name="l00248"></a>00248 <span class="keywordflow">return</span> params.retval; <a name="l00249"></a>00249 } <a name="l00250"></a>00250 <a name="l00251"></a>00251 <span class="keywordtype">bool</span> KArchive::prepareWriting_impl(<span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> &name, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> &user, <a name="l00252"></a>00252 <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> &group, uint size, mode_t <span class="comment">/*perm*/</span>, <a name="l00253"></a>00253 time_t <span class="comment">/*atime*/</span>, time_t <span class="comment">/*mtime*/</span>, time_t <span class="comment">/*ctime*/</span> ) { <a name="l00254"></a>00254 kdWarning(7040) << <span class="stringliteral">"New prepareWriting API not implemented in this class."</span> << endl <a name="l00255"></a>00255 << <span class="stringliteral">"Falling back to old API (metadata information will be lost)"</span> << endl; <a name="l00256"></a>00256 <span class="keywordflow">return</span> <a class="code" href="classKArchive.html#a60b42cc93e203295157d6cff896dc225" title="Here's another way of writing a file into an archive: Call prepareWriting, then call writeData() as m...">prepareWriting</a>(name,user,group,size); <a name="l00257"></a>00257 } <a name="l00258"></a>00258 <a name="l00259"></a><a class="code" href="classKArchive.html#a1b5fba2a65734a795d0d5109817fd651">00259</a> <span class="keywordtype">bool</span> <a class="code" href="classKArchive.html#a11a0ccee850c26cfcd835ec14c5c3d96" title="If an archive is opened for writing then you can add a new file using this function.">KArchive::writeFile</a>( <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& name, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& user, <a name="l00260"></a>00260 <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& group, uint size, mode_t perm, <a name="l00261"></a>00261 time_t atime, time_t mtime, time_t ctime, <a name="l00262"></a>00262 <span class="keyword">const</span> <span class="keywordtype">char</span>* data ) { <a name="l00263"></a>00263 WriteFileParams params; <a name="l00264"></a>00264 params.name = &name; <a name="l00265"></a>00265 params.user = &user; <a name="l00266"></a>00266 params.group = &group; <a name="l00267"></a>00267 params.size = size; <a name="l00268"></a>00268 params.perm = perm; <a name="l00269"></a>00269 params.atime = atime; <a name="l00270"></a>00270 params.mtime = mtime; <a name="l00271"></a>00271 params.ctime = ctime; <a name="l00272"></a>00272 params.<a class="codeRef" href="qstring.html#data">data</a> = data; <a name="l00273"></a>00273 virtual_hook(VIRTUAL_WRITE_FILE,&params); <a name="l00274"></a>00274 <span class="keywordflow">return</span> params.retval; <a name="l00275"></a>00275 } <a name="l00276"></a>00276 <a name="l00277"></a>00277 <span class="keywordtype">bool</span> KArchive::writeFile_impl( <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& name, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& user, <a name="l00278"></a>00278 <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& group, uint size, mode_t perm, <a name="l00279"></a>00279 time_t atime, time_t mtime, time_t ctime, <a name="l00280"></a>00280 <span class="keyword">const</span> <span class="keywordtype">char</span>* data ) { <a name="l00281"></a>00281 <a name="l00282"></a>00282 <span class="keywordflow">if</span> ( !<a class="code" href="classKArchive.html#a60b42cc93e203295157d6cff896dc225" title="Here's another way of writing a file into an archive: Call prepareWriting, then call writeData() as m...">prepareWriting</a>( name, user, group, size, perm, atime, mtime, ctime ) ) <a name="l00283"></a>00283 { <a name="l00284"></a>00284 kdWarning() << <span class="stringliteral">"KArchive::writeFile prepareWriting failed"</span> << endl; <a name="l00285"></a>00285 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00286"></a>00286 } <a name="l00287"></a>00287 <a name="l00288"></a>00288 <span class="comment">// Write data</span> <a name="l00289"></a>00289 <span class="comment">// Note: if data is 0L, don't call writeBlock, it would terminate the KFilterDev</span> <a name="l00290"></a>00290 <span class="keywordflow">if</span> ( data && size && !<a class="code" href="classKArchive.html#ac6cc6eb9cf66e19de86fc8b7631a35f3" title="Write data into the current file - to be called after calling prepareWriting.">writeData</a>( data, size ) ) <a name="l00291"></a>00291 { <a name="l00292"></a>00292 kdWarning() << <span class="stringliteral">"KArchive::writeFile writeData failed"</span> << endl; <a name="l00293"></a>00293 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00294"></a>00294 } <a name="l00295"></a>00295 <a name="l00296"></a>00296 <span class="keywordflow">if</span> ( !<a class="code" href="classKArchive.html#aa25a334b408e743c4ac928597777a5d0" title="Call doneWriting after writing the data.">doneWriting</a>( size ) ) <a name="l00297"></a>00297 { <a name="l00298"></a>00298 kdWarning() << <span class="stringliteral">"KArchive::writeFile doneWriting failed"</span> << endl; <a name="l00299"></a>00299 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00300"></a>00300 } <a name="l00301"></a>00301 <span class="keywordflow">return</span> <span class="keyword">true</span>; <a name="l00302"></a>00302 } <a name="l00303"></a>00303 <a name="l00304"></a><a class="code" href="classKArchive.html#a34c27e0aa9dc810ba1d5771f504162b3">00304</a> <span class="keywordtype">bool</span> <a class="code" href="classKArchive.html#ae8a68fbcdc1daa3a125b5899676cecc1" title="If an archive is opened for writing then you can add new directories using this function.">KArchive::writeDir</a>(<span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& name, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& user, <a name="l00305"></a>00305 <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& group, mode_t perm, <a name="l00306"></a>00306 time_t atime, time_t mtime, time_t ctime) { <a name="l00307"></a>00307 WriteDirParams params; <a name="l00308"></a>00308 params.name = &name; <a name="l00309"></a>00309 params.user = &user; <a name="l00310"></a>00310 params.group = &group; <a name="l00311"></a>00311 params.perm = perm; <a name="l00312"></a>00312 params.atime = atime; <a name="l00313"></a>00313 params.mtime = mtime; <a name="l00314"></a>00314 params.ctime = ctime; <a name="l00315"></a>00315 virtual_hook(VIRTUAL_WRITE_DIR,&params); <a name="l00316"></a>00316 <span class="keywordflow">return</span> params.retval; <a name="l00317"></a>00317 } <a name="l00318"></a>00318 <a name="l00319"></a>00319 <span class="keywordtype">bool</span> KArchive::writeDir_impl(<span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> &name, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> &user, <a name="l00320"></a>00320 <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> &group, mode_t <span class="comment">/*perm*/</span>, <a name="l00321"></a>00321 time_t <span class="comment">/*atime*/</span>, time_t <span class="comment">/*mtime*/</span>, time_t <span class="comment">/*ctime*/</span> ) { <a name="l00322"></a>00322 kdWarning(7040) << <span class="stringliteral">"New writeDir API not implemented in this class."</span> << endl <a name="l00323"></a>00323 << <span class="stringliteral">"Falling back to old API (metadata information will be lost)"</span> << endl; <a name="l00324"></a>00324 <span class="keywordflow">return</span> <a class="code" href="classKArchive.html#ae8a68fbcdc1daa3a125b5899676cecc1" title="If an archive is opened for writing then you can add new directories using this function.">writeDir</a>(name,user,group); <a name="l00325"></a>00325 } <a name="l00326"></a>00326 <a name="l00327"></a><a class="code" href="classKArchive.html#a3798b8058f9f0639a2102e12722c95bb">00327</a> <span class="keywordtype">bool</span> <a class="code" href="classKArchive.html#a3798b8058f9f0639a2102e12722c95bb" title="Writes a symbolic link to the archive if the archive must be opened for writing.">KArchive::writeSymLink</a>(<span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> &name, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> &target, <a name="l00328"></a>00328 <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> &user, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> &group, <a name="l00329"></a>00329 mode_t perm, time_t atime, time_t mtime, time_t ctime) { <a name="l00330"></a>00330 WriteSymlinkParams params; <a name="l00331"></a>00331 params.name = &name; <a name="l00332"></a>00332 params.target = &target; <a name="l00333"></a>00333 params.user = &user; <a name="l00334"></a>00334 params.group = &group; <a name="l00335"></a>00335 params.perm = perm; <a name="l00336"></a>00336 params.atime = atime; <a name="l00337"></a>00337 params.mtime = mtime; <a name="l00338"></a>00338 params.ctime = ctime; <a name="l00339"></a>00339 virtual_hook(VIRTUAL_WRITE_SYMLINK,&params); <a name="l00340"></a>00340 <span class="keywordflow">return</span> params.retval; <a name="l00341"></a>00341 } <a name="l00342"></a>00342 <a name="l00343"></a>00343 <span class="keywordtype">bool</span> KArchive::writeSymLink_impl(<span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> &<span class="comment">/*name*/</span>,<span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> &<span class="comment">/*target*/</span>, <a name="l00344"></a>00344 <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> &<span class="comment">/*user*/</span>, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> &<span class="comment">/*group*/</span>, <a name="l00345"></a>00345 mode_t <span class="comment">/*perm*/</span>, time_t <span class="comment">/*atime*/</span>, time_t <span class="comment">/*mtime*/</span>, <a name="l00346"></a>00346 time_t <span class="comment">/*ctime*/</span>) { <a name="l00347"></a>00347 kdWarning(7040) << <span class="stringliteral">"writeSymLink not implemented in this class."</span> << endl <a name="l00348"></a>00348 << <span class="stringliteral">"No fallback available."</span> << endl; <a name="l00349"></a>00349 <span class="comment">// FIXME: better return true here for compatibility with KDE < 3.2</span> <a name="l00350"></a>00350 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00351"></a>00351 } <a name="l00352"></a>00352 <a name="l00353"></a><a class="code" href="classKArchive.html#ac6cc6eb9cf66e19de86fc8b7631a35f3">00353</a> <span class="keywordtype">bool</span> <a class="code" href="classKArchive.html#ac6cc6eb9cf66e19de86fc8b7631a35f3" title="Write data into the current file - to be called after calling prepareWriting.">KArchive::writeData</a>( <span class="keyword">const</span> <span class="keywordtype">char</span>* data, uint size ) <a name="l00354"></a>00354 { <a name="l00355"></a>00355 WriteDataParams params; <a name="l00356"></a>00356 params.data = data; <a name="l00357"></a>00357 params.size = size; <a name="l00358"></a>00358 virtual_hook( VIRTUAL_WRITE_DATA, &params ); <a name="l00359"></a>00359 <span class="keywordflow">return</span> params.retval; <a name="l00360"></a>00360 } <a name="l00361"></a>00361 <a name="l00362"></a>00362 <span class="keywordtype">bool</span> KArchive::writeData_impl( <span class="keyword">const</span> <span class="keywordtype">char</span>* data, uint size ) <a name="l00363"></a>00363 { <a name="l00364"></a>00364 Q_ASSERT( <a class="code" href="classKArchive.html#a42393a1c08518fcf8d8d956872be72ea" title="The underlying device.">device</a>() ); <a name="l00365"></a>00365 <span class="keywordflow">return</span> <a class="code" href="classKArchive.html#a42393a1c08518fcf8d8d956872be72ea" title="The underlying device.">device</a>()-><a class="codeRef" href="qiodevice.html#writeBlock">writeBlock</a>( data, size ) == (Q_LONG)size; <a name="l00366"></a>00366 } <a name="l00367"></a>00367 <a name="l00368"></a><a class="code" href="classKArchive.html#a218da40618b5ea5623656d3dbf3d9ecc">00368</a> <a class="code" href="classKArchiveDirectory.html" title="Represents a directory entry in a KArchive.">KArchiveDirectory</a> * <a class="code" href="classKArchive.html#a218da40618b5ea5623656d3dbf3d9ecc" title="Retrieves or create the root directory.">KArchive::rootDir</a>() <a name="l00369"></a>00369 { <a name="l00370"></a>00370 <span class="keywordflow">if</span> ( !d->rootDir ) <a name="l00371"></a>00371 { <a name="l00372"></a>00372 <span class="comment">//kdDebug() << "Making root dir " << endl;</span> <a name="l00373"></a>00373 <span class="keyword">struct </span>passwd* pw = getpwuid( getuid() ); <a name="l00374"></a>00374 <span class="keyword">struct </span>group* grp = getgrgid( getgid() ); <a name="l00375"></a>00375 <a class="codeRef" href="qstring.html">QString</a> username = pw ? <a class="codeRef" href="qfile.html#decodeName">QFile::decodeName</a>(pw->pw_name) : <a class="codeRef" href="qstring.html#number">QString::number</a>( getuid() ); <a name="l00376"></a>00376 <a class="codeRef" href="qstring.html">QString</a> groupname = grp ? QFile::decodeName(grp->gr_name) : <a class="codeRef" href="qstring.html#number">QString::number</a>( getgid() ); <a name="l00377"></a>00377 <a name="l00378"></a>00378 d->rootDir = <span class="keyword">new</span> <a class="code" href="classKArchiveDirectory.html" title="Represents a directory entry in a KArchive.">KArchiveDirectory</a>( <span class="keyword">this</span>, <a class="codeRef" href="qstring.html#fromLatin1">QString::fromLatin1</a>(<span class="stringliteral">"/"</span>), (<span class="keywordtype">int</span>)(0777 + S_IFDIR), 0, username, groupname, QString::null ); <a name="l00379"></a>00379 } <a name="l00380"></a>00380 <span class="keywordflow">return</span> d->rootDir; <a name="l00381"></a>00381 } <a name="l00382"></a>00382 <a name="l00383"></a><a class="code" href="classKArchive.html#aa5dfd148c5c870da8a2330d0371e3d6e">00383</a> <a class="code" href="classKArchiveDirectory.html" title="Represents a directory entry in a KArchive.">KArchiveDirectory</a> * <a class="code" href="classKArchive.html#aa5dfd148c5c870da8a2330d0371e3d6e" title="Ensures that path exists, create otherwise.">KArchive::findOrCreate</a>( <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> & path ) <a name="l00384"></a>00384 { <a name="l00385"></a>00385 <span class="comment">//kdDebug() << "KArchive::findOrCreate " << path << endl;</span> <a name="l00386"></a>00386 <span class="keywordflow">if</span> ( path.<a class="codeRef" href="qstring.html#isEmpty">isEmpty</a>() || path == <span class="stringliteral">"/"</span> || path == <span class="stringliteral">"."</span> ) <span class="comment">// root dir => found</span> <a name="l00387"></a>00387 { <a name="l00388"></a>00388 <span class="comment">//kdDebug() << "KArchive::findOrCreate returning rootdir" << endl;</span> <a name="l00389"></a>00389 <span class="keywordflow">return</span> <a class="code" href="classKArchive.html#a218da40618b5ea5623656d3dbf3d9ecc" title="Retrieves or create the root directory.">rootDir</a>(); <a name="l00390"></a>00390 } <a name="l00391"></a>00391 <span class="comment">// Important note : for tar files containing absolute paths</span> <a name="l00392"></a>00392 <span class="comment">// (i.e. beginning with "/"), this means the leading "/" will</span> <a name="l00393"></a>00393 <span class="comment">// be removed (no KDirectory for it), which is exactly the way</span> <a name="l00394"></a>00394 <span class="comment">// the "tar" program works (though it displays a warning about it)</span> <a name="l00395"></a>00395 <span class="comment">// See also KArchiveDirectory::entry().</span> <a name="l00396"></a>00396 <a name="l00397"></a>00397 <span class="comment">// Already created ? => found</span> <a name="l00398"></a>00398 <a class="code" href="classKArchiveEntry.html" title="A base class for entries in an KArchive.">KArchiveEntry</a>* ent = <a class="code" href="classKArchive.html#a218da40618b5ea5623656d3dbf3d9ecc" title="Retrieves or create the root directory.">rootDir</a>()-><a class="code" href="classKArchiveDirectory.html#a2a27e00995e14f5bcdec377d2cad99c0" title="Returns the entry with the given name.">entry</a>( path ); <a name="l00399"></a>00399 <span class="keywordflow">if</span> ( ent ) <a name="l00400"></a>00400 { <a name="l00401"></a>00401 <span class="keywordflow">if</span> ( ent-><a class="code" href="classKArchiveEntry.html#a292120b0b7b801ce6adef76986bcdec1" title="Checks whether the entry is a directory.">isDirectory</a>() ) <a name="l00402"></a>00402 <span class="comment">//kdDebug() << "KArchive::findOrCreate found it" << endl;</span> <a name="l00403"></a>00403 <span class="keywordflow">return</span> (<a class="code" href="classKArchiveDirectory.html" title="Represents a directory entry in a KArchive.">KArchiveDirectory</a> *) ent; <a name="l00404"></a>00404 <span class="keywordflow">else</span> <a name="l00405"></a>00405 kdWarning() << <span class="stringliteral">"Found "</span> << path << <span class="stringliteral">" but it's not a directory"</span> << endl; <a name="l00406"></a>00406 } <a name="l00407"></a>00407 <a name="l00408"></a>00408 <span class="comment">// Otherwise go up and try again</span> <a name="l00409"></a>00409 <span class="keywordtype">int</span> pos = path.<a class="codeRef" href="qstring.html#findRev">findRev</a>( <span class="charliteral">'/'</span> ); <a name="l00410"></a>00410 <a class="code" href="classKArchiveDirectory.html" title="Represents a directory entry in a KArchive.">KArchiveDirectory</a> * parent; <a name="l00411"></a>00411 <a class="codeRef" href="qstring.html">QString</a> dirname; <a name="l00412"></a>00412 <span class="keywordflow">if</span> ( pos == -1 ) <span class="comment">// no more slash => create in root dir</span> <a name="l00413"></a>00413 { <a name="l00414"></a>00414 parent = <a class="code" href="classKArchive.html#a218da40618b5ea5623656d3dbf3d9ecc" title="Retrieves or create the root directory.">rootDir</a>(); <a name="l00415"></a>00415 dirname = path; <a name="l00416"></a>00416 } <a name="l00417"></a>00417 <span class="keywordflow">else</span> <a name="l00418"></a>00418 { <a name="l00419"></a>00419 <a class="codeRef" href="qstring.html">QString</a> left = path.<a class="codeRef" href="qstring.html#left">left</a>( pos ); <a name="l00420"></a>00420 dirname = path.<a class="codeRef" href="qstring.html#mid">mid</a>( pos + 1 ); <a name="l00421"></a>00421 parent = <a class="code" href="classKArchive.html#aa5dfd148c5c870da8a2330d0371e3d6e" title="Ensures that path exists, create otherwise.">findOrCreate</a>( left ); <span class="comment">// recursive call... until we find an existing dir.</span> <a name="l00422"></a>00422 } <a name="l00423"></a>00423 <a name="l00424"></a>00424 <span class="comment">//kdDebug() << "KTar : found parent " << parent->name() << " adding " << dirname << " to ensure " << path << endl;</span> <a name="l00425"></a>00425 <span class="comment">// Found -> add the missing piece</span> <a name="l00426"></a>00426 <a class="code" href="classKArchiveDirectory.html" title="Represents a directory entry in a KArchive.">KArchiveDirectory</a> * e = <span class="keyword">new</span> <a class="code" href="classKArchiveDirectory.html" title="Represents a directory entry in a KArchive.">KArchiveDirectory</a>( <span class="keyword">this</span>, dirname, d->rootDir->permissions(), <a name="l00427"></a>00427 d->rootDir->date(), d->rootDir->user(), <a name="l00428"></a>00428 d->rootDir->group(), QString::null ); <a name="l00429"></a>00429 parent->addEntry( e ); <a name="l00430"></a>00430 <span class="keywordflow">return</span> e; <span class="comment">// now a directory to <path> exists</span> <a name="l00431"></a>00431 } <a name="l00432"></a>00432 <a name="l00433"></a>00433 <span class="keywordtype">void</span> KArchive::setDevice( <a class="codeRef" href="qiodevice.html">QIODevice</a> * dev ) <a name="l00434"></a>00434 { <a name="l00435"></a>00435 m_dev = dev; <a name="l00436"></a>00436 } <a name="l00437"></a>00437 <a name="l00438"></a>00438 <span class="keywordtype">void</span> KArchive::setRootDir( <a class="code" href="classKArchiveDirectory.html" title="Represents a directory entry in a KArchive.">KArchiveDirectory</a> *rootDir ) <a name="l00439"></a>00439 { <a name="l00440"></a>00440 Q_ASSERT( !d->rootDir ); <span class="comment">// Call setRootDir only once during parsing please ;)</span> <a name="l00441"></a>00441 d->rootDir = <a class="code" href="classKArchive.html#a218da40618b5ea5623656d3dbf3d9ecc" title="Retrieves or create the root directory.">rootDir</a>; <a name="l00442"></a>00442 } <a name="l00443"></a>00443 <a name="l00447"></a><a class="code" href="classKArchiveEntry.html#abfbb2b809a3a9824966c29aefe82cc14">00447</a> <a class="code" href="classKArchiveEntry.html#abfbb2b809a3a9824966c29aefe82cc14" title="Creates a new entry.">KArchiveEntry::KArchiveEntry</a>( <a class="code" href="classKArchive.html" title="KArchive is a base class for reading and writing archives.">KArchive</a>* t, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& name, <span class="keywordtype">int</span> access, <span class="keywordtype">int</span> date, <a name="l00448"></a>00448 <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& user, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& group, <span class="keyword">const</span> <a name="l00449"></a>00449 <a class="codeRef" href="qstring.html">QString</a>& symlink) <a name="l00450"></a>00450 { <a name="l00451"></a>00451 m_name = <a class="code" href="classKArchiveEntry.html#ad58bf4da148e9eeda1a45d8bccdcda0c" title="Name of the file without path.">name</a>; <a name="l00452"></a>00452 m_access = access; <a name="l00453"></a>00453 m_date = <a class="code" href="classKArchiveEntry.html#a47ce53784a3d7aee9291501dc5caf4c6" title="Creation date of the file.">date</a>; <a name="l00454"></a>00454 m_user = <a class="code" href="classKArchiveEntry.html#a66289c1b5d168f6bab76b92b9b183506" title="User who created the file.">user</a>; <a name="l00455"></a>00455 m_group = <a class="code" href="classKArchiveEntry.html#a7f4127cb2339ec226c3ae2a184d0a858" title="Group of the user who created the file.">group</a>; <a name="l00456"></a>00456 m_symlink = <a class="code" href="classKArchiveEntry.html#a93ac4953fd62469e44a375223ff5ceb7" title="Symlink if there is one.">symlink</a>; <a name="l00457"></a>00457 m_archive = t; <a name="l00458"></a>00458 <a name="l00459"></a>00459 } <a name="l00460"></a>00460 <a name="l00461"></a><a class="code" href="classKArchiveEntry.html#a5d29ebe59ce00bd729f183402362528f">00461</a> <a class="codeRef" href="qdatetime.html">QDateTime</a> <a class="code" href="classKArchiveEntry.html#a5d29ebe59ce00bd729f183402362528f" title="Creation date of the file.">KArchiveEntry::datetime</a>()<span class="keyword"> const</span> <a name="l00462"></a>00462 <span class="keyword"></span>{ <a name="l00463"></a>00463 <a class="codeRef" href="qdatetime.html">QDateTime</a> d; <a name="l00464"></a>00464 d.<a class="codeRef" href="qdatetime.html#setTime_t">setTime_t</a>( m_date ); <a name="l00465"></a>00465 <span class="keywordflow">return</span> d; <a name="l00466"></a>00466 } <a name="l00467"></a>00467 <a name="l00471"></a>00471 <a name="l00472"></a><a class="code" href="classKArchiveFile.html#a43a8826ec6b11a94722a38ec67578eb9">00472</a> <a class="code" href="classKArchiveFile.html#a43a8826ec6b11a94722a38ec67578eb9" title="Creates a new file entry.">KArchiveFile::KArchiveFile</a>( <a class="code" href="classKArchive.html" title="KArchive is a base class for reading and writing archives.">KArchive</a>* t, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& name, <span class="keywordtype">int</span> access, <span class="keywordtype">int</span> date, <a name="l00473"></a>00473 <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& user, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& group, <a name="l00474"></a>00474 <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> & symlink, <a name="l00475"></a>00475 <span class="keywordtype">int</span> pos, <span class="keywordtype">int</span> size ) <a name="l00476"></a>00476 : <a class="code" href="classKArchiveEntry.html" title="A base class for entries in an KArchive.">KArchiveEntry</a>( t, name, access, date, user, group, symlink ) <a name="l00477"></a>00477 { <a name="l00478"></a>00478 m_pos = pos; <a name="l00479"></a>00479 m_size = <a class="code" href="classKArchiveFile.html#a439a52423feb7e3774cf0c03df079750" title="Size of the data.">size</a>; <a name="l00480"></a>00480 } <a name="l00481"></a>00481 <a name="l00482"></a><a class="code" href="classKArchiveFile.html#abfaf4d36563072b66591956f21426716">00482</a> <span class="keywordtype">int</span> <a class="code" href="classKArchiveFile.html#abfaf4d36563072b66591956f21426716" title="Position of the data in the [uncompressed] archive.">KArchiveFile::position</a>()<span class="keyword"> const</span> <a name="l00483"></a>00483 <span class="keyword"></span>{ <a name="l00484"></a>00484 <span class="keywordflow">return</span> m_pos; <a name="l00485"></a>00485 } <a name="l00486"></a>00486 <a name="l00487"></a><a class="code" href="classKArchiveFile.html#a439a52423feb7e3774cf0c03df079750">00487</a> <span class="keywordtype">int</span> <a class="code" href="classKArchiveFile.html#a439a52423feb7e3774cf0c03df079750" title="Size of the data.">KArchiveFile::size</a>()<span class="keyword"> const</span> <a name="l00488"></a>00488 <span class="keyword"></span>{ <a name="l00489"></a>00489 <span class="keywordflow">return</span> m_size; <a name="l00490"></a>00490 } <a name="l00491"></a>00491 <a name="l00492"></a><a class="code" href="classKArchiveFile.html#a753cd4043f12f458cb5e1e68d6da7ef0">00492</a> <a class="codeRef" href="qbytearray.html">QByteArray</a> <a class="code" href="classKArchiveFile.html#a753cd4043f12f458cb5e1e68d6da7ef0" title="Returns the data of the file.">KArchiveFile::data</a>()<span class="keyword"> const</span> <a name="l00493"></a>00493 <span class="keyword"></span>{ <a name="l00494"></a>00494 archive()-><a class="code" href="classKArchive.html#a42393a1c08518fcf8d8d956872be72ea" title="The underlying device.">device</a>()-><a class="codeRef" href="qiodevice.html#at">at</a>( m_pos ); <a name="l00495"></a>00495 <a name="l00496"></a>00496 <span class="comment">// Read content</span> <a name="l00497"></a>00497 <a class="codeRef" href="qbytearray.html">QByteArray</a> arr( m_size ); <a name="l00498"></a>00498 <span class="keywordflow">if</span> ( m_size ) <a name="l00499"></a>00499 { <a name="l00500"></a>00500 assert( arr.data() ); <a name="l00501"></a>00501 <span class="keywordtype">int</span> n = archive()-><a class="code" href="classKArchive.html#a42393a1c08518fcf8d8d956872be72ea" title="The underlying device.">device</a>()-><a class="codeRef" href="qiodevice.html#readBlock">readBlock</a>( arr.data(), m_size ); <a name="l00502"></a>00502 <span class="keywordflow">if</span> ( n != m_size ) <a name="l00503"></a>00503 arr.resize( n ); <a name="l00504"></a>00504 } <a name="l00505"></a>00505 <span class="keywordflow">return</span> arr; <a name="l00506"></a>00506 } <a name="l00507"></a>00507 <a name="l00508"></a>00508 <span class="comment">// ** This should be a virtual method, and this code should be in ktar.cpp</span> <a name="l00509"></a><a class="code" href="classKArchiveFile.html#a404bf125353c450004fe4020e294a4a8">00509</a> <a class="codeRef" href="qiodevice.html">QIODevice</a> *<a class="code" href="classKArchiveFile.html#a404bf125353c450004fe4020e294a4a8" title="This method returns QIODevice (internal class: KLimitedIODevice) on top of the underlying QIODevice...">KArchiveFile::device</a>()<span class="keyword"> const</span> <a name="l00510"></a>00510 <span class="keyword"></span>{ <a name="l00511"></a>00511 <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="classKLimitedIODevice.html" title="A readonly device that reads from an underlying device from a given point to another (e...">KLimitedIODevice</a>( archive()-><a class="code" href="classKArchiveFile.html#a404bf125353c450004fe4020e294a4a8" title="This method returns QIODevice (internal class: KLimitedIODevice) on top of the underlying QIODevice...">device</a>(), m_pos, m_size ); <a name="l00512"></a>00512 } <a name="l00513"></a>00513 <a name="l00514"></a><a class="code" href="classKArchiveFile.html#a67884151c4025dbcad78c7b781f720de">00514</a> <span class="keywordtype">void</span> <a class="code" href="classKArchiveFile.html#a67884151c4025dbcad78c7b781f720de" title="Extracts the file to the directory dest.">KArchiveFile::copyTo</a>(<span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& dest)<span class="keyword"> const</span> <a name="l00515"></a>00515 <span class="keyword"></span>{ <a name="l00516"></a>00516 <a class="codeRef" href="qfile.html">QFile</a> f( dest + <span class="stringliteral">"/"</span> + <a class="code" href="classKArchiveEntry.html#ad58bf4da148e9eeda1a45d8bccdcda0c" title="Name of the file without path.">name</a>() ); <a name="l00517"></a>00517 f.<a class="codeRef" href="qfile.html#open">open</a>( IO_ReadWrite | IO_Truncate ); <a name="l00518"></a>00518 f.writeBlock( <a class="code" href="classKArchiveFile.html#a753cd4043f12f458cb5e1e68d6da7ef0" title="Returns the data of the file.">data</a>() ); <a name="l00519"></a>00519 f.<a class="codeRef" href="qfile.html#close">close</a>(); <a name="l00520"></a>00520 } <a name="l00521"></a>00521 <a name="l00525"></a>00525 <a name="l00526"></a>00526 <a name="l00527"></a><a class="code" href="classKArchiveDirectory.html#a9df39c57f1c46d405fff0f9c835581c3">00527</a> <a class="code" href="classKArchiveDirectory.html#a9df39c57f1c46d405fff0f9c835581c3" title="Creates a new directory entry.">KArchiveDirectory::KArchiveDirectory</a>( <a class="code" href="classKArchive.html" title="KArchive is a base class for reading and writing archives.">KArchive</a>* t, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& name, <span class="keywordtype">int</span> access, <a name="l00528"></a>00528 <span class="keywordtype">int</span> date, <a name="l00529"></a>00529 <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& user, <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& group, <a name="l00530"></a>00530 <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> &symlink) <a name="l00531"></a>00531 : <a class="code" href="classKArchiveEntry.html" title="A base class for entries in an KArchive.">KArchiveEntry</a>( t, name, access, date, user, group, symlink ) <a name="l00532"></a>00532 { <a name="l00533"></a>00533 m_entries.<a class="codeRef" href="qdict.html#setAutoDelete">setAutoDelete</a>( <span class="keyword">true</span> ); <a name="l00534"></a>00534 } <a name="l00535"></a>00535 <a name="l00536"></a><a class="code" href="classKArchiveDirectory.html#ac5d2c6652a63c3bf4212b7e80ea3d036">00536</a> <a class="codeRef" href="qstringlist.html">QStringList</a> <a class="code" href="classKArchiveDirectory.html#ac5d2c6652a63c3bf4212b7e80ea3d036" title="Returns a list of sub-entries.">KArchiveDirectory::entries</a>()<span class="keyword"> const</span> <a name="l00537"></a>00537 <span class="keyword"></span>{ <a name="l00538"></a>00538 <a class="codeRef" href="qstringlist.html">QStringList</a> l; <a name="l00539"></a>00539 <a name="l00540"></a>00540 <a class="codeRef" href="qdictiterator.html">QDictIterator<KArchiveEntry></a> it( m_entries ); <a name="l00541"></a>00541 <span class="keywordflow">for</span>( ; it.<a class="codeRef" href="qdictiterator.html#current">current</a>(); ++it ) <a name="l00542"></a>00542 l.append( it.<a class="codeRef" href="qdictiterator.html#currentKey">currentKey</a>() ); <a name="l00543"></a>00543 <a name="l00544"></a>00544 <span class="keywordflow">return</span> l; <a name="l00545"></a>00545 } <a name="l00546"></a>00546 <a name="l00547"></a><a class="code" href="classKArchiveDirectory.html#a2a27e00995e14f5bcdec377d2cad99c0">00547</a> <a class="code" href="classKArchiveEntry.html" title="A base class for entries in an KArchive.">KArchiveEntry</a>* <a class="code" href="classKArchiveDirectory.html#a2a27e00995e14f5bcdec377d2cad99c0" title="Returns the entry with the given name.">KArchiveDirectory::entry</a>( <a class="codeRef" href="qstring.html">QString</a> name ) <a name="l00548"></a>00548 <span class="comment">// not "const QString & name" since we want a local copy</span> <a name="l00549"></a>00549 <span class="comment">// (to remove leading slash if any)</span> <a name="l00550"></a>00550 { <a name="l00551"></a>00551 <span class="keywordtype">int</span> pos = name.<a class="codeRef" href="qstring.html#find">find</a>( <span class="charliteral">'/'</span> ); <a name="l00552"></a>00552 <span class="keywordflow">if</span> ( pos == 0 ) <span class="comment">// ouch absolute path (see also KArchive::findOrCreate)</span> <a name="l00553"></a>00553 { <a name="l00554"></a>00554 <span class="keywordflow">if</span> (name.<a class="codeRef" href="qstring.html#length">length</a>()>1) <a name="l00555"></a>00555 { <a name="l00556"></a>00556 name = name.<a class="codeRef" href="qstring.html#mid">mid</a>( 1 ); <span class="comment">// remove leading slash</span> <a name="l00557"></a>00557 pos = name.<a class="codeRef" href="qstring.html#find">find</a>( <span class="charliteral">'/'</span> ); <span class="comment">// look again</span> <a name="l00558"></a>00558 } <a name="l00559"></a>00559 <span class="keywordflow">else</span> <span class="comment">// "/"</span> <a name="l00560"></a>00560 <span class="keywordflow">return</span> <span class="keyword">this</span>; <a name="l00561"></a>00561 } <a name="l00562"></a>00562 <span class="comment">// trailing slash ? -> remove</span> <a name="l00563"></a>00563 <span class="keywordflow">if</span> ( pos != -1 && pos == (<span class="keywordtype">int</span>)name.<a class="codeRef" href="qstring.html#length">length</a>()-1 ) <a name="l00564"></a>00564 { <a name="l00565"></a>00565 name = name.<a class="codeRef" href="qstring.html#left">left</a>( pos ); <a name="l00566"></a>00566 pos = name.<a class="codeRef" href="qstring.html#find">find</a>( <span class="charliteral">'/'</span> ); <span class="comment">// look again</span> <a name="l00567"></a>00567 } <a name="l00568"></a>00568 <span class="keywordflow">if</span> ( pos != -1 ) <a name="l00569"></a>00569 { <a name="l00570"></a>00570 <a class="codeRef" href="qstring.html">QString</a> left = name.<a class="codeRef" href="qstring.html#left">left</a>( pos ); <a name="l00571"></a>00571 <a class="codeRef" href="qstring.html">QString</a> right = name.<a class="codeRef" href="qstring.html#mid">mid</a>( pos + 1 ); <a name="l00572"></a>00572 <a name="l00573"></a>00573 <span class="comment">//kdDebug() << "KArchiveDirectory::entry left=" << left << " right=" << right << endl;</span> <a name="l00574"></a>00574 <a name="l00575"></a>00575 <a class="code" href="classKArchiveEntry.html" title="A base class for entries in an KArchive.">KArchiveEntry</a>* e = m_entries[ left ]; <a name="l00576"></a>00576 <span class="keywordflow">if</span> ( !e || !e-><a class="code" href="classKArchiveEntry.html#a292120b0b7b801ce6adef76986bcdec1" title="Checks whether the entry is a directory.">isDirectory</a>() ) <a name="l00577"></a>00577 <span class="keywordflow">return</span> 0; <a name="l00578"></a>00578 <span class="keywordflow">return</span> ((<a class="code" href="classKArchiveDirectory.html" title="Represents a directory entry in a KArchive.">KArchiveDirectory</a>*)e)-><a class="code" href="classKArchiveDirectory.html#a2a27e00995e14f5bcdec377d2cad99c0" title="Returns the entry with the given name.">entry</a>( right ); <a name="l00579"></a>00579 } <a name="l00580"></a>00580 <a name="l00581"></a>00581 <span class="keywordflow">return</span> m_entries[ <a class="code" href="classKArchiveEntry.html#ad58bf4da148e9eeda1a45d8bccdcda0c" title="Name of the file without path.">name</a> ]; <a name="l00582"></a>00582 } <a name="l00583"></a>00583 <a name="l00584"></a><a class="code" href="classKArchiveDirectory.html#a55f3f49fc53ba1e39222541777b254a1">00584</a> <span class="keyword">const</span> <a class="code" href="classKArchiveEntry.html" title="A base class for entries in an KArchive.">KArchiveEntry</a>* <a class="code" href="classKArchiveDirectory.html#a2a27e00995e14f5bcdec377d2cad99c0" title="Returns the entry with the given name.">KArchiveDirectory::entry</a>( <a class="codeRef" href="qstring.html">QString</a> name )<span class="keyword"> const</span> <a name="l00585"></a>00585 <span class="keyword"></span>{ <a name="l00586"></a>00586 <span class="keywordflow">return</span> ((<a class="code" href="classKArchiveDirectory.html" title="Represents a directory entry in a KArchive.">KArchiveDirectory</a>*)<span class="keyword">this</span>)->entry( name ); <a name="l00587"></a>00587 } <a name="l00588"></a>00588 <a name="l00589"></a>00589 <span class="keywordtype">void</span> KArchiveDirectory::addEntry( <a class="code" href="classKArchiveEntry.html" title="A base class for entries in an KArchive.">KArchiveEntry</a>* entry ) <a name="l00590"></a>00590 { <a name="l00591"></a>00591 <span class="keywordflow">if</span>( entry-><a class="code" href="classKArchiveEntry.html#ad58bf4da148e9eeda1a45d8bccdcda0c" title="Name of the file without path.">name</a>().<a class="codeRef" href="qstring.html#isEmpty">isEmpty</a>() ) <a name="l00592"></a>00592 <span class="keywordflow">return</span>; <a name="l00593"></a>00593 <a name="l00594"></a>00594 <span class="keywordflow">if</span>( m_entries[ entry-><a class="code" href="classKArchiveEntry.html#ad58bf4da148e9eeda1a45d8bccdcda0c" title="Name of the file without path.">name</a>() ] ) { <a name="l00595"></a>00595 kdWarning() << <span class="stringliteral">"KArchiveDirectory::addEntry: directory "</span> << <a class="code" href="classKArchiveEntry.html#ad58bf4da148e9eeda1a45d8bccdcda0c" title="Name of the file without path.">name</a>() <a name="l00596"></a>00596 << <span class="stringliteral">" has entry "</span> << entry-><a class="code" href="classKArchiveEntry.html#ad58bf4da148e9eeda1a45d8bccdcda0c" title="Name of the file without path.">name</a>() << <span class="stringliteral">" already"</span> << endl; <a name="l00597"></a>00597 } <a name="l00598"></a>00598 m_entries.<a class="codeRef" href="qdict.html#insert">insert</a>( entry-><a class="code" href="classKArchiveEntry.html#ad58bf4da148e9eeda1a45d8bccdcda0c" title="Name of the file without path.">name</a>(), <a class="code" href="classKArchiveDirectory.html#a2a27e00995e14f5bcdec377d2cad99c0" title="Returns the entry with the given name.">entry</a> ); <a name="l00599"></a>00599 } <a name="l00600"></a>00600 <a name="l00601"></a><a class="code" href="classKArchiveDirectory.html#aced5459649fa2a556b9027cfa55a64fe">00601</a> <span class="keywordtype">void</span> <a class="code" href="classKArchiveDirectory.html#aced5459649fa2a556b9027cfa55a64fe" title="Extracts all entries in this archive directory to the directory dest.">KArchiveDirectory::copyTo</a>(<span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a>& dest, <span class="keywordtype">bool</span> recursiveCopy )<span class="keyword"> const</span> <a name="l00602"></a>00602 <span class="keyword"></span>{ <a name="l00603"></a>00603 <a class="codeRef" href="qdir.html">QDir</a> root; <a name="l00604"></a>00604 <a name="l00605"></a>00605 PosSortedPtrList fileList; <a name="l00606"></a>00606 <a class="codeRef" href="qmap.html">QMap<int, QString></a> fileToDir; <a name="l00607"></a>00607 <a name="l00608"></a>00608 QStringList::Iterator it; <a name="l00609"></a>00609 <a name="l00610"></a>00610 <span class="comment">// placeholders for iterated items</span> <a name="l00611"></a>00611 <a class="code" href="classKArchiveDirectory.html" title="Represents a directory entry in a KArchive.">KArchiveDirectory</a>* curDir; <a name="l00612"></a>00612 <a class="codeRef" href="qstring.html">QString</a> curDirName; <a name="l00613"></a>00613 <a name="l00614"></a>00614 <a class="codeRef" href="qstringlist.html">QStringList</a> dirEntries; <a name="l00615"></a>00615 <a class="code" href="classKArchiveEntry.html" title="A base class for entries in an KArchive.">KArchiveEntry</a>* curEntry; <a name="l00616"></a>00616 <a class="code" href="classKArchiveFile.html" title="Represents a file entry in a KArchive.">KArchiveFile</a>* curFile; <a name="l00617"></a>00617 <a name="l00618"></a>00618 <a name="l00619"></a>00619 <a class="codeRef" href="qptrstack.html">QPtrStack<KArchiveDirectory></a> dirStack; <a name="l00620"></a>00620 <a class="codeRef" href="qvaluestack.html">QValueStack<QString></a> dirNameStack; <a name="l00621"></a>00621 <a name="l00622"></a>00622 dirStack.<a class="codeRef" href="qptrstack.html#push">push</a>( <span class="keyword">this</span> ); <span class="comment">// init stack at current directory</span> <a name="l00623"></a>00623 dirNameStack.<a class="codeRef" href="qvaluestack.html#push">push</a>( dest ); <span class="comment">// ... with given path</span> <a name="l00624"></a>00624 <span class="keywordflow">do</span> { <a name="l00625"></a>00625 curDir = dirStack.<a class="codeRef" href="qptrstack.html#pop">pop</a>(); <a name="l00626"></a>00626 curDirName = dirNameStack.<a class="codeRef" href="qvaluestack.html#pop">pop</a>(); <a name="l00627"></a>00627 root.<a class="codeRef" href="qdir.html#mkdir">mkdir</a>(curDirName); <a name="l00628"></a>00628 <a name="l00629"></a>00629 dirEntries = curDir-><a class="code" href="classKArchiveDirectory.html#ac5d2c6652a63c3bf4212b7e80ea3d036" title="Returns a list of sub-entries.">entries</a>(); <a name="l00630"></a>00630 <span class="keywordflow">for</span> ( it = dirEntries.begin(); it != dirEntries.end(); ++it ) { <a name="l00631"></a>00631 curEntry = curDir-><a class="code" href="classKArchiveDirectory.html#a2a27e00995e14f5bcdec377d2cad99c0" title="Returns the entry with the given name.">entry</a>(*it); <a name="l00632"></a>00632 <span class="keywordflow">if</span> (!curEntry-><a class="code" href="classKArchiveEntry.html#a93ac4953fd62469e44a375223ff5ceb7" title="Symlink if there is one.">symlink</a>().<a class="codeRef" href="qstring.html#isEmpty">isEmpty</a>()) { <a name="l00633"></a>00633 <span class="keyword">const</span> <a class="codeRef" href="qstring.html">QString</a> linkName = curDirName+<span class="charliteral">'/'</span>+curEntry-><a class="code" href="classKArchiveEntry.html#ad58bf4da148e9eeda1a45d8bccdcda0c" title="Name of the file without path.">name</a>(); <a name="l00634"></a>00634 kdDebug() << <span class="stringliteral">"symlink("</span> << curEntry-><a class="code" href="classKArchiveEntry.html#a93ac4953fd62469e44a375223ff5ceb7" title="Symlink if there is one.">symlink</a>() << <span class="charliteral">','</span> << linkName << <span class="charliteral">')'</span>; <a name="l00635"></a>00635 <span class="preprocessor">#ifdef Q_OS_UNIX</span> <a name="l00636"></a>00636 <span class="preprocessor"></span> <span class="keywordflow">if</span> (!::<a class="code" href="classKArchiveEntry.html#a93ac4953fd62469e44a375223ff5ceb7" title="Symlink if there is one.">symlink</a>(curEntry-><a class="code" href="classKArchiveEntry.html#a93ac4953fd62469e44a375223ff5ceb7" title="Symlink if there is one.">symlink</a>().<a class="codeRef" href="qstring.html#local8Bit">local8Bit</a>(), linkName.<a class="codeRef" href="qstring.html#local8Bit">local8Bit</a>())) { <a name="l00637"></a>00637 kdDebug() << <span class="stringliteral">"symlink("</span> << curEntry-><a class="code" href="classKArchiveEntry.html#a93ac4953fd62469e44a375223ff5ceb7" title="Symlink if there is one.">symlink</a>() << <span class="charliteral">','</span> << linkName << <span class="stringliteral">") failed:"</span> << strerror(errno); <a name="l00638"></a>00638 } <a name="l00639"></a>00639 <span class="preprocessor">#endif</span> <a name="l00640"></a>00640 <span class="preprocessor"></span> } <span class="keywordflow">else</span> { <a name="l00641"></a>00641 <span class="keywordflow">if</span> ( curEntry-><a class="code" href="classKArchiveEntry.html#acb45f3cb7a2fc6d317fa70f55dd0fb5c" title="Checks whether the entry is a file.">isFile</a>() ) { <a name="l00642"></a>00642 curFile = <span class="keyword">dynamic_cast<</span><a class="code" href="classKArchiveFile.html" title="Represents a file entry in a KArchive.">KArchiveFile</a>*<span class="keyword">></span>( curEntry ); <a name="l00643"></a>00643 <span class="keywordflow">if</span> (curFile) { <a name="l00644"></a>00644 fileList.append( curFile ); <a name="l00645"></a>00645 fileToDir.<a class="codeRef" href="qmap.html#insert">insert</a>( curFile-><a class="code" href="classKArchiveFile.html#abfaf4d36563072b66591956f21426716" title="Position of the data in the [uncompressed] archive.">position</a>(), curDirName ); <a name="l00646"></a>00646 } <a name="l00647"></a>00647 } <a name="l00648"></a>00648 <a name="l00649"></a>00649 <span class="keywordflow">if</span> ( curEntry-><a class="code" href="classKArchiveEntry.html#a292120b0b7b801ce6adef76986bcdec1" title="Checks whether the entry is a directory.">isDirectory</a>() ) <a name="l00650"></a>00650 <span class="keywordflow">if</span> ( recursiveCopy ) { <a name="l00651"></a>00651 <a class="code" href="classKArchiveDirectory.html" title="Represents a directory entry in a KArchive.">KArchiveDirectory</a> *ad = <span class="keyword">dynamic_cast<</span><a class="code" href="classKArchiveDirectory.html" title="Represents a directory entry in a KArchive.">KArchiveDirectory</a>*<span class="keyword">></span>( curEntry ); <a name="l00652"></a>00652 <span class="keywordflow">if</span> (ad) { <a name="l00653"></a>00653 dirStack.<a class="codeRef" href="qptrstack.html#push">push</a>( ad ); <a name="l00654"></a>00654 dirNameStack.<a class="codeRef" href="qvaluestack.html#push">push</a>( curDirName + <span class="stringliteral">"/"</span> + curEntry-><a class="code" href="classKArchiveEntry.html#ad58bf4da148e9eeda1a45d8bccdcda0c" title="Name of the file without path.">name</a>() ); <a name="l00655"></a>00655 } <a name="l00656"></a>00656 } <a name="l00657"></a>00657 } <a name="l00658"></a>00658 } <a name="l00659"></a>00659 } <span class="keywordflow">while</span> (!dirStack.<a class="codeRef" href="qptrstack.html#isEmpty">isEmpty</a>()); <a name="l00660"></a>00660 <a name="l00661"></a>00661 fileList.sort(); <span class="comment">// sort on m_pos, so we have a linear access</span> <a name="l00662"></a>00662 <a name="l00663"></a>00663 <a class="code" href="classKArchiveFile.html" title="Represents a file entry in a KArchive.">KArchiveFile</a>* f; <a name="l00664"></a>00664 <span class="keywordflow">for</span> ( f = fileList.first(); f; f = fileList.next() ) { <a name="l00665"></a>00665 <span class="keywordtype">int</span> pos = f-><a class="code" href="classKArchiveFile.html#abfaf4d36563072b66591956f21426716" title="Position of the data in the [uncompressed] archive.">position</a>(); <a name="l00666"></a>00666 f-><a class="code" href="classKArchiveFile.html#a67884151c4025dbcad78c7b781f720de" title="Extracts the file to the directory dest.">copyTo</a>( fileToDir[pos] ); <a name="l00667"></a>00667 } <a name="l00668"></a>00668 } <a name="l00669"></a>00669 <a name="l00670"></a>00670 <span class="keywordtype">void</span> KArchive::virtual_hook( <span class="keywordtype">int</span> <span class="keywordtype">id</span>, <span class="keywordtype">void</span>* data ) <a name="l00671"></a>00671 { <a name="l00672"></a>00672 <span class="keywordflow">switch</span> (<span class="keywordtype">id</span>) { <a name="l00673"></a>00673 <span class="keywordflow">case</span> VIRTUAL_WRITE_DATA: { <a name="l00674"></a>00674 WriteDataParams* params = <span class="keyword">reinterpret_cast<</span>WriteDataParams *<span class="keyword">></span>(data); <a name="l00675"></a>00675 params->retval = writeData_impl( params->data, params->size ); <a name="l00676"></a>00676 <span class="keywordflow">break</span>; <a name="l00677"></a>00677 } <a name="l00678"></a>00678 <span class="keywordflow">case</span> VIRTUAL_WRITE_SYMLINK: { <a name="l00679"></a>00679 WriteSymlinkParams *params = <span class="keyword">reinterpret_cast<</span>WriteSymlinkParams *<span class="keyword">></span>(data); <a name="l00680"></a>00680 params->retval = writeSymLink_impl(*params->name,*params->target, <a name="l00681"></a>00681 *params->user,*params->group,params->perm, <a name="l00682"></a>00682 params->atime,params->mtime,params->ctime); <a name="l00683"></a>00683 <span class="keywordflow">break</span>; <a name="l00684"></a>00684 } <a name="l00685"></a>00685 <span class="keywordflow">case</span> VIRTUAL_WRITE_DIR: { <a name="l00686"></a>00686 WriteDirParams *params = <span class="keyword">reinterpret_cast<</span>WriteDirParams *<span class="keyword">></span>(data); <a name="l00687"></a>00687 params->retval = writeDir_impl(*params->name,*params->user, <a name="l00688"></a>00688 *params->group,params->perm, <a name="l00689"></a>00689 params->atime,params->mtime,params->ctime); <a name="l00690"></a>00690 <span class="keywordflow">break</span>; <a name="l00691"></a>00691 } <a name="l00692"></a>00692 <span class="keywordflow">case</span> VIRTUAL_WRITE_FILE: { <a name="l00693"></a>00693 WriteFileParams *params = <span class="keyword">reinterpret_cast<</span>WriteFileParams *<span class="keyword">></span>(data); <a name="l00694"></a>00694 params->retval = writeFile_impl(*params->name,*params->user, <a name="l00695"></a>00695 *params->group,params->size,params->perm, <a name="l00696"></a>00696 params->atime,params->mtime,params->ctime, <a name="l00697"></a>00697 params->data); <a name="l00698"></a>00698 <span class="keywordflow">break</span>; <a name="l00699"></a>00699 } <a name="l00700"></a>00700 <span class="keywordflow">case</span> VIRTUAL_PREPARE_WRITING: { <a name="l00701"></a>00701 PrepareWritingParams *params = <span class="keyword">reinterpret_cast<</span>PrepareWritingParams *<span class="keyword">></span>(data); <a name="l00702"></a>00702 params->retval = prepareWriting_impl(*params->name,*params->user, <a name="l00703"></a>00703 *params->group,params->size,params->perm, <a name="l00704"></a>00704 params->atime,params->mtime,params->ctime); <a name="l00705"></a>00705 <span class="keywordflow">break</span>; <a name="l00706"></a>00706 } <a name="l00707"></a>00707 <span class="keywordflow">default</span>: <a name="l00708"></a>00708 <span class="comment">/*BASE::virtual_hook( id, data )*/</span>; <a name="l00709"></a>00709 }<span class="comment">/*end switch*/</span> <a name="l00710"></a>00710 } <a name="l00711"></a>00711 <a name="l00712"></a>00712 <span class="keywordtype">void</span> KArchiveEntry::virtual_hook( <span class="keywordtype">int</span>, <span class="keywordtype">void</span>* ) <a name="l00713"></a>00713 { <span class="comment">/*BASE::virtual_hook( id, data );*/</span> } <a name="l00714"></a>00714 <a name="l00715"></a>00715 <span class="keywordtype">void</span> KArchiveFile::virtual_hook( <span class="keywordtype">int</span> <span class="keywordtype">id</span>, <span class="keywordtype">void</span>* data ) <a name="l00716"></a>00716 { KArchiveEntry::virtual_hook( <span class="keywordtype">id</span>, data ); } <a name="l00717"></a>00717 <a name="l00718"></a>00718 <span class="keywordtype">void</span> KArchiveDirectory::virtual_hook( <span class="keywordtype">int</span> <span class="keywordtype">id</span>, <span class="keywordtype">void</span>* data ) <a name="l00719"></a>00719 { KArchiveEntry::virtual_hook( <span class="keywordtype">id</span>, data ); } </pre></div></div> </div> </div></div> </td> </tr> <tr> <td valign="top" id="leftmenu" width="25%"> <a name="navigation"></a> <div class="menu_box"><h2>kio/kio</h2> <div class="nav_list"> <ul><li><a href="index.html">Main Page</a></li><li><a href="modules.html">Modules</a></li><li><a href="namespaces.html">Namespace List</a></li><li><a href="hierarchy.html">Class Hierarchy</a></li><li><a href="classes.html">Alphabetical List</a></li><li><a href="annotated.html">Class List</a></li><li><a href="files.html">File List</a></li><li><a href="namespacemembers.html">Namespace Members</a></li><li><a href="functions.html">Class Members</a></li><li><a href="pages.html">Related Pages</a></li></ul> <!-- <h2>Class Picker</h2> <div style="text-align: center;"> <form name="guideform"> <select name="guidelinks" style="width:100%;" onChange="window.location=document.guideform.guidelinks.options[document.guideform.guidelinks.selectedIndex].value"> <option value="annotated.html">-- Choose --</option> <option value="classKACL.html">kacl</option>, <option value="classKAr.html">kar</option>, <option value="classKArchive.html">karchive</option>, <option value="classKArchiveDirectory.html">karchivedirectory</option>, <option value="classKArchiveEntry.html">karchiveentry</option>, <option value="classKArchiveFile.html">karchivefile</option>, <option value="classKAutoMount.html">kautomount</option>, <option value="classKAutoUnmount.html">kautounmount</option>, <option value="classKDataTool.html">kdatatool</option>, <option value="classKDataToolAction.html">kdatatoolaction</option>, <option value="classKDataToolInfo.html">kdatatoolinfo</option>, <option value="classKDCOPServiceStarter.html">kdcopservicestarter</option>, <option value="classKDEDesktopMimeType.html">kdedesktopmimetype</option>, <option value="classKDirLister.html">kdirlister</option>, <option value="classKDirNotify.html">kdirnotify</option>, <option value="classKDirWatch.html">kdirwatch</option>, <option value="classKEMailSettings.html">kemailsettings</option>, <option value="classKExecMimeType.html">kexecmimetype</option>, <option value="classKFileFilter.html">kfilefilter</option>, <option value="classKFileItem.html">kfileitem</option>, <option value="classKFileMetaInfo.html">kfilemetainfo</option>, <option value="classKFileMetaInfoGroup.html">kfilemetainfogroup</option>, <option value="classKFileMetaInfoItem.html">kfilemetainfoitem</option>, <option value="classKFileMimeTypeInfo.html">kfilemimetypeinfo</option>, <option value="classKFileMimeTypeInfo_1_1GroupInfo.html">kfilemimetypeinfo::groupinfo</option>, <option value="classKFileMimeTypeInfo_1_1ItemInfo.html">kfilemimetypeinfo::iteminfo</option>, <option value="classKFilePlugin.html">kfileplugin</option>, <option value="classKFileShare.html">kfileshare</option>, <option value="classKFilterBase.html">kfilterbase</option>, <option value="classKFilterDev.html">kfilterdev</option>, <option value="classKFolderType.html">kfoldertype</option>, <option value="classKImageIO.html">kimageio</option>, <option value="classKIO_1_1AuthInfo.html">kio::authinfo</option>, <option value="classKIO_1_1ChmodJob.html">kio::chmodjob</option>, <option value="classKIO_1_1Connection.html">kio::connection</option>, <option value="classKIO_1_1CopyJob.html">kio::copyjob</option>, <option value="classKIO_1_1DataProtocol.html">kio::dataprotocol</option>, <option value="classKIO_1_1DataSlave.html">kio::dataslave</option>, <option value="classKIO_1_1DavJob.html">kio::davjob</option>, <option value="classKIO_1_1DeleteJob.html">kio::deletejob</option>, <option value="classKIO_1_1FileCopyJob.html">kio::filecopyjob</option>, <option value="classKIO_1_1ForwardingSlaveBase.html">kio::forwardingslavebase</option>, <option value="classKIO_1_1Job.html">kio::job</option>, <option value="classKIO_1_1ListJob.html">kio::listjob</option>, <option value="classKIO_1_1MetaData.html">kio::metadata</option>, <option value="classKIO_1_1MetaInfoJob.html">kio::metainfojob</option>, <option value="classKIO_1_1MimetypeJob.html">kio::mimetypejob</option>, <option value="classKIO_1_1MkdirJob.html">kio::mkdirjob</option>, <option value="classKIO_1_1MultiGetJob.html">kio::multigetjob</option>, <option value="classKIO_1_1NetAccess.html">kio::netaccess</option>, <option value="classKIO_1_1NetRC.html">kio::netrc</option>, <option value="classKIO_1_1PasswordDialog.html">kio::passworddialog</option>, <option value="classKIO_1_1PreviewJob.html">kio::previewjob</option>, <option value="classKIO_1_1ProgressBase.html">kio::progressbase</option>, <option value="classKIO_1_1RenameDlg.html">kio::renamedlg</option>, <option value="classKIO_1_1Scheduler.html">kio::scheduler</option>, <option value="classKIO_1_1SimpleJob.html">kio::simplejob</option>, <option value="classKIO_1_1Slave.html">kio::slave</option>, <option value="classKIO_1_1SlaveBase.html">kio::slavebase</option>, <option value="classKIO_1_1SlaveConfig.html">kio::slaveconfig</option>, <option value="classKIO_1_1SlaveInterface.html">kio::slaveinterface</option>, <option value="classKIO_1_1StatJob.html">kio::statjob</option>, <option value="classKIO_1_1StatusbarProgress.html">kio::statusbarprogress</option>, <option value="classKIO_1_1StoredTransferJob.html">kio::storedtransferjob</option>, <option value="classKIO_1_1TCPSlaveBase.html">kio::tcpslavebase</option>, <option value="classKIO_1_1TransferJob.html">kio::transferjob</option>, <option value="classKLimitedIODevice.html">klimitediodevice</option>, <option value="classKMimeMagic.html">kmimemagic</option>, <option value="classKMimeMagicResult.html">kmimemagicresult</option>, <option value="classKMimeType.html">kmimetype</option>, <option value="classKMimeTypeChooser.html">kmimetypechooser</option>, <option value="classKMimeTypeChooserDialog.html">kmimetypechooserdialog</option>, <option value="classKMimeTypeResolver.html">kmimetyperesolver</option>, <option value="classKNFSShare.html">knfsshare</option>, <option value="classKOCRDialog.html">kocrdialog</option>, <option value="classKOCRDialogFactory.html">kocrdialogfactory</option>, <option value="classKOpenWithHandler.html">kopenwithhandler</option>, <option value="classKProtocolInfo.html">kprotocolinfo</option>, <option value="classKProtocolManager.html">kprotocolmanager</option>, <option value="classKRemoteEncoding.html">kremoteencoding</option>, <option value="classKRun.html">krun</option>, <option value="classKSambaShare.html">ksambashare</option>, <option value="classKScanDialog.html">kscandialog</option>, <option value="classKScanDialogFactory.html">kscandialogfactory</option>, <option value="classKService.html">kservice</option>, <option value="classKServiceGroup.html">kservicegroup</option>, <option value="classKServiceOffer.html">kserviceoffer</option>, <option value="classKServiceType.html">kservicetype</option>, <option value="classKServiceTypeProfile.html">kservicetypeprofile</option>, <option value="classKShellCompletion.html">kshellcompletion</option>, <option value="classKShred.html">kshred</option>, <option value="classKSimpleFileFilter.html">ksimplefilefilter</option>, <option value="classKTar.html">ktar</option>, <option value="classKTrader.html">ktrader</option>, <option value="classKURIFilter.html">kurifilter</option>, <option value="classKURIFilterData.html">kurifilterdata</option>, <option value="classKURIFilterPlugin.html">kurifilterplugin</option>, <option value="classKURIFilterPluginList.html">kurifilterpluginlist</option>, <option value="classKURLCompletion.html">kurlcompletion</option>, <option value="classKURLPixmapProvider.html">kurlpixmapprovider</option>, <option value="classKZip.html">kzip</option>, <option value="classObserver.html">observer</option>, <option value="classRenameDlgPlugin.html">renamedlgplugin</option>, <option value="classThumbCreator.html">thumbcreator</option>, </select> </form> </div> --> </div></div> <div class="menu_box"><h2>API Dox</h2> <div class="nav_list"> <ul> <li><a href="../../../arts/html/index.html">arts</a></li><li><a href="../../../dcop/html/index.html">dcop</a></li><li><a href="../../../dnssd/html/index.html">dnssd</a></li><li><a href="../../../interfaces/html/index.html">interfaces</a></li><li> <a href="../../../interfaces/kimproxy/interface/html/index.html">interface</a></li><li> <a href="../../../interfaces/kimproxy/library/html/index.html">library</a></li><li> <a href="../../../interfaces/kspeech/html/index.html">kspeech</a></li><li> <a href="../../../interfaces/ktexteditor/html/index.html">ktexteditor</a></li><li><a href="../../../kabc/html/index.html">kabc</a></li><li><a href="../../../kate/html/index.html">kate</a></li><li><a href="../../../kcmshell/html/index.html">kcmshell</a></li><li><a href="../../../kdecore/html/index.html">kdecore</a></li><li><a href="../../../kded/html/index.html">kded</a></li><li><a href="../../../kdefx/html/index.html">kdefx</a></li><li><a href="../../../kdeprint/html/index.html">kdeprint</a></li><li><a href="../../../kdesu/html/index.html">kdesu</a></li><li><a href="../../../kdeui/html/index.html">kdeui</a></li><li><a href="../../../kdoctools/html/index.html">kdoctools</a></li><li><a href="../../../khtml/html/index.html">khtml</a></li><li><a href="../../../kimgio/html/index.html">kimgio</a></li><li><a href="../../../kinit/html/index.html">kinit</a></li><li><a href="../../../kio/html/index.html">kio</a></li><li> <a href="../../../kio/bookmarks/html/index.html">bookmarks</a></li><li> <a href="../../../kio/httpfilter/html/index.html">httpfilter</a></li><li> <a href="../../../kio/kfile/html/index.html">kfile</a></li><li> <a href="../../../kio/kio/html/index.html">kio</a></li><li> <a href="../../../kio/kioexec/html/index.html">kioexec</a></li><li> <a href="../../../kio/kpasswdserver/html/index.html">kpasswdserver</a></li><li> <a href="../../../kio/kssl/html/index.html">kssl</a></li><li><a href="../../../kioslave/html/index.html">kioslave</a></li><li> <a href="../../../kioslave/http/html/index.html">http</a></li><li><a href="../../../kjs/html/index.html">kjs</a></li><li><a href="../../../kmdi/html/index.html">kmdi</a></li><li> <a href="../../../kmdi/kmdi/html/index.html">kmdi</a></li><li><a href="../../../knewstuff/html/index.html">knewstuff</a></li><li><a href="../../../kparts/html/index.html">kparts</a></li><li><a href="../../../kresources/html/index.html">kresources</a></li><li><a href="../../../kspell2/html/index.html">kspell2</a></li><li><a href="../../../kunittest/html/index.html">kunittest</a></li><li><a href="../../../kutils/html/index.html">kutils</a></li><li><a href="../../../kwallet/html/index.html">kwallet</a></li><li><a href="../../../libkmid/html/index.html">libkmid</a></li><li><a href="../../../libkscreensaver/html/index.html">libkscreensaver</a></li> </ul></div></div> </td> </tr> </table> <span class="doNotDisplay"> <a href="http://www.kde.org/" accesskey="8">KDE Home</a> | <a href="http://accessibility.kde.org/" accesskey="9">KDE Accessibility Home</a> | <a href="http://www.kde.org/media/accesskeys.php" accesskey="0">Description of Access Keys</a> </span> <div style="height: 8px"></div> <div id="footer"> <div id="footer_left"> Maintained by <a href="mailto:groot@kde.org">Adriaan de Groot</a> and <a href="mailto:winter@kde.org">Allen Winter</a>. <br/> KDE and K Desktop Environment are trademarks of <a href="http://www.kde.org/areas/kde-ev/" title="Homepage of the KDE non-profit Organization">KDE e.V.</a> | <a href="http://www.kde.org/contact/impressum.php">Legal</a> </div> <div id="footer_right"><img src="/media/images/footer_right.png" style="margin: 0px" alt="" /></div> </div> <!-- WARNING: DO NOT SEND MAIL TO THE FOLLOWING EMAIL ADDRESS! YOU WILL BE BLOCKED INSTANTLY AND PERMANENTLY! <a href="mailto:aaaatrap-425acc3b5374943f@kde.org">Block me</a> WARNING END --> </body> </html>