Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ext/standard/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1374,7 +1374,11 @@ PHP_FUNCTION(ftruncate)
RETURN_FALSE;
}

RETURN_BOOL(0 == php_stream_truncate_set_size(stream, size));
if (php_stream_truncate_set_size(stream, size) == 0) {
php_clear_stat_cache(0, NULL, 0);
RETURN_TRUE;
}
RETURN_FALSE;
}
/* }}} */
PHPAPI void php_fstat(php_stream *stream, zval *return_value)
Expand Down
23 changes: 23 additions & 0 deletions ext/standard/tests/file/ftruncate_stat_cache.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
GH-25232 ftruncate() clears the stat cache
--CREDITS--
tolry (tobias.olry@gmail.com)
--FILE--
<?php
$file = tempnam(sys_get_temp_dir(), 'stat-demo-');

file_put_contents($file, 'abcdefgh');

$handle = fopen($file, 'r+');

var_dump(filesize($file));
var_dump(ftruncate($handle, 3));
var_dump(filesize($file));

fclose($handle);
unlink($file);
?>
--EXPECT--
int(8)
bool(true)
int(3)
Loading