]> git.joonet.de Git - adminer.git/commitdiff
Constraint memory used in TAR export
authorJakub Vrana <jakub@vrana.cz>
Wed, 1 May 2013 16:33:23 +0000 (09:33 -0700)
committerJakub Vrana <jakub@vrana.cz>
Wed, 1 May 2013 16:33:23 +0000 (09:33 -0700)
adminer/dump.inc.php
adminer/include/editing.inc.php
adminer/include/tmpfile.inc.php [new file with mode: 0644]
adminer/index.php
changes.txt
todo.txt

index 78ade4ee4d6c5bbd38b3e3a4b651df3a71ed35d1..4e0e0fe042e730b38869fdd7ce1bb20a263d03d6 100644 (file)
@@ -71,7 +71,8 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
                                        $data = (DB == "" || in_array($name, (array) $_POST["data"]));
                                        if ($table || $data) {
                                                if ($ext == "tar") {
-                                                       ob_start();
+                                                       $tmp_file = new TmpFile;
+                                                       ob_start(array($tmp_file, 'write'), 1e5);
                                                }
                                                $adminer->dumpTable($name, ($table ? $_POST["table_style"] : ""), (is_view($table_status) ? 2 : 0));
                                                if (is_view($table_status)) {
@@ -84,7 +85,8 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
                                                        echo "\nDELIMITER ;;\n$triggers\nDELIMITER ;\n";
                                                }
                                                if ($ext == "tar") {
-                                                       tar_file((DB != "" ? "" : "$db/") . "$name.csv", ob_get_clean());
+                                                       ob_end_flush();
+                                                       tar_file((DB != "" ? "" : "$db/") . "$name.csv", $tmp_file);
                                                } elseif ($is_sql) {
                                                        echo "\n";
                                                }
index da42e32334d702e6540318c3bf0022320802fb9e..9cb939a6333c2aaad1be76fa4a297eca95462c9b 100644 (file)
@@ -409,13 +409,13 @@ function remove_definer($query) {
        return preg_replace('~^([A-Z =]+) DEFINER=`' . preg_replace('~@(.*)~', '`@`(%|\\1)', logged_user()) . '`~', '\\1', $query); //! proper escaping of user
 }
 
-/** Get string to add a file in TAR
-* @param string
+/** Add a file to TAR
 * @param string
+* @param TmpFile
 * @return null prints the output
 */
-function tar_file($filename, $contents) {
-       $return = pack("a100a8a8a8a12a12", $filename, 644, 0, 0, decoct(strlen($contents)), decoct(time()));
+function tar_file($filename, $tmp_file) {
+       $return = pack("a100a8a8a8a12a12", $filename, 644, 0, 0, decoct($tmp_file->size), decoct(time()));
        $checksum = 8*32; // space for checksum itself
        for ($i=0; $i < strlen($return); $i++) {
                $checksum += ord($return[$i]);
@@ -423,8 +423,8 @@ function tar_file($filename, $contents) {
        $return .= sprintf("%06o", $checksum) . "\0 ";
        echo $return;
        echo str_repeat("\0", 512 - strlen($return));
-       echo $contents;
-       echo str_repeat("\0", 511 - (strlen($contents) + 511) % 512);
+       $tmp_file->send();
+       echo str_repeat("\0", 511 - ($tmp_file->size + 511) % 512);
 }
 
 /** Get INI bytes value
diff --git a/adminer/include/tmpfile.inc.php b/adminer/include/tmpfile.inc.php
new file mode 100644 (file)
index 0000000..6fa58c1
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+
+class TmpFile {
+       var $handler;
+       var $size;
+       
+       function TmpFile() {
+               $this->handler = tmpfile();
+       }
+       
+       function write($contents) {
+               $this->size += strlen($contents);
+               fwrite($this->handler, $contents);
+       }
+       
+       function send() {
+               fseek($this->handler, 0);
+               fpassthru($this->handler);
+               fclose($this->handler);
+       }
+}
index dd667f345ccb9eeaff246b7e0f9b60c910433150..a024aabddd8c06bcbe1712ac737457805f140faf 100644 (file)
@@ -8,6 +8,7 @@
 */
 
 include "./include/bootstrap.inc.php";
+include "./include/tmpfile.inc.php";
 
 $enum_length = "'(?:''|[^'\\\\]|\\\\.)*+'";
 $inout = "IN|OUT|INOUT";
index 417db3cf4ac1b1aec9579cb0a93eb952cfa7a86e..1f53f7624bca1e25b4801e87d71855700116c4b3 100644 (file)
@@ -4,6 +4,7 @@ Print run time next to executed queries
 Disable SQL export when applying functions in select
 Allow using lang() in plugins (customization)
 Remove bzip2 compression support
+Constraint memory used in TAR export
 Allow exporting views dependent on each other (bug #3459151)
 MySQL: Optimize create table page and Editor navigation
 MySQL: Display bit type as binary number
index f682ba0cead009c28145521a1c93351f07e4f6c2..6adabfebb6b58443d3303889d320936b4602ae28 100644 (file)
--- a/todo.txt
+++ b/todo.txt
@@ -4,7 +4,6 @@ Variables editation
 Blob download and image display in edit form (important for Editor with hidden fields in select and SQL command)
 Add title to Logout, edit (in select) and select (in menu) for style "hever"
 Export by GET parameters
-Files are missing in TAR due to exhausted memory - can be fixed by creating a temporary file
 Draggable columns in alter table (thanks to Michal Manak)
 <option class> for system databases and schemas - information_schema and driver-specific (thanks to Vaclav Novotny)
 Define foreign keys name - http://forum.zdrojak.root.cz/index.php?topic=185.msg1255#msg1255