- Timestamp:
- 21.07.2005 12:58:13 (3 years ago)
- Files:
-
- 1 modified
-
trunk/File/Bittorrent/MakeTorrent.php (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/File/Bittorrent/MakeTorrent.php
r27 r33 33 33 * @category File 34 34 */ 35 35 36 36 /** 37 37 * Include required classes … … 48 48 * @author Justin Jones <j.nagash@gmail.com> 49 49 * @author Markus Tacker <m@tacker.org> 50 * @version $Id$51 50 * @package File_Bittorrent 52 51 * @category File … … 94 93 */ 95 94 var $_created_by = 'File_Bittorrent_MakeTorrent $Rev$. http://pear.php.net/package/File_Bittorrent'; 96 95 97 96 /** 98 97 * @var string The .torrent suggested name (file/dir) … … 124 123 */ 125 124 var $_data_gap = false; 126 125 127 126 /** 128 127 * @var resource file pointer … … 167 166 { 168 167 if (!is_array($announce_list)) { 169 PEAR::raiseError(__CLASS__ . '::'. __FUNCTION__ . '() - No array given.');170 return false;168 PEAR::raiseError(__CLASS__ . '::'. __FUNCTION__ . '() - No array given.'); 169 return false; 171 170 } 172 171 $this->_announce_list = $announce_list; … … 221 220 { 222 221 if ($piece_length < 32 or $piece_length > 4096) { 223 PEAR::raiseError(__CLASS__ . '::'. __FUNCTION__ . '() - Invalid piece lenth: "' . $piece_length . '"');224 return false;222 PEAR::raiseError(__CLASS__ . '::'. __FUNCTION__ . '() - Invalid piece lenth: "' . $piece_length . '"'); 223 return false; 225 224 } 226 225 $this->_piece_length = $piece_length * 1024; … … 239 238 if ($this->_is_file) { 240 239 if (!$info = $this->_addFile($this->_path)) { 241 return false;240 return false; 242 241 } 243 242 if (!$metainfo = $this->_encodeTorrent($info)) { 244 return false;245 } 243 return false; 244 } 246 245 } else if ($this->_is_dir) { 247 246 if (!$diradd_ok = $this->_addDir($this->_path)) { 248 return false;247 return false; 249 248 } 250 249 $metainfo = $this->_encodeTorrent(); … … 275 274 $bencdata['info']['files'] = $this->_files; 276 275 } else { 277 PEAR::raiseError(__CLASS__ . '::'. __FUNCTION__ . '() - Use ' . __CLASS__ . '::setPath() to define a file or directory.');276 PEAR::raiseError(__CLASS__ . '::'. __FUNCTION__ . '() - Use ' . __CLASS__ . '::setPath() to define a file or directory.'); 278 277 return false; 279 278 } … … 297 296 * @param string path to the file 298 297 * @return mixed false on failure or file metainfo data 299 * @access private300 */298 * @access private 299 */ 301 300 function _addFile($file) 302 301 { 303 if (!$this->_openFile($file)) return false;304 302 if (!$this->_openFile($file)) return false; 303 305 304 $filelength = 0; 306 305 $md5sum = md5_file($file); … … 406 405 if ($dh = opendir($current_dir)) { 407 406 while ( ($file = readdir($dh)) !== false ) { 408 if ($file{0} =='.') continue;407 if ($file{0} =='.') continue; 409 408 $current_file = $current_dir . '/' . $file; 410 409 if (is_file($current_file)) { … … 428 427 */ 429 428 function _filesize($file) 430 {429 { 431 430 $size = @filesize($file); 432 431 if ($size == 0) { 433 if (PHP_OS != 'Linux') return false;432 if (PHP_OS != 'Linux') return false; 434 433 $size = exec('du -b ' . escapeshellarg($file)); 435 434 } … … 446 445 */ 447 446 function _openFile($file) 448 {447 { 449 448 $fsize = $this->_filesize($file); 450 449 if ($fsize <= 2*1024*1024*1024) { 451 if (!$this->_fp = fopen($file, 'r')) {452 PEAR::raiseError(__CLASS__ . '::'. __FUNCTION__ . '() - Failed to open "' . $file . '"');453 return false;454 }450 if (!$this->_fp = fopen($file, 'r')) { 451 PEAR::raiseError(__CLASS__ . '::'. __FUNCTION__ . '() - Failed to open "' . $file . '"'); 452 return false; 453 } 455 454 $this->_fopen = true; 456 455 } else { 457 if (PHP_OS != 'Linux') {458 PEAR::raiseError(__CLASS__ . '::'. __FUNCTION__ . '() - File size is greater than 2GB. This is only supported under Linux.');459 return false;460 }456 if (PHP_OS != 'Linux') { 457 PEAR::raiseError(__CLASS__ . '::'. __FUNCTION__ . '() - File size is greater than 2GB. This is only supported under Linux.'); 458 return false; 459 } 461 460 $this->_fp = popen('cat ' . escapeshellarg($file), 'r'); 462 461 $this->_fopen = false; … … 472 471 function _closeFile() 473 472 { 474 if ($this->_fopen) {475 fclose($this->_fp);476 } else {473 if ($this->_fopen) { 474 fclose($this->_fp); 475 } else { 477 476 pclose($this->_fp); 478 477 }