Page MenuHomePhabricator

bug_21140.patch

Authored By
bzimport
Nov 21 2014, 10:56 PM
Size
2 KB
Referenced Files
None
Subscribers
None

bug_21140.patch

Index: GlobalFunctions.php
===================================================================
--- GlobalFunctions.php (revision 57706)
+++ GlobalFunctions.php (working copy)
@@ -3346,3 +3346,55 @@
$langCode = implode ( '-' , $codeBCP );
return $langCode;
}
+
+/* Fixes shell_exec problems on Windows
+ * From http://www.php.net/manual/de/function.shell-exec.php#52826 via bug 21140
+ */
+function wfRunExternal($cmd,&$code) {
+ $descriptorspec = array(
+ 0 => array("pipe", "r"), // stdin is a pipe that the child will read from
+ 1 => array("pipe", "w"), // stdout is a pipe that the child will write to
+ 2 => array("pipe", "w") // stderr is a file to write to
+ );
+
+ $pipes= array();
+ $process = proc_open($cmd, $descriptorspec, $pipes);
+
+ $output= "";
+
+ if (!is_resource($process)) return false;
+
+ #close child's input imidiately
+ fclose($pipes[0]);
+
+ stream_set_blocking($pipes[1],false);
+ stream_set_blocking($pipes[2],false);
+
+ $todo= array($pipes[1],$pipes[2]);
+
+ while( true ) {
+ $read= array();
+ if( !feof($pipes[1]) ) $read[]= $pipes[1];
+ if( !feof($pipes[2]) ) $read[]= $pipes[2];
+
+ if (!$read) break;
+
+ $ready= stream_select($read, $write=NULL, $ex= NULL, 2);
+
+ if ($ready === false) {
+ break; #should never happen - something died
+ }
+
+ foreach ($read as $r) {
+ $s= fread($r,1024);
+ $output.= $s;
+ }
+ }
+
+ fclose($pipes[1]);
+ fclose($pipes[2]);
+
+ $code= proc_close($process);
+
+ return $output;
+}
Index: upload/UploadBase.php
===================================================================
--- upload/UploadBase.php (revision 57706)
+++ upload/UploadBase.php (working copy)
@@ -814,11 +814,12 @@
# Ask me (Duesentrieb) about it if it's ever needed.
$output = array();
if ( wfIsWindows() ) {
- exec( "$command", $output, $exitCode );
+ $output = wfRunExternal($command, $exitCode);
} else {
exec( "$command 2>&1", $output, $exitCode );
}
+
# map exit code to AV_xxx constants.
$mappedCode = $exitCode;
if ( $exitCodeMap ) {
@@ -829,6 +830,7 @@
}
}
+
if ( $mappedCode === AV_SCAN_FAILED ) {
# scan failed (code was mapped to false by $exitCodeMap)
wfDebug( __METHOD__ . ": failed to scan $file (code $exitCode).\n" );

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5956
Default Alt Text
bug_21140.patch (2 KB)

Event Timeline