aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
authorAndreas Fischer <bantu@phpbb.com>2012-08-06 23:32:28 +0200
committerAndreas Fischer <bantu@phpbb.com>2012-08-06 23:32:28 +0200
commit095d7d97a34bed98278fc1b2108e93c03e4d1df3 (patch)
tree32cec06c99de1a07deaa2e8a74dfe72a09a556a4 /phpBB/includes
parentae3f86dbb076c84dbae1588deca3244a102005fd (diff)
parentecb310c6f7a2f8aa5c1f2217d7de6cb878aa85f4 (diff)
downloadforums-095d7d97a34bed98278fc1b2108e93c03e4d1df3.tar
forums-095d7d97a34bed98278fc1b2108e93c03e4d1df3.tar.gz
forums-095d7d97a34bed98278fc1b2108e93c03e4d1df3.tar.bz2
forums-095d7d97a34bed98278fc1b2108e93c03e4d1df3.tar.xz
forums-095d7d97a34bed98278fc1b2108e93c03e4d1df3.zip
Merge remote-tracking branch 'Fyorl/ticket/11044' into develop
* Fyorl/ticket/11044: [ticket/11044] Added comment explaining filename splitting [ticket/11044] Preserve the file extension in unique filenames [ticket/11044] Minor adjustments as per PR comments [ticket/11044] Compress class now deals with file conflicts
Diffstat (limited to 'phpBB/includes')
-rw-r--r--phpBB/includes/functions_compress.php37
1 files changed, 37 insertions, 0 deletions
diff --git a/phpBB/includes/functions_compress.php b/phpBB/includes/functions_compress.php
index 72d8eabe76..8e07e6d1b8 100644
--- a/phpBB/includes/functions_compress.php
+++ b/phpBB/includes/functions_compress.php
@@ -24,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 = '')
@@ -123,6 +128,36 @@ class compress
}
/**
+ * 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
*/
function methods()
@@ -361,6 +396,7 @@ class compress_zip extends compress
function data($name, $data, $is_dir = false, $stat)
{
$name = str_replace('\\', '/', $name);
+ $name = $this->unique_filename($name);
$hexdtime = pack('V', $this->unix_to_dos_time($stat[9]));
@@ -633,6 +669,7 @@ class compress_tar extends compress
*/
function data($name, $data, $is_dir = false, $stat)
{
+ $name = $this->unique_filename($name);
$this->wrote = true;
$fzwrite = ($this->isbz && function_exists('bzwrite')) ? 'bzwrite' : (($this->isgz && @extension_loaded('zlib')) ? 'gzwrite' : 'fwrite');