Browse Source

! Hopefully guard better against bad stuff happening in package backup process.

Signed-off-by: Peter Spicer <[email protected]>
Peter Spicer 11 years ago
parent
commit
360d2e6e5c
1 changed files with 9 additions and 4 deletions
  1. 9 4
      Sources/Subs-Package.php

+ 9 - 4
Sources/Subs-Package.php

@@ -2981,10 +2981,15 @@ function package_create_backup($id = 'backup')
 		if ($stat['size'] == 0)
 			continue;
 
-		$fp = fopen($real_file, 'rb');
-		while (!feof($fp))
-			$fwrite($output, fread($fp, 16384));
-		fclose($fp);
+		$fp = @fopen($real_file, 'rb');
+		while ($fp && !feof($fp))
+		{
+			$buffer = fread($fp, 16384);
+			if (strlen($buffer) == 0)
+				break;
+			$fwrite($output, $buffer);
+		}
+		@fclose($fp);
 
 		$fwrite($output, pack('a' . (512 - $stat['size'] % 512), ''));
 	}