diff --git a/hphp/runtime/ext/std/ext_std_file.cpp b/hphp/runtime/ext/std/ext_std_file.cpp index c922629ba07fb..565097848e168 100644 --- a/hphp/runtime/ext/std/ext_std_file.cpp +++ b/hphp/runtime/ext/std/ext_std_file.cpp @@ -577,8 +577,18 @@ Variant HHVM_FUNCTION(file_put_contents, return false; } - if ((flags & LOCK_EX) && !f->lock(LOCK_EX)) { - return false; + if (flags & LOCK_EX) { + // Check to make sure we are dealing with a regular file + if (!dynamic_cast(f)) { + raise_warning( + "%s(): Exclusive locks may only be set for regular files", + __FUNCTION__ + 2); + return false; + } + + if (!f->lock(LOCK_EX)) { + return false; + } } int numbytes = 0; diff --git a/hphp/test/frameworks/results/vfsstream.expect b/hphp/test/frameworks/results/vfsstream.expect index 6bd3debef334d..1a17941c4b8a6 100644 --- a/hphp/test/frameworks/results/vfsstream.expect +++ b/hphp/test/frameworks/results/vfsstream.expect @@ -219,7 +219,7 @@ org\bovigo\vfs\vfsStreamDirectoryTestCase::rename org\bovigo\vfs\vfsStreamDirectoryTestCase::renameToInvalidNameThrowsvfsStreamException . org\bovigo\vfs\vfsStreamExLockTestCase::filePutContentsLockShouldReportError -F +. org\bovigo\vfs\vfsStreamExLockTestCase::flockSouldPass . org\bovigo\vfs\vfsStreamFileTestCase::content diff --git a/hphp/test/slow/ext_file/file_put_contents.php b/hphp/test/slow/ext_file/file_put_contents.php index 8d7189bd77807..f310ab53d8f94 100644 --- a/hphp/test/slow/ext_file/file_put_contents.php +++ b/hphp/test/slow/ext_file/file_put_contents.php @@ -6,3 +6,10 @@ var_dump(file_get_contents($tempfile)); unlink($tempfile); + +$tempfile2 = tempnam('/tmp', 'vmextfiletest'); + +file_put_contents('File://' . $tempfile2, 'testing file_put_contents with File:// url and LOCK_EX', LOCK_EX); +var_dump(file_get_contents($tempfile2)); + +unlink($tempfile2); diff --git a/hphp/test/slow/ext_file/file_put_contents.php.expect b/hphp/test/slow/ext_file/file_put_contents.php.expect index 75f1783a8c7e8..2a1f22359f2ab 100644 --- a/hphp/test/slow/ext_file/file_put_contents.php.expect +++ b/hphp/test/slow/ext_file/file_put_contents.php.expect @@ -1 +1,2 @@ string(25) "testing file_put_contents" +string(54) "testing file_put_contents with File:// url and LOCK_EX"