Projet

Général

Profil

Révision 30d5b9c5

Ajouté par Mathieu Schiano Di Schiabica il y a environ 8 ans

Update to 7.42

Voir les différences:

drupal7/modules/system/system.tar.inc
30 30
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 31
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 32
 *
33
 *
34
 * @category    File_Formats
35
 * @package     Archive_Tar
36
 * @author      Vincent Blavet <vincent@phpconcept.net>
37
 * @copyright   1997-2008 The Authors
38
 * @license     http://www.opensource.org/licenses/bsd-license.php New BSD License
39
 * @version     CVS: Id: Tar.php,v 1.43 2008/10/30 17:58:42 dufuz Exp
40
 * @link        http://pear.php.net/package/Archive_Tar
33
 * @category  File_Formats
34
 * @package   Archive_Tar
35
 * @author    Vincent Blavet <vincent@phpconcept.net>
36
 * @copyright 1997-2010 The Authors
37
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
38
 * @version   CVS: $Id$
39
 * @link      http://pear.php.net/package/Archive_Tar
40
 */
41

  
42
 /**
43
 * Note on Drupal 8 porting.
44
 * This file origin is Tar.php, release 1.4.0 (stable) with some code
45
 * from PEAR.php, release 1.9.5 (stable) both at http://pear.php.net.
46
 * To simplify future porting from pear of this file, you should not
47
 * do cosmetic or other non significant changes to this file.
48
 * The following changes have been done:
49
 *  Added namespace Drupal\Core\Archiver.
50
 *  Removed require_once 'PEAR.php'.
51
 *  Added defintion of OS_WINDOWS taken from PEAR.php.
52
 *  Renamed class to ArchiveTar.
53
 *  Removed extends PEAR from class.
54
 *  Removed call parent:: __construct().
55
 *  Changed PEAR::loadExtension($extname) to this->loadExtension($extname).
56
 *  Added function loadExtension() taken from PEAR.php.
57
 *  Changed all calls of unlink() to drupal_unlink().
58
 *  Changed $this->error_object = &$this->raiseError($p_message)
59
 *  to throw new \Exception($p_message).
60
 */
61

  
62
 /**
63
 * Note on Drupal 7 backporting from Drupal 8.
64
 * File origin is core/lib/Drupal/Core/Archiver/ArchiveTar.php from Drupal 8.
65
 * The following changes have been done:
66
 *  Removed namespace Drupal\Core\Archiver.
67
 *  Renamed class to Archive_Tar.
68
 *  Changed \Exception to Exception.
41 69
 */
42 70

  
43
//require_once 'PEAR.php';
44
//
45
//
46
define ('ARCHIVE_TAR_ATT_SEPARATOR', 90001);
47
define ('ARCHIVE_TAR_END_BLOCK', pack("a512", ''));
71

  
72
// Drupal removal require_once 'PEAR.php'.
73

  
74
// Drupal addition OS_WINDOWS as defined in PEAR.php.
75
if (substr(PHP_OS, 0, 3) == 'WIN') {
76
    define('OS_WINDOWS', true);
77
} else {
78
    define('OS_WINDOWS', false);
79
}
80

  
81
define('ARCHIVE_TAR_ATT_SEPARATOR', 90001);
82
define('ARCHIVE_TAR_END_BLOCK', pack("a512", ''));
83

  
84
if (!function_exists('gzopen') && function_exists('gzopen64')) {
85
    function gzopen($filename, $mode, $use_include_path = 0)
86
    {
87
        return gzopen64($filename, $mode, $use_include_path);
88
    }
89
}
90

  
91
if (!function_exists('gztell') && function_exists('gztell64')) {
92
    function gztell($zp)
93
    {
94
        return gztell64($zp);
95
    }
96
}
97

  
98
if (!function_exists('gzseek') && function_exists('gzseek64')) {
99
    function gzseek($zp, $offset, $whence = SEEK_SET)
100
    {
101
        return gzseek64($zp, $offset, $whence);
102
    }
103
}
48 104

  
49 105
/**
50
* Creates a (compressed) Tar archive
51
*
52
* @author   Vincent Blavet <vincent@phpconcept.net>
53
* @version  Revision: 1.43
54
* @license  http://www.opensource.org/licenses/bsd-license.php New BSD License
55
* @package  Archive_Tar
56
*/
57
class Archive_Tar // extends PEAR
106
 * Creates a (compressed) Tar archive
107
 *
108
 * @package Archive_Tar
109
 * @author  Vincent Blavet <vincent@phpconcept.net>
110
 * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
111
 * @version $Revision$
112
 */
113
// Drupal change class Archive_Tar extends PEAR.
114
class Archive_Tar
58 115
{
59 116
    /**
60
    * @var string Name of the Tar
61
    */
62
    var $_tarname='';
117
     * @var string Name of the Tar
118
     */
119
    public $_tarname = '';
63 120

  
64 121
    /**
65
    * @var boolean if true, the Tar file will be gzipped
66
    */
67
    var $_compress=false;
122
     * @var boolean if true, the Tar file will be gzipped
123
     */
124
    public $_compress = false;
68 125

  
69 126
    /**
70
    * @var string Type of compression : 'none', 'gz' or 'bz2'
71
    */
72
    var $_compress_type='none';
127
     * @var string Type of compression : 'none', 'gz', 'bz2' or 'lzma2'
128
     */
129
    public $_compress_type = 'none';
73 130

  
74 131
    /**
75
    * @var string Explode separator
76
    */
77
    var $_separator=' ';
132
     * @var string Explode separator
133
     */
134
    public $_separator = ' ';
78 135

  
79 136
    /**
80
    * @var file descriptor
81
    */
82
    var $_file=0;
137
     * @var file descriptor
138
     */
139
    public $_file = 0;
83 140

  
84 141
    /**
85
    * @var string Local Tar name of a remote Tar (http:// or ftp://)
86
    */
87
    var $_temp_tarname='';
142
     * @var string Local Tar name of a remote Tar (http:// or ftp://)
143
     */
144
    public $_temp_tarname = '';
88 145

  
89
    // {{{ constructor
90 146
    /**
91
    * Archive_Tar Class constructor. This flavour of the constructor only
92
    * declare a new Archive_Tar object, identifying it by the name of the
93
    * tar file.
94
    * If the compress argument is set the tar will be read or created as a
95
    * gzip or bz2 compressed TAR file.
96
    *
97
    * @param    string  $p_tarname  The name of the tar archive to create
98
    * @param    string  $p_compress can be null, 'gz' or 'bz2'. This
99
    *                   parameter indicates if gzip or bz2 compression
100
    *                   is required.  For compatibility reason the
101
    *                   boolean value 'true' means 'gz'.
102
    * @access public
103
    */
104
//    function Archive_Tar($p_tarname, $p_compress = null)
105
    function __construct($p_tarname, $p_compress = null)
147
     * @var string regular expression for ignoring files or directories
148
     */
149
    public $_ignore_regexp = '';
150

  
151
    /**
152
     * @var object PEAR_Error object
153
     */
154
    public $error_object = null;
155

  
156
    /**
157
     * Archive_Tar Class constructor. This flavour of the constructor only
158
     * declare a new Archive_Tar object, identifying it by the name of the
159
     * tar file.
160
     * If the compress argument is set the tar will be read or created as a
161
     * gzip or bz2 compressed TAR file.
162
     *
163
     * @param string $p_tarname The name of the tar archive to create
164
     * @param string $p_compress can be null, 'gz', 'bz2' or 'lzma2'. This
165
     *               parameter indicates if gzip, bz2 or lzma2 compression
166
     *               is required.  For compatibility reason the
167
     *               boolean value 'true' means 'gz'.
168
     *
169
     * @return bool
170
     */
171
    public function __construct($p_tarname, $p_compress = null)
106 172
    {
107
//        $this->PEAR();
173
        // Drupal removal parent::__construct().
174

  
108 175
        $this->_compress = false;
109 176
        $this->_compress_type = 'none';
110 177
        if (($p_compress === null) || ($p_compress == '')) {
......
116 183
                    if ($data == "\37\213") {
117 184
                        $this->_compress = true;
118 185
                        $this->_compress_type = 'gz';
119
                    // No sure it's enought for a magic code ....
186
                        // No sure it's enought for a magic code ....
120 187
                    } elseif ($data == "BZ") {
121 188
                        $this->_compress = true;
122 189
                        $this->_compress_type = 'bz2';
190
                    } elseif (file_get_contents($p_tarname, false, null, 1, 4) == '7zXZ') {
191
                        $this->_compress = true;
192
                        $this->_compress_type = 'lzma2';
123 193
                    }
124 194
                }
125 195
            } else {
......
129 199
                    $this->_compress = true;
130 200
                    $this->_compress_type = 'gz';
131 201
                } elseif ((substr($p_tarname, -3) == 'bz2') ||
132
                          (substr($p_tarname, -2) == 'bz')) {
202
                    (substr($p_tarname, -2) == 'bz')
203
                ) {
133 204
                    $this->_compress = true;
134 205
                    $this->_compress_type = 'bz2';
206
                } else {
207
                    if (substr($p_tarname, -2) == 'xz') {
208
                        $this->_compress = true;
209
                        $this->_compress_type = 'lzma2';
210
                    }
135 211
                }
136 212
            }
137 213
        } else {
138 214
            if (($p_compress === true) || ($p_compress == 'gz')) {
139 215
                $this->_compress = true;
140 216
                $this->_compress_type = 'gz';
141
            } else if ($p_compress == 'bz2') {
142
                $this->_compress = true;
143
                $this->_compress_type = 'bz2';
144 217
            } else {
145
                die("Unsupported compression type '$p_compress'\n".
146
                    "Supported types are 'gz' and 'bz2'.\n");
147
                return false;
218
                if ($p_compress == 'bz2') {
219
                    $this->_compress = true;
220
                    $this->_compress_type = 'bz2';
221
                } else {
222
                    if ($p_compress == 'lzma2') {
223
                        $this->_compress = true;
224
                        $this->_compress_type = 'lzma2';
225
                    } else {
226
                        $this->_error(
227
                            "Unsupported compression type '$p_compress'\n" .
228
                            "Supported types are 'gz', 'bz2' and 'lzma2'.\n"
229
                        );
230
                        return false;
231
                    }
232
                }
148 233
            }
149 234
        }
150 235
        $this->_tarname = $p_tarname;
151
        if ($this->_compress) { // assert zlib or bz2 extension support
152
            if ($this->_compress_type == 'gz')
236
        if ($this->_compress) { // assert zlib or bz2 or xz extension support
237
            if ($this->_compress_type == 'gz') {
153 238
                $extname = 'zlib';
154
            else if ($this->_compress_type == 'bz2')
155
                $extname = 'bz2';
239
            } else {
240
                if ($this->_compress_type == 'bz2') {
241
                    $extname = 'bz2';
242
                } else {
243
                    if ($this->_compress_type == 'lzma2') {
244
                        $extname = 'xz';
245
                    }
246
                }
247
            }
156 248

  
157 249
            if (!extension_loaded($extname)) {
158
//                PEAR::loadExtension($extname);
250
                // Drupal change PEAR::loadExtension($extname).
159 251
                $this->loadExtension($extname);
160 252
            }
161 253
            if (!extension_loaded($extname)) {
162
                die("The extension '$extname' couldn't be found.\n".
163
                    "Please make sure your version of PHP was built ".
164
                    "with '$extname' support.\n");
254
                $this->_error(
255
                    "The extension '$extname' couldn't be found.\n" .
256
                    "Please make sure your version of PHP was built " .
257
                    "with '$extname' support.\n"
258
                );
165 259
                return false;
166 260
            }
167 261
        }
168 262
    }
169
    // }}}
170 263

  
264
    public function __destruct()
265
    {
266
        $this->_close();
267
        // ----- Look for a local copy to delete
268
        if ($this->_temp_tarname != '') {
269
            @drupal_unlink($this->_temp_tarname);
270
        }
271
    }
272

  
273
    // Drupal addition from PEAR.php.
171 274
    /**
172 275
    * OS independent PHP extension load. Remember to take care
173 276
    * on the correct extension name for case sensitive OSes.
174
    * The function is the copy of PEAR::loadExtension().
175 277
    *
176 278
    * @param string $ext The extension name
177 279
    * @return bool Success or not on the dl() call
178 280
    */
179 281
    function loadExtension($ext)
180 282
    {
181
        if (!extension_loaded($ext)) {
182
            // if either returns true dl() will produce a FATAL error, stop that
183
            if ((ini_get('enable_dl') != 1) || (ini_get('safe_mode') == 1)) {
184
                return false;
185
            }
283
        if (extension_loaded($ext)) {
284
            return true;
285
        }
186 286

  
187
            if (OS_WINDOWS) {
188
                $suffix = '.dll';
189
            } elseif (PHP_OS == 'HP-UX') {
190
                $suffix = '.sl';
191
            } elseif (PHP_OS == 'AIX') {
192
                $suffix = '.a';
193
            } elseif (PHP_OS == 'OSX') {
194
                $suffix = '.bundle';
195
            } else {
196
                $suffix = '.so';
197
            }
287
        // if either returns true dl() will produce a FATAL error, stop that
288
        if (
289
            function_exists('dl') === false ||
290
            ini_get('enable_dl') != 1 ||
291
            ini_get('safe_mode') == 1
292
        ) {
293
            return false;
294
        }
198 295

  
199
            return @dl('php_'.$ext.$suffix) || @dl($ext.$suffix);
296
        if (OS_WINDOWS) {
297
            $suffix = '.dll';
298
        } elseif (PHP_OS == 'HP-UX') {
299
            $suffix = '.sl';
300
        } elseif (PHP_OS == 'AIX') {
301
            $suffix = '.a';
302
        } elseif (PHP_OS == 'OSX') {
303
            $suffix = '.bundle';
304
        } else {
305
            $suffix = '.so';
200 306
        }
201 307

  
202
        return true;
308
        return @dl('php_'.$ext.$suffix) || @dl($ext.$suffix);
203 309
    }
204 310

  
205 311

  
206
    // {{{ destructor
207
//    function _Archive_Tar()
208
    function __destruct()
209
    {
210
        $this->_close();
211
        // ----- Look for a local copy to delete
212
        if ($this->_temp_tarname != '')
213
            @drupal_unlink($this->_temp_tarname);
214
//        $this->_PEAR();
215
    }
216
    // }}}
217

  
218
    // {{{ create()
219 312
    /**
220
    * This method creates the archive file and add the files / directories
221
    * that are listed in $p_filelist.
222
    * If a file with the same name exist and is writable, it is replaced
223
    * by the new tar.
224
    * The method return false and a PEAR error text.
225
    * The $p_filelist parameter can be an array of string, each string
226
    * representing a filename or a directory name with their path if
227
    * needed. It can also be a single string with names separated by a
228
    * single blank.
229
    * For each directory added in the archive, the files and
230
    * sub-directories are also added.
231
    * See also createModify() method for more details.
232
    *
233
    * @param array  $p_filelist An array of filenames and directory names, or a
234
	*                           single string with names separated by a single
235
	*                           blank space.
236
    * @return                   true on success, false on error.
237
    * @see createModify()
238
    * @access public
239
    */
240
    function create($p_filelist)
313
     * This method creates the archive file and add the files / directories
314
     * that are listed in $p_filelist.
315
     * If a file with the same name exist and is writable, it is replaced
316
     * by the new tar.
317
     * The method return false and a PEAR error text.
318
     * The $p_filelist parameter can be an array of string, each string
319
     * representing a filename or a directory name with their path if
320
     * needed. It can also be a single string with names separated by a
321
     * single blank.
322
     * For each directory added in the archive, the files and
323
     * sub-directories are also added.
324
     * See also createModify() method for more details.
325
     *
326
     * @param array $p_filelist An array of filenames and directory names, or a
327
     *              single string with names separated by a single
328
     *              blank space.
329
     *
330
     * @return true on success, false on error.
331
     * @see    createModify()
332
     */
333
    public function create($p_filelist)
241 334
    {
242 335
        return $this->createModify($p_filelist, '', '');
243 336
    }
244
    // }}}
245 337

  
246
    // {{{ add()
247 338
    /**
248
    * This method add the files / directories that are listed in $p_filelist in
249
    * the archive. If the archive does not exist it is created.
250
    * The method return false and a PEAR error text.
251
    * The files and directories listed are only added at the end of the archive,
252
    * even if a file with the same name is already archived.
253
    * See also createModify() method for more details.
254
    *
255
    * @param array  $p_filelist An array of filenames and directory names, or a
256
	*                           single string with names separated by a single
257
	*                           blank space.
258
    * @return                   true on success, false on error.
259
    * @see createModify()
260
    * @access public
261
    */
262
    function add($p_filelist)
339
     * This method add the files / directories that are listed in $p_filelist in
340
     * the archive. If the archive does not exist it is created.
341
     * The method return false and a PEAR error text.
342
     * The files and directories listed are only added at the end of the archive,
343
     * even if a file with the same name is already archived.
344
     * See also createModify() method for more details.
345
     *
346
     * @param array $p_filelist An array of filenames and directory names, or a
347
     *              single string with names separated by a single
348
     *              blank space.
349
     *
350
     * @return true on success, false on error.
351
     * @see    createModify()
352
     * @access public
353
     */
354
    public function add($p_filelist)
263 355
    {
264 356
        return $this->addModify($p_filelist, '', '');
265 357
    }
266
    // }}}
267 358

  
268
    // {{{ extract()
269
    function extract($p_path='')
359
    /**
360
     * @param string $p_path
361
     * @param bool $p_preserve
362
     * @return bool
363
     */
364
    public function extract($p_path = '', $p_preserve = false)
270 365
    {
271
        return $this->extractModify($p_path, '');
366
        return $this->extractModify($p_path, '', $p_preserve);
272 367
    }
273
    // }}}
274 368

  
275
    // {{{ listContent()
276
    function listContent()
369
    /**
370
     * @return array|int
371
     */
372
    public function listContent()
277 373
    {
278 374
        $v_list_detail = array();
279 375

  
......
287 383

  
288 384
        return $v_list_detail;
289 385
    }
290
    // }}}
291 386

  
292
    // {{{ createModify()
293 387
    /**
294
    * This method creates the archive file and add the files / directories
295
    * that are listed in $p_filelist.
296
    * If the file already exists and is writable, it is replaced by the
297
    * new tar. It is a create and not an add. If the file exists and is
298
    * read-only or is a directory it is not replaced. The method return
299
    * false and a PEAR error text.
300
    * The $p_filelist parameter can be an array of string, each string
301
    * representing a filename or a directory name with their path if
302
    * needed. It can also be a single string with names separated by a
303
    * single blank.
304
    * The path indicated in $p_remove_dir will be removed from the
305
    * memorized path of each file / directory listed when this path
306
    * exists. By default nothing is removed (empty path '')
307
    * The path indicated in $p_add_dir will be added at the beginning of
308
    * the memorized path of each file / directory listed. However it can
309
    * be set to empty ''. The adding of a path is done after the removing
310
    * of path.
311
    * The path add/remove ability enables the user to prepare an archive
312
    * for extraction in a different path than the origin files are.
313
    * See also addModify() method for file adding properties.
314
    *
315
    * @param array  $p_filelist     An array of filenames and directory names,
316
	*                               or a single string with names separated by
317
	*                               a single blank space.
318
    * @param string $p_add_dir      A string which contains a path to be added
319
	*                               to the memorized path of each element in
320
	*                               the list.
321
    * @param string $p_remove_dir   A string which contains a path to be
322
	*                               removed from the memorized path of each
323
	*                               element in the list, when relevant.
324
    * @return boolean               true on success, false on error.
325
    * @access public
326
    * @see addModify()
327
    */
328
    function createModify($p_filelist, $p_add_dir, $p_remove_dir='')
388
     * This method creates the archive file and add the files / directories
389
     * that are listed in $p_filelist.
390
     * If the file already exists and is writable, it is replaced by the
391
     * new tar. It is a create and not an add. If the file exists and is
392
     * read-only or is a directory it is not replaced. The method return
393
     * false and a PEAR error text.
394
     * The $p_filelist parameter can be an array of string, each string
395
     * representing a filename or a directory name with their path if
396
     * needed. It can also be a single string with names separated by a
397
     * single blank.
398
     * The path indicated in $p_remove_dir will be removed from the
399
     * memorized path of each file / directory listed when this path
400
     * exists. By default nothing is removed (empty path '')
401
     * The path indicated in $p_add_dir will be added at the beginning of
402
     * the memorized path of each file / directory listed. However it can
403
     * be set to empty ''. The adding of a path is done after the removing
404
     * of path.
405
     * The path add/remove ability enables the user to prepare an archive
406
     * for extraction in a different path than the origin files are.
407
     * See also addModify() method for file adding properties.
408
     *
409
     * @param array $p_filelist An array of filenames and directory names,
410
     *                             or a single string with names separated by
411
     *                             a single blank space.
412
     * @param string $p_add_dir A string which contains a path to be added
413
     *                             to the memorized path of each element in
414
     *                             the list.
415
     * @param string $p_remove_dir A string which contains a path to be
416
     *                             removed from the memorized path of each
417
     *                             element in the list, when relevant.
418
     *
419
     * @return boolean true on success, false on error.
420
     * @see addModify()
421
     */
422
    public function createModify($p_filelist, $p_add_dir, $p_remove_dir = '')
329 423
    {
330 424
        $v_result = true;
331 425

  
332
        if (!$this->_openWrite())
426
        if (!$this->_openWrite()) {
333 427
            return false;
428
        }
334 429

  
335 430
        if ($p_filelist != '') {
336
            if (is_array($p_filelist))
431
            if (is_array($p_filelist)) {
337 432
                $v_list = $p_filelist;
338
            elseif (is_string($p_filelist))
433
            } elseif (is_string($p_filelist)) {
339 434
                $v_list = explode($this->_separator, $p_filelist);
340
            else {
435
            } else {
341 436
                $this->_cleanFile();
342 437
                $this->_error('Invalid file list');
343 438
                return false;
......
349 444
        if ($v_result) {
350 445
            $this->_writeFooter();
351 446
            $this->_close();
352
        } else
447
        } else {
353 448
            $this->_cleanFile();
449
        }
354 450

  
355 451
        return $v_result;
356 452
    }
357
    // }}}
358 453

  
359
    // {{{ addModify()
360 454
    /**
361
    * This method add the files / directories listed in $p_filelist at the
362
    * end of the existing archive. If the archive does not yet exists it
363
    * is created.
364
    * The $p_filelist parameter can be an array of string, each string
365
    * representing a filename or a directory name with their path if
366
    * needed. It can also be a single string with names separated by a
367
    * single blank.
368
    * The path indicated in $p_remove_dir will be removed from the
369
    * memorized path of each file / directory listed when this path
370
    * exists. By default nothing is removed (empty path '')
371
    * The path indicated in $p_add_dir will be added at the beginning of
372
    * the memorized path of each file / directory listed. However it can
373
    * be set to empty ''. The adding of a path is done after the removing
374
    * of path.
375
    * The path add/remove ability enables the user to prepare an archive
376
    * for extraction in a different path than the origin files are.
377
    * If a file/dir is already in the archive it will only be added at the
378
    * end of the archive. There is no update of the existing archived
379
    * file/dir. However while extracting the archive, the last file will
380
    * replace the first one. This results in a none optimization of the
381
    * archive size.
382
    * If a file/dir does not exist the file/dir is ignored. However an
383
    * error text is send to PEAR error.
384
    * If a file/dir is not readable the file/dir is ignored. However an
385
    * error text is send to PEAR error.
386
    *
387
    * @param array      $p_filelist     An array of filenames and directory
388
	*                                   names, or a single string with names
389
	*                                   separated by a single blank space.
390
    * @param string     $p_add_dir      A string which contains a path to be
391
	*                                   added to the memorized path of each
392
	*                                   element in the list.
393
    * @param string     $p_remove_dir   A string which contains a path to be
394
	*                                   removed from the memorized path of
395
	*                                   each element in the list, when
396
    *                                   relevant.
397
    * @return                           true on success, false on error.
398
    * @access public
399
    */
400
    function addModify($p_filelist, $p_add_dir, $p_remove_dir='')
455
     * This method add the files / directories listed in $p_filelist at the
456
     * end of the existing archive. If the archive does not yet exists it
457
     * is created.
458
     * The $p_filelist parameter can be an array of string, each string
459
     * representing a filename or a directory name with their path if
460
     * needed. It can also be a single string with names separated by a
461
     * single blank.
462
     * The path indicated in $p_remove_dir will be removed from the
463
     * memorized path of each file / directory listed when this path
464
     * exists. By default nothing is removed (empty path '')
465
     * The path indicated in $p_add_dir will be added at the beginning of
466
     * the memorized path of each file / directory listed. However it can
467
     * be set to empty ''. The adding of a path is done after the removing
468
     * of path.
469
     * The path add/remove ability enables the user to prepare an archive
470
     * for extraction in a different path than the origin files are.
471
     * If a file/dir is already in the archive it will only be added at the
472
     * end of the archive. There is no update of the existing archived
473
     * file/dir. However while extracting the archive, the last file will
474
     * replace the first one. This results in a none optimization of the
475
     * archive size.
476
     * If a file/dir does not exist the file/dir is ignored. However an
477
     * error text is send to PEAR error.
478
     * If a file/dir is not readable the file/dir is ignored. However an
479
     * error text is send to PEAR error.
480
     *
481
     * @param array $p_filelist An array of filenames and directory
482
     *                             names, or a single string with names
483
     *                             separated by a single blank space.
484
     * @param string $p_add_dir A string which contains a path to be
485
     *                             added to the memorized path of each
486
     *                             element in the list.
487
     * @param string $p_remove_dir A string which contains a path to be
488
     *                             removed from the memorized path of
489
     *                             each element in the list, when
490
     *                             relevant.
491
     *
492
     * @return true on success, false on error.
493
     */
494
    public function addModify($p_filelist, $p_add_dir, $p_remove_dir = '')
401 495
    {
402 496
        $v_result = true;
403 497

  
404
        if (!$this->_isArchive())
405
            $v_result = $this->createModify($p_filelist, $p_add_dir,
406
			                                $p_remove_dir);
407
        else {
408
            if (is_array($p_filelist))
498
        if (!$this->_isArchive()) {
499
            $v_result = $this->createModify(
500
                $p_filelist,
501
                $p_add_dir,
502
                $p_remove_dir
503
            );
504
        } else {
505
            if (is_array($p_filelist)) {
409 506
                $v_list = $p_filelist;
410
            elseif (is_string($p_filelist))
507
            } elseif (is_string($p_filelist)) {
411 508
                $v_list = explode($this->_separator, $p_filelist);
412
            else {
509
            } else {
413 510
                $this->_error('Invalid file list');
414 511
                return false;
415 512
            }
......
419 516

  
420 517
        return $v_result;
421 518
    }
422
    // }}}
423 519

  
424
    // {{{ addString()
425 520
    /**
426
    * This method add a single string as a file at the
427
    * end of the existing archive. If the archive does not yet exists it
428
    * is created.
429
    *
430
    * @param string     $p_filename     A string which contains the full
431
	*                                   filename path that will be associated
432
	*                                   with the string.
433
    * @param string     $p_string       The content of the file added in
434
	*                                   the archive.
435
    * @return                           true on success, false on error.
436
    * @access public
437
    */
438
    function addString($p_filename, $p_string)
521
     * This method add a single string as a file at the
522
     * end of the existing archive. If the archive does not yet exists it
523
     * is created.
524
     *
525
     * @param string $p_filename A string which contains the full
526
     *                           filename path that will be associated
527
     *                           with the string.
528
     * @param string $p_string The content of the file added in
529
     *                           the archive.
530
     * @param bool|int $p_datetime A custom date/time (unix timestamp)
531
     *                           for the file (optional).
532
     * @param array $p_params An array of optional params:
533
     *                               stamp => the datetime (replaces
534
     *                                   datetime above if it exists)
535
     *                               mode => the permissions on the
536
     *                                   file (600 by default)
537
     *                               type => is this a link?  See the
538
     *                                   tar specification for details.
539
     *                                   (default = regular file)
540
     *                               uid => the user ID of the file
541
     *                                   (default = 0 = root)
542
     *                               gid => the group ID of the file
543
     *                                   (default = 0 = root)
544
     *
545
     * @return true on success, false on error.
546
     */
547
    public function addString($p_filename, $p_string, $p_datetime = false, $p_params = array())
439 548
    {
549
        $p_stamp = @$p_params["stamp"] ? $p_params["stamp"] : ($p_datetime ? $p_datetime : time());
550
        $p_mode = @$p_params["mode"] ? $p_params["mode"] : 0600;
551
        $p_type = @$p_params["type"] ? $p_params["type"] : "";
552
        $p_uid = @$p_params["uid"] ? $p_params["uid"] : "";
553
        $p_gid = @$p_params["gid"] ? $p_params["gid"] : "";
440 554
        $v_result = true;
441 555

  
442 556
        if (!$this->_isArchive()) {
......
446 560
            $this->_close();
447 561
        }
448 562

  
449
        if (!$this->_openAppend())
563
        if (!$this->_openAppend()) {
450 564
            return false;
565
        }
451 566

  
452 567
        // Need to check the get back to the temporary file ? ....
453
        $v_result = $this->_addString($p_filename, $p_string);
568
        $v_result = $this->_addString($p_filename, $p_string, $p_datetime, $p_params);
454 569

  
455 570
        $this->_writeFooter();
456 571

  
......
458 573

  
459 574
        return $v_result;
460 575
    }
461
    // }}}
462 576

  
463
    // {{{ extractModify()
464 577
    /**
465
    * This method extract all the content of the archive in the directory
466
    * indicated by $p_path. When relevant the memorized path of the
467
    * files/dir can be modified by removing the $p_remove_path path at the
468
    * beginning of the file/dir path.
469
    * While extracting a file, if the directory path does not exists it is
470
    * created.
471
    * While extracting a file, if the file already exists it is replaced
472
    * without looking for last modification date.
473
    * While extracting a file, if the file already exists and is write
474
    * protected, the extraction is aborted.
475
    * While extracting a file, if a directory with the same name already
476
    * exists, the extraction is aborted.
477
    * While extracting a directory, if a file with the same name already
478
    * exists, the extraction is aborted.
479
    * While extracting a file/directory if the destination directory exist
480
    * and is write protected, or does not exist but can not be created,
481
    * the extraction is aborted.
482
    * If after extraction an extracted file does not show the correct
483
    * stored file size, the extraction is aborted.
484
    * When the extraction is aborted, a PEAR error text is set and false
485
    * is returned. However the result can be a partial extraction that may
486
    * need to be manually cleaned.
487
    *
488
    * @param string $p_path         The path of the directory where the
489
	*                               files/dir need to by extracted.
490
    * @param string $p_remove_path  Part of the memorized path that can be
491
	*                               removed if present at the beginning of
492
	*                               the file/dir path.
493
    * @return boolean               true on success, false on error.
494
    * @access public
495
    * @see extractList()
496
    */
497
    function extractModify($p_path, $p_remove_path)
578
     * This method extract all the content of the archive in the directory
579
     * indicated by $p_path. When relevant the memorized path of the
580
     * files/dir can be modified by removing the $p_remove_path path at the
581
     * beginning of the file/dir path.
582
     * While extracting a file, if the directory path does not exists it is
583
     * created.
584
     * While extracting a file, if the file already exists it is replaced
585
     * without looking for last modification date.
586
     * While extracting a file, if the file already exists and is write
587
     * protected, the extraction is aborted.
588
     * While extracting a file, if a directory with the same name already
589
     * exists, the extraction is aborted.
590
     * While extracting a directory, if a file with the same name already
591
     * exists, the extraction is aborted.
592
     * While extracting a file/directory if the destination directory exist
593
     * and is write protected, or does not exist but can not be created,
594
     * the extraction is aborted.
595
     * If after extraction an extracted file does not show the correct
596
     * stored file size, the extraction is aborted.
597
     * When the extraction is aborted, a PEAR error text is set and false
598
     * is returned. However the result can be a partial extraction that may
599
     * need to be manually cleaned.
600
     *
601
     * @param string $p_path The path of the directory where the
602
     *                               files/dir need to by extracted.
603
     * @param string $p_remove_path Part of the memorized path that can be
604
     *                               removed if present at the beginning of
605
     *                               the file/dir path.
606
     * @param boolean $p_preserve Preserve user/group ownership of files
607
     *
608
     * @return boolean true on success, false on error.
609
     * @see    extractList()
610
     */
611
    public function extractModify($p_path, $p_remove_path, $p_preserve = false)
498 612
    {
499 613
        $v_result = true;
500 614
        $v_list_detail = array();
501 615

  
502 616
        if ($v_result = $this->_openRead()) {
503
            $v_result = $this->_extractList($p_path, $v_list_detail,
504
			                                "complete", 0, $p_remove_path);
617
            $v_result = $this->_extractList(
618
                $p_path,
619
                $v_list_detail,
620
                "complete",
621
                0,
622
                $p_remove_path,
623
                $p_preserve
624
            );
505 625
            $this->_close();
506 626
        }
507 627

  
508 628
        return $v_result;
509 629
    }
510
    // }}}
511 630

  
512
    // {{{ extractInString()
513 631
    /**
514
    * This method extract from the archive one file identified by $p_filename.
515
    * The return value is a string with the file content, or NULL on error.
516
    * @param string $p_filename     The path of the file to extract in a string.
517
    * @return                       a string with the file content or NULL.
518
    * @access public
519
    */
520
    function extractInString($p_filename)
632
     * This method extract from the archive one file identified by $p_filename.
633
     * The return value is a string with the file content, or NULL on error.
634
     *
635
     * @param string $p_filename The path of the file to extract in a string.
636
     *
637
     * @return a string with the file content or NULL.
638
     */
639
    public function extractInString($p_filename)
521 640
    {
522 641
        if ($this->_openRead()) {
523 642
            $v_result = $this->_extractInString($p_filename);
524 643
            $this->_close();
525 644
        } else {
526
            $v_result = NULL;
645
            $v_result = null;
527 646
        }
528 647

  
529 648
        return $v_result;
530 649
    }
531
    // }}}
532 650

  
533
    // {{{ extractList()
534 651
    /**
535
    * This method extract from the archive only the files indicated in the
536
    * $p_filelist. These files are extracted in the current directory or
537
    * in the directory indicated by the optional $p_path parameter.
538
    * If indicated the $p_remove_path can be used in the same way as it is
539
    * used in extractModify() method.
540
    * @param array  $p_filelist     An array of filenames and directory names,
541
	*                               or a single string with names separated
542
	*                               by a single blank space.
543
    * @param string $p_path         The path of the directory where the
544
	*                               files/dir need to by extracted.
545
    * @param string $p_remove_path  Part of the memorized path that can be
546
	*                               removed if present at the beginning of
547
	*                               the file/dir path.
548
    * @return                       true on success, false on error.
549
    * @access public
550
    * @see extractModify()
551
    */
552
    function extractList($p_filelist, $p_path='', $p_remove_path='')
652
     * This method extract from the archive only the files indicated in the
653
     * $p_filelist. These files are extracted in the current directory or
654
     * in the directory indicated by the optional $p_path parameter.
655
     * If indicated the $p_remove_path can be used in the same way as it is
656
     * used in extractModify() method.
657
     *
658
     * @param array $p_filelist An array of filenames and directory names,
659
     *                               or a single string with names separated
660
     *                               by a single blank space.
661
     * @param string $p_path The path of the directory where the
662
     *                               files/dir need to by extracted.
663
     * @param string $p_remove_path Part of the memorized path that can be
664
     *                               removed if present at the beginning of
665
     *                               the file/dir path.
666
     * @param boolean $p_preserve Preserve user/group ownership of files
667
     *
668
     * @return true on success, false on error.
669
     * @see    extractModify()
670
     */
671
    public function extractList($p_filelist, $p_path = '', $p_remove_path = '', $p_preserve = false)
553 672
    {
554 673
        $v_result = true;
555 674
        $v_list_detail = array();
556 675

  
557
        if (is_array($p_filelist))
676
        if (is_array($p_filelist)) {
558 677
            $v_list = $p_filelist;
559
        elseif (is_string($p_filelist))
678
        } elseif (is_string($p_filelist)) {
560 679
            $v_list = explode($this->_separator, $p_filelist);
561
        else {
680
        } else {
562 681
            $this->_error('Invalid string list');
563 682
            return false;
564 683
        }
565 684

  
566 685
        if ($v_result = $this->_openRead()) {
567
            $v_result = $this->_extractList($p_path, $v_list_detail, "partial",
568
			                                $v_list, $p_remove_path);
686
            $v_result = $this->_extractList(
687
                $p_path,
688
                $v_list_detail,
689
                "partial",
690
                $v_list,
691
                $p_remove_path,
692
                $p_preserve
693
            );
569 694
            $this->_close();
570 695
        }
571 696

  
572 697
        return $v_result;
573 698
    }
574
    // }}}
575 699

  
576
    // {{{ setAttribute()
577 700
    /**
578
    * This method set specific attributes of the archive. It uses a variable
579
    * list of parameters, in the format attribute code + attribute values :
580
    * $arch->setAttribute(ARCHIVE_TAR_ATT_SEPARATOR, ',');
581
    * @param mixed $argv            variable list of attributes and values
582
    * @return                       true on success, false on error.
583
    * @access public
584
    */
585
    function setAttribute()
701
     * This method set specific attributes of the archive. It uses a variable
702
     * list of parameters, in the format attribute code + attribute values :
703
     * $arch->setAttribute(ARCHIVE_TAR_ATT_SEPARATOR, ',');
704
     *
705
     * @return true on success, false on error.
706
     */
707
    public function setAttribute()
586 708
    {
587 709
        $v_result = true;
588 710

  
......
592 714
        }
593 715

  
594 716
        // ----- Get the arguments
595
        $v_att_list = &func_get_args();
717
        $v_att_list = & func_get_args();
596 718

  
597 719
        // ----- Read the attributes
598
        $i=0;
599
        while ($i<$v_size) {
720
        $i = 0;
721
        while ($i < $v_size) {
600 722

  
601 723
            // ----- Look for next option
602 724
            switch ($v_att_list[$i]) {
603 725
                // ----- Look for options that request a string value
604 726
                case ARCHIVE_TAR_ATT_SEPARATOR :
605 727
                    // ----- Check the number of parameters
606
                    if (($i+1) >= $v_size) {
607
                        $this->_error('Invalid number of parameters for '
608
						              .'attribute ARCHIVE_TAR_ATT_SEPARATOR');
728
                    if (($i + 1) >= $v_size) {
729
                        $this->_error(
730
                            'Invalid number of parameters for '
731
                            . 'attribute ARCHIVE_TAR_ATT_SEPARATOR'
732
                        );
609 733
                        return false;
610 734
                    }
611 735

  
612 736
                    // ----- Get the value
613
                    $this->_separator = $v_att_list[$i+1];
737
                    $this->_separator = $v_att_list[$i + 1];
614 738
                    $i++;
615
                break;
739
                    break;
616 740

  
617 741
                default :
618
                    $this->_error('Unknow attribute code '.$v_att_list[$i].'');
742
                    $this->_error('Unknown attribute code ' . $v_att_list[$i] . '');
619 743
                    return false;
620 744
            }
621 745

  
......
625 749

  
626 750
        return $v_result;
627 751
    }
628
    // }}}
629 752

  
630
    // {{{ _error()
631
    function _error($p_message)
753
    /**
754
     * This method sets the regular expression for ignoring files and directories
755
     * at import, for example:
756
     * $arch->setIgnoreRegexp("#CVS|\.svn#");
757
     *
758
     * @param string $regexp regular expression defining which files or directories to ignore
759
     */
760
    public function setIgnoreRegexp($regexp)
761
    {
762
        $this->_ignore_regexp = $regexp;
763
    }
764

  
765
    /**
766
     * This method sets the regular expression for ignoring all files and directories
767
     * matching the filenames in the array list at import, for example:
768
     * $arch->setIgnoreList(array('CVS', '.svn', 'bin/tool'));
769
     *
770
     * @param array $list a list of file or directory names to ignore
771
     *
772
     * @access public
773
     */
774
    public function setIgnoreList($list)
775
    {
776
        $regexp = str_replace(array('#', '.', '^', '$'), array('\#', '\.', '\^', '\$'), $list);
777
        $regexp = '#/' . join('$|/', $list) . '#';
778
        $this->setIgnoreRegexp($regexp);
779
    }
780

  
781
    /**
782
     * @param string $p_message
783
     */
784
    public function _error($p_message)
632 785
    {
633
        // ----- To be completed
634
//        $this->raiseError($p_message);
786
        // Drupal change $this->error_object = $this->raiseError($p_message).
635 787
        throw new Exception($p_message);
636 788
    }
637
    // }}}
638 789

  
639
    // {{{ _warning()
640
    function _warning($p_message)
790
    /**
791
     * @param string $p_message
792
     */
793
    public function _warning($p_message)
641 794
    {
642
        // ----- To be completed
643
//        $this->raiseError($p_message);
795
        // Drupal change $this->error_object = $this->raiseError($p_message).
644 796
        throw new Exception($p_message);
645 797
    }
646
    // }}}
647 798

  
648
    // {{{ _isArchive()
649
    function _isArchive($p_filename=NULL)
799
    /**
800
     * @param string $p_filename
801
     * @return bool
802
     */
803
    public function _isArchive($p_filename = null)
650 804
    {
651
        if ($p_filename == NULL) {
805
        if ($p_filename == null) {
652 806
            $p_filename = $this->_tarname;
653 807
        }
654 808
        clearstatcache();
655 809
        return @is_file($p_filename) && !@is_link($p_filename);
656 810
    }
657
    // }}}
658 811

  
659
    // {{{ _openWrite()
660
    function _openWrite()
812
    /**
813
     * @return bool
814
     */
815
    public function _openWrite()
661 816
    {
662
        if ($this->_compress_type == 'gz')
817
        if ($this->_compress_type == 'gz' && function_exists('gzopen')) {
663 818
            $this->_file = @gzopen($this->_tarname, "wb9");
664
        else if ($this->_compress_type == 'bz2')
665
            $this->_file = @bzopen($this->_tarname, "w");
666
        else if ($this->_compress_type == 'none')
667
            $this->_file = @fopen($this->_tarname, "wb");
668
        else
669
            $this->_error('Unknown or missing compression type ('
670
			              .$this->_compress_type.')');
819
        } else {
820
            if ($this->_compress_type == 'bz2' && function_exists('bzopen')) {
821
                $this->_file = @bzopen($this->_tarname, "w");
822
            } else {
823
                if ($this->_compress_type == 'lzma2' && function_exists('xzopen')) {
824
                    $this->_file = @xzopen($this->_tarname, 'w');
825
                } else {
826
                    if ($this->_compress_type == 'none') {
827
                        $this->_file = @fopen($this->_tarname, "wb");
828
                    } else {
829
                        $this->_error(
830
                            'Unknown or missing compression type ('
831
                            . $this->_compress_type . ')'
832
                        );
833
                        return false;
834
                    }
835
                }
836
            }
837
        }
671 838

  
672 839
        if ($this->_file == 0) {
673
            $this->_error('Unable to open in write mode \''
674
			              .$this->_tarname.'\'');
840
            $this->_error(
841
                'Unable to open in write mode \''
842
                . $this->_tarname . '\''
843
            );
675 844
            return false;
676 845
        }
677 846

  
678 847
        return true;
679 848
    }
680
    // }}}
681 849

  
682
    // {{{ _openRead()
683
    function _openRead()
850
    /**
851
     * @return bool
852
     */
853
    public function _openRead()
684 854
    {
685 855
        if (strtolower(substr($this->_tarname, 0, 7)) == 'http://') {
686 856

  
687
          // ----- Look if a local copy need to be done
688
          if ($this->_temp_tarname == '') {
689
              $this->_temp_tarname = uniqid('tar').'.tmp';
690
              if (!$v_file_from = @fopen($this->_tarname, 'rb')) {
691
                $this->_error('Unable to open in read mode \''
692
				              .$this->_tarname.'\'');
693
                $this->_temp_tarname = '';
694
                return false;
695
              }
696
              if (!$v_file_to = @fopen($this->_temp_tarname, 'wb')) {
697
                $this->_error('Unable to open in write mode \''
698
				              .$this->_temp_tarname.'\'');
699
                $this->_temp_tarname = '';
700
                return false;
701
              }
702
              while ($v_data = @fread($v_file_from, 1024))
703
                  @fwrite($v_file_to, $v_data);
704
              @fclose($v_file_from);
705
              @fclose($v_file_to);
706
          }
857
            // ----- Look if a local copy need to be done
858
            if ($this->_temp_tarname == '') {
859
                $this->_temp_tarname = uniqid('tar') . '.tmp';
860
                if (!$v_file_from = @fopen($this->_tarname, 'rb')) {
861
                    $this->_error(
862
                        'Unable to open in read mode \''
863
                        . $this->_tarname . '\''
864
                    );
865
                    $this->_temp_tarname = '';
866
                    return false;
867
                }
868
                if (!$v_file_to = @fopen($this->_temp_tarname, 'wb')) {
869
                    $this->_error(
870
                        'Unable to open in write mode \''
871
                        . $this->_temp_tarname . '\''
872
                    );
873
                    $this->_temp_tarname = '';
874
                    return false;
875
                }
876
                while ($v_data = @fread($v_file_from, 1024)) {
877
                    @fwrite($v_file_to, $v_data);
878
                }
879
                @fclose($v_file_from);
880
                @fclose($v_file_to);
881
            }
707 882

  
708
          // ----- File to open if the local copy
709
          $v_filename = $this->_temp_tarname;
883
            // ----- File to open if the local copy
884
            $v_filename = $this->_temp_tarname;
885
        } else {
886
            // ----- File to open if the normal Tar file
710 887

  
711
        } else
712
          // ----- File to open if the normal Tar file
713
          $v_filename = $this->_tarname;
888
            $v_filename = $this->_tarname;
889
        }
714 890

  
715
        if ($this->_compress_type == 'gz')
891
        if ($this->_compress_type == 'gz' && function_exists('gzopen')) {
716 892
            $this->_file = @gzopen($v_filename, "rb");
717
        else if ($this->_compress_type == 'bz2')
718
            $this->_file = @bzopen($v_filename, "r");
719
        else if ($this->_compress_type == 'none')
720
            $this->_file = @fopen($v_filename, "rb");
721
        else
722
            $this->_error('Unknown or missing compression type ('
723
			              .$this->_compress_type.')');
893
        } else {
894
            if ($this->_compress_type == 'bz2' && function_exists('bzopen')) {
895
                $this->_file = @bzopen($v_filename, "r");
896
            } else {
897
                if ($this->_compress_type == 'lzma2' && function_exists('xzopen')) {
898
                    $this->_file = @xzopen($v_filename, "r");
899
                } else {
900
                    if ($this->_compress_type == 'none') {
901
                        $this->_file = @fopen($v_filename, "rb");
902
                    } else {
903
                        $this->_error(
904
                            'Unknown or missing compression type ('
905
                            . $this->_compress_type . ')'
906
                        );
907
                        return false;
908
                    }
909
                }
910
            }
911
        }
724 912

  
725 913
        if ($this->_file == 0) {
726
            $this->_error('Unable to open in read mode \''.$v_filename.'\'');
914
            $this->_error('Unable to open in read mode \'' . $v_filename . '\'');
727 915
            return false;
728 916
        }
729 917

  
730 918
        return true;
731 919
    }
732
    // }}}
733 920

  
734
    // {{{ _openReadWrite()
735
    function _openReadWrite()
921
    /**
922
     * @return bool
923
     */
924
    public function _openReadWrite()
736 925
    {
737
        if ($this->_compress_type == 'gz')
926
        if ($this->_compress_type == 'gz') {
738 927
            $this->_file = @gzopen($this->_tarname, "r+b");
739
        else if ($this->_compress_type == 'bz2') {
740
            $this->_error('Unable to open bz2 in read/write mode \''
741
			              .$this->_tarname.'\' (limitation of bz2 extension)');
742
            return false;
743
        } else if ($this->_compress_type == 'none')
744
            $this->_file = @fopen($this->_tarname, "r+b");
745
        else
746
            $this->_error('Unknown or missing compression type ('
747
			              .$this->_compress_type.')');
928
        } else {
929
            if ($this->_compress_type == 'bz2') {
930
                $this->_error(
931
                    'Unable to open bz2 in read/write mode \''
932
                    . $this->_tarname . '\' (limitation of bz2 extension)'
933
                );
934
                return false;
935
            } else {
936
                if ($this->_compress_type == 'lzma2') {
937
                    $this->_error(
938
                        'Unable to open lzma2 in read/write mode \''
939
                        . $this->_tarname . '\' (limitation of lzma2 extension)'
940
                    );
941
                    return false;
942
                } else {
943
                    if ($this->_compress_type == 'none') {
944
                        $this->_file = @fopen($this->_tarname, "r+b");
945
                    } else {
946
                        $this->_error(
947
                            'Unknown or missing compression type ('
948
                            . $this->_compress_type . ')'
949
                        );
950
                        return false;
951
                    }
952
                }
953
            }
954
        }
748 955

  
749 956
        if ($this->_file == 0) {
750
            $this->_error('Unable to open in read/write mode \''
751
			              .$this->_tarname.'\'');
957
            $this->_error(
958
                'Unable to open in read/write mode \''
959
                . $this->_tarname . '\''
960
            );
752 961
            return false;
753 962
        }
754 963

  
755 964
        return true;
756 965
    }
757
    // }}}
758 966

  
759
    // {{{ _close()
760
    function _close()
967
    /**
968
     * @return bool
969
     */
970
    public function _close()
761 971
    {
762 972
        //if (isset($this->_file)) {
763 973
        if (is_resource($this->_file)) {
764
            if ($this->_compress_type == 'gz')
974
            if ($this->_compress_type == 'gz') {
765 975
                @gzclose($this->_file);
766
            else if ($this->_compress_type == 'bz2')
767
                @bzclose($this->_file);
768
            else if ($this->_compress_type == 'none')
769
                @fclose($this->_file);
770
            else
771
                $this->_error('Unknown or missing compression type ('
772
				              .$this->_compress_type.')');
976
            } else {
977
                if ($this->_compress_type == 'bz2') {
978
                    @bzclose($this->_file);
979
                } else {
980
                    if ($this->_compress_type == 'lzma2') {
981
                        @xzclose($this->_file);
982
                    } else {
983
                        if ($this->_compress_type == 'none') {
984
                            @fclose($this->_file);
985
                        } else {
986
                            $this->_error(
987
                                'Unknown or missing compression type ('
988
                                . $this->_compress_type . ')'
989
                            );
990
                        }
991
                    }
992
                }
993
            }
773 994

  
774 995
            $this->_file = 0;
775 996
        }
......
783 1004

  
784 1005
        return true;
785 1006
    }
786
    // }}}
787 1007

  
788
    // {{{ _cleanFile()
789
    function _cleanFile()
1008
    /**
1009
     * @return bool
1010
     */
1011
    public function _cleanFile()
790 1012
    {
791 1013
        $this->_close();
792 1014

  
......
803 1025

  
804 1026
        return true;
805 1027
    }
806
    // }}}
807 1028

  
808
    // {{{ _writeBlock()
809
    function _writeBlock($p_binary_data, $p_len=null)
1029
    /**
1030
     * @param mixed $p_binary_data
1031
     * @param integer $p_len
1032
     * @return bool
1033
     */
1034
    public function _writeBlock($p_binary_data, $p_len = null)
810 1035
    {
811
      if (is_resource($this->_file)) {
812
          if ($p_len === null) {
813
              if ($this->_compress_type == 'gz')
814
                  @gzputs($this->_file, $p_binary_data);
815
              else if ($this->_compress_type == 'bz2')
816
                  @bzwrite($this->_file, $p_binary_data);
817
              else if ($this->_compress_type == 'none')
818
                  @fputs($this->_file, $p_binary_data);
819
              else
820
                  $this->_error('Unknown or missing compression type ('
821
				                .$this->_compress_type.')');
822
          } else {
823
              if ($this->_compress_type == 'gz')
824
                  @gzputs($this->_file, $p_binary_data, $p_len);
825
              else if ($this->_compress_type == 'bz2')
826
                  @bzwrite($this->_file, $p_binary_data, $p_len);
827
              else if ($this->_compress_type == 'none')
828
                  @fputs($this->_file, $p_binary_data, $p_len);
829
              else
830
                  $this->_error('Unknown or missing compression type ('
831
				                .$this->_compress_type.')');
832

  
833
          }
834
      }
835
      return true;
1036
        if (is_resource($this->_file)) {
1037
            if ($p_len === null) {
1038
                if ($this->_compress_type == 'gz') {
1039
                    @gzputs($this->_file, $p_binary_data);
1040
                } else {
1041
                    if ($this->_compress_type == 'bz2') {
1042
                        @bzwrite($this->_file, $p_binary_data);
1043
                    } else {
1044
                        if ($this->_compress_type == 'lzma2') {
1045
                            @xzwrite($this->_file, $p_binary_data);
1046
                        } else {
1047
                            if ($this->_compress_type == 'none') {
1048
                                @fputs($this->_file, $p_binary_data);
1049
                            } else {
1050
                                $this->_error(
1051
                                    'Unknown or missing compression type ('
1052
                                    . $this->_compress_type . ')'
1053
                                );
1054
                            }
1055
                        }
1056
                    }
1057
                }
1058
            } else {
1059
                if ($this->_compress_type == 'gz') {
1060
                    @gzputs($this->_file, $p_binary_data, $p_len);
1061
                } else {
1062
                    if ($this->_compress_type == 'bz2') {
1063
                        @bzwrite($this->_file, $p_binary_data, $p_len);
1064
                    } else {
1065
                        if ($this->_compress_type == 'lzma2') {
1066
                            @xzwrite($this->_file, $p_binary_data, $p_len);
1067
                        } else {
1068
                            if ($this->_compress_type == 'none') {
1069
                                @fputs($this->_file, $p_binary_data, $p_len);
1070
                            } else {
1071
                                $this->_error(
1072
                                    'Unknown or missing compression type ('
1073
                                    . $this->_compress_type . ')'
1074
                                );
1075
                            }
1076
                        }
1077
                    }
1078
                }
1079
            }
1080
        }
1081
        return true;
836 1082
    }
837
    // }}}
838 1083

  
839
    // {{{ _readBlock()
840
    function _readBlock()
1084
    /**
1085
     * @return null|string
... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.

Formats disponibles : Unified diff