diff options
| author | Ilia Alshanetsky <iliaa@php.net> | 2007-11-12 18:47:46 +0000 |
|---|---|---|
| committer | Ilia Alshanetsky <iliaa@php.net> | 2007-11-12 18:47:46 +0000 |
| commit | 5d09ce66a3994e3e68852e7d44bce2af3493ef78 (patch) | |
| tree | 880b234caf34053dadc5a49a3daa7f3b52bf263f | |
| parent | 144419b3a1423965526409d16afaa9530f34c182 (diff) | |
| download | php-git-5d09ce66a3994e3e68852e7d44bce2af3493ef78.tar.gz | |
Fixed bug #43182 (file_put_contents() LOCK_EX does not work properly on
file
| -rw-r--r-- | NEWS | 2 | ||||
| -rw-r--r-- | ext/standard/file.c | 15 | ||||
| -rw-r--r-- | main/streams/plain_wrapper.c | 3 |
3 files changed, 18 insertions, 2 deletions
@@ -3,6 +3,8 @@ PHP NEWS ?? ??? 2008, PHP 5.2.6 - Fixed bug #43216 (stream_is_local() returns false on "file://"). (Dmitry) - Fixed bug #43201 (Crash on using unitialized vals and __get/__set). (Dmitry) +- Fixed bug #43182 (file_put_contents() LOCK_EX does not work properly on file + truncation). (Ilia) - Fixed bug #43175 (__destruct() throwing an exception with __call() causes segfault). (Dmitry) - Fixed bug #42937 (__call() method not invoked when methods are called on diff --git a/ext/standard/file.c b/ext/standard/file.c index c54ce62313..605367c405 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -592,6 +592,7 @@ PHP_FUNCTION(file_put_contents) zval *zcontext = NULL; php_stream_context *context = NULL; php_stream *srcstream = NULL; + char mode[3] = "wb"; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz/|lr!", &filename, &filename_len, &data, &flags, &zcontext) == FAILURE) { @@ -604,8 +605,14 @@ PHP_FUNCTION(file_put_contents) context = php_stream_context_from_zval(zcontext, flags & PHP_FILE_NO_DEFAULT_CONTEXT); - stream = php_stream_open_wrapper_ex(filename, (flags & PHP_FILE_APPEND) ? "ab" : "wb", - ((flags & PHP_FILE_USE_INCLUDE_PATH) ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, context); + if (flags & PHP_FILE_APPEND) { + mode[0] = 'a'; + } else if (flags & LOCK_EX) { + mode[0] = 'c'; + } + mode[2] = '\0'; + + stream = php_stream_open_wrapper_ex(filename, mode, ((flags & PHP_FILE_USE_INCLUDE_PATH) ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, context); if (stream == NULL) { RETURN_FALSE; } @@ -615,6 +622,10 @@ PHP_FUNCTION(file_put_contents) RETURN_FALSE; } + if (mode[0] = 'c') { + php_stream_truncate_set_size(stream, 0); + } + switch (Z_TYPE_P(data)) { case IS_RESOURCE: numbytes = php_stream_copy_to_stream(srcstream, stream, PHP_STREAM_COPY_ALL); diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index f50db8adc3..f921f0124e 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -63,6 +63,9 @@ PHPAPI int php_stream_parse_fopen_modes(const char *mode, int *open_flags) case 'x': flags = O_CREAT|O_EXCL; break; + case 'c': + flags = O_CREAT; + break; default: /* unknown mode */ return FAILURE; |
