improve error handling in extraction code, add is_extractable functionality
This commit is contained in:
		
							parent
							
								
									de54a15ca0
								
							
						
					
					
						commit
						eaefa56fb9
					
				|  | @ -432,7 +432,7 @@ class m_bro { | ||||||
|     } |     } | ||||||
|     if (!$file || !$dest) { |     if (!$file || !$dest) { | ||||||
|       $err->raise("bro",1); |       $err->raise("bro",1); | ||||||
|       return false; |       return 1; | ||||||
|     } |     } | ||||||
|     $file = escapeshellarg($file); |     $file = escapeshellarg($file); | ||||||
|     $dest = escapeshellarg($dest); |     $dest = escapeshellarg($dest); | ||||||
|  | @ -445,12 +445,16 @@ class m_bro { | ||||||
|     } else if ($i == 2) { |     } else if ($i == 2) { | ||||||
|       exec("unzip '$file' -d '$dest'", $void, $ret); |       exec("unzip '$file' -d '$dest'", $void, $ret); | ||||||
|     } else { |     } else { | ||||||
|  |       $err->raise("bro","undefined extractiong error: %s", $ret); | ||||||
|       return $ret; |       return $ret; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if ($ret) { |     if ($ret) { | ||||||
|       $i++; |       $i++; | ||||||
|       $this->ExtractFile($file, $dest); |       $ret = $this->ExtractFile($file, $dest); | ||||||
|  |       if ($ret) { | ||||||
|  |         $err->raise("bro","could not find a way to extract file %s, unsupported format?", $file); | ||||||
|  |       } | ||||||
|     } |     } | ||||||
|     return $ret; |     return $ret; | ||||||
|   } |   } | ||||||
|  | @ -668,6 +672,33 @@ class m_bro { | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   /** | ||||||
|  |    * Return a HTML snippet representing an extraction function only if the mimetype of $name is supported | ||||||
|  |    */ | ||||||
|  |   function is_extractable($dir,$name) { | ||||||
|  |     if ($parts = explode(".", $name)) { | ||||||
|  |       $ext = array_pop($parts); | ||||||
|  |       switch ($ext) { | ||||||
|  |       case "gz": | ||||||
|  |       case "bz": | ||||||
|  |       case "bz2": | ||||||
|  | 	$ext = array_pop($parts) . $ext; | ||||||
|  | 	/* FALLTHROUGH */ | ||||||
|  |       case "tar.gz": | ||||||
|  |       case "tar.bz": | ||||||
|  |       case "tar.bz2": | ||||||
|  |       case "tgz": | ||||||
|  |       case "tbz": | ||||||
|  |       case "tbz2": | ||||||
|  |       case "tar": | ||||||
|  |       case "Z": | ||||||
|  |       case "zip": | ||||||
|  |         return true; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |     return false; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   function content_send($R,$file) { |   function content_send($R,$file) { | ||||||
|     global $err; |     global $err; | ||||||
|     $absolute=$this->convertabsolute($R,0); |     $absolute=$this->convertabsolute($R,0); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Antoine Beaupré
						Antoine Beaupré