OSDN Git Service
(root)
/
wvm
/
wvm.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
4d3fccc
)
Handle error caused by reading empty file
author
goldenapples
<goldenapplesdesign@gmail.com>
Wed, 13 Feb 2013 19:23:45 +0000
(11:23 -0800)
committer
goldenapples
<goldenapplesdesign@gmail.com>
Wed, 13 Feb 2013 19:23:45 +0000
(11:23 -0800)
`fread()` will throw an error if trying to read an empty file (ie if
user deleted all post content or quit the editor on `wp post create`.
Detect that and fail gracefully.
php/utils.php
patch
|
blob
|
history
diff --git
a/php/utils.php
b/php/utils.php
index
68cc356
..
bb0ee3d
100644
(file)
--- a/
php/utils.php
+++ b/
php/utils.php
@@
-280,8
+280,13
@@
function launch_editor_for_input( $input, $title = 'WP-CLI' ) {
\WP_CLI::launch( "\${EDITOR:-vi} '$tmpfile'" );
+ $filesize = filesize( $tmpfile );
+
+ if ( $filesize === 0 )
+ return false;
+
$handle = fopen( $tmpfile, 'r' );
- $output = fread( $handle,
filesize( $tmpfile )
);
+ $output = fread( $handle,
$filesize
);
fclose( $handle );
unlink( $tmpfile );