From: awm086 at gmail dot com
Operating system: LINUX
PHP version: Irrelevant
Package: Filesystem function related
Bug Type: Bug
Bug description:file_put_contents is not atomic.
Description:
------------
The function file_put_contents is not atomic. When the function fails a
file
should not be created. However, when the reason for failure is full
directory,
(full diskspace, 0 empty), the function return FALSE, but a file is still
created
in
the directory with size 0. The function should either complete the job
successfully or have no effects at all (atomic).
Test script:
---------------
$data = 'somedata';
$temp_name = '/tmp/myfile';
if (file_put_contents($temp_name, $data) === FALSE) {
// the message print that the file could not be created.
print 'The file could not be created.';
}
// after this a file named myfile will exist in the directory.
Expected result:
----------------
No file should be created
Actual result:
--------------
File is created in the directory.
--
Edit bug report at https://bugs.php.net/bug.php?id=63908&edit=1
--
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=63908&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=63908&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=63908&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=63908&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=63908&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=63908&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=63908&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=63908&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=63908&r=support
Expected behavior: https://bugs.php.net/fix.php?id=63908&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=63908&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=63908&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=63908&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=63908&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=63908&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=63908&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=63908&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=63908&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=63908&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=63908&r=mysqlcfg