aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/functions_compress.php
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/includes/functions_compress.php')
-rw-r--r--phpBB/includes/functions_compress.php58
1 files changed, 47 insertions, 11 deletions
diff --git a/phpBB/includes/functions_compress.php b/phpBB/includes/functions_compress.php
index 455debd939..39a1b2ad21 100644
--- a/phpBB/includes/functions_compress.php
+++ b/phpBB/includes/functions_compress.php
@@ -2,9 +2,8 @@
/**
*
* @package phpBB3
-* @version $Id$
* @copyright (c) 2005 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
@@ -25,6 +24,11 @@ class compress
var $fp = 0;
/**
+ * @var array
+ */
+ protected $filelist = array();
+
+ /**
* Add file to archive
*/
function add_file($src, $src_rm_prefix = '', $src_add_prefix = '', $skip_files = '')
@@ -42,7 +46,7 @@ class compress
if (is_file($phpbb_root_path . $src))
{
- $this->data($src_path, file_get_contents("$phpbb_root_path$src"), false, stat("$phpbb_root_path$src"));
+ $this->data($src_path, file_get_contents("$phpbb_root_path$src"), stat("$phpbb_root_path$src"), false);
}
else if (is_dir($phpbb_root_path . $src))
{
@@ -82,7 +86,7 @@ class compress
continue;
}
- $this->data("$src_path$path$file", file_get_contents("$phpbb_root_path$src$path$file"), false, stat("$phpbb_root_path$src$path$file"));
+ $this->data("$src_path$path$file", file_get_contents("$phpbb_root_path$src$path$file"), stat("$phpbb_root_path$src$path$file"), false);
}
}
}
@@ -105,7 +109,7 @@ class compress
return false;
}
- $this->data($filename, file_get_contents($src), false, stat($src));
+ $this->data($filename, file_get_contents($src), stat($src), false);
return true;
}
@@ -119,14 +123,46 @@ class compress
$stat[4] = $stat[5] = 0;
$stat[7] = strlen($src);
$stat[9] = time();
- $this->data($name, $src, false, $stat);
+ $this->data($name, $src, $stat, false);
return true;
}
/**
+ * Checks if a file by that name as already been added and, if it has,
+ * returns a new, unique name.
+ *
+ * @param string $name The filename
+ * @return string A unique filename
+ */
+ protected function unique_filename($name)
+ {
+ if (isset($this->filelist[$name]))
+ {
+ $start = $name;
+ $ext = '';
+ $this->filelist[$name]++;
+
+ // Separate the extension off the end of the filename to preserve it
+ $pos = strrpos($name, '.');
+ if ($pos !== false)
+ {
+ $start = substr($name, 0, $pos);
+ $ext = substr($name, $pos);
+ }
+
+ return $start . '_' . $this->filelist[$name] . $ext;
+ }
+
+ $this->filelist[$name] = 0;
+ return $name;
+ }
+
+ /**
* Return available methods
+ *
+ * @return array Array of strings of available compression methods (.tar, .tar.gz, .zip, etc.)
*/
- function methods()
+ static public function methods()
{
$methods = array('.tar');
$available_methods = array('.tar.gz' => 'zlib', '.tar.bz2' => 'bz2', '.zip' => 'zlib');
@@ -359,9 +395,10 @@ class compress_zip extends compress
/**
* Create the structures ... note we assume version made by is MSDOS
*/
- function data($name, $data, $is_dir = false, $stat)
+ function data($name, $data, $stat, $is_dir = false)
{
$name = str_replace('\\', '/', $name);
+ $name = $this->unique_filename($name);
$hexdtime = pack('V', $this->unix_to_dos_time($stat[9]));
@@ -632,8 +669,9 @@ class compress_tar extends compress
/**
* Create the structures
*/
- function data($name, $data, $is_dir = false, $stat)
+ function data($name, $data, $stat, $is_dir = false)
{
+ $name = $this->unique_filename($name);
$this->wrote = true;
$fzwrite = ($this->isbz && function_exists('bzwrite')) ? 'bzwrite' : (($this->isgz && @extension_loaded('zlib')) ? 'gzwrite' : 'fwrite');
@@ -735,5 +773,3 @@ class compress_tar extends compress
}
}
}
-
-?> \ No newline at end of file