Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lazy stat and readlink function #7953

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions hphp/runtime/ext/fb/ext_fb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,13 @@ static Variant do_lazy_stat(Function dostat, const String& filename) {
return stat_impl(&sb);
}

Variant HHVM_FUNCTION(fb_lazy_stat, const String& filename) {
if (!FileUtil::checkPathAndWarn(filename, __FUNCTION__ + 2, 1)) {
return false;
}
return do_lazy_stat(StatCache::stat, filename);
}

Variant HHVM_FUNCTION(fb_lazy_lstat, const String& filename) {
if (!FileUtil::checkPathAndWarn(filename, __FUNCTION__ + 2, 1)) {
return false;
Expand All @@ -1173,6 +1180,14 @@ Variant HHVM_FUNCTION(fb_lazy_realpath, const String& filename) {
return StatCache::realpath(filename.c_str());
}

Variant HHVM_FUNCTION(fb_lazy_readlink, const String& filename) {
if (!FileUtil::checkPathAndWarn(filename, __FUNCTION__ + 2, 1)) {
return false;
}

return StatCache::readlink(filename.c_str());
}

///////////////////////////////////////////////////////////////////////////////

EXTERNALLY_VISIBLE
Expand Down Expand Up @@ -1210,8 +1225,10 @@ struct FBExtension : Extension {
HHVM_FE(fb_output_compression);
HHVM_FE(fb_set_exit_callback);
HHVM_FE(fb_get_last_flush_size);
HHVM_FE(fb_lazy_stat);
HHVM_FE(fb_lazy_lstat);
HHVM_FE(fb_lazy_realpath);
HHVM_FE(fb_lazy_readlink);
HHVM_FE(fb_call_user_func_safe);
HHVM_FE(fb_call_user_func_safe_return);
HHVM_FE(fb_call_user_func_array_safe);
Expand Down
2 changes: 2 additions & 0 deletions hphp/runtime/ext/fb/ext_fb.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ Variant HHVM_FUNCTION(fb_disable_code_coverage);
bool HHVM_FUNCTION(fb_output_compression, bool new_value);
void HHVM_FUNCTION(fb_set_exit_callback, const Variant& function);
int64_t HHVM_FUNCTION(fb_get_last_flush_size);
Variant HHVM_FUNCTION(fb_lazy_stat, const String& filename);
Variant HHVM_FUNCTION(fb_lazy_lstat, const String& filename);
Variant HHVM_FUNCTION(fb_lazy_realpath, const String& filename);
Variant HHVM_FUNCTION(fb_lazy_readlink, const String& filename);

Array HHVM_FUNCTION(fb_call_user_func_safe,
const Variant& function,
Expand Down
18 changes: 18 additions & 0 deletions hphp/runtime/ext/fb/ext_fb.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@ function fb_set_exit_callback(mixed $function): void;
<<__HipHopSpecific, __Native>>
function fb_get_last_flush_size(): int;

/* Gathers the statistics of the file named by filename, like stat(), except
* uses cached information from an internal inotify-based mechanism that may
* not be updated during the duration of a request.
* @param string $filename - Path to a file or a symbolic link.
* @return mixed - Same format as the normal php stat() function.
*/
<<__Native>>
function fb_lazy_stat(string $filename): mixed;

/* Gathers the statistics of the file named by filename, like lstat(), except
* uses cached information from an internal inotify-based mechanism that may
* not be updated during the duration of a request.
Expand All @@ -198,6 +207,15 @@ function fb_lazy_lstat(string $filename): mixed;
<<__Native>>
function fb_lazy_realpath(string $filename): mixed;

/* Returns the contents of the symbolic link path, like realpath(),
* except uses cached information from an internal inotify-based mechanism
* that may not be updated during the duration of a request.
* @param string $filename - The symbolic link path.
* @return string - Returns the contents of the symbolic link path.
*/
<<__Native>>
function fb_lazy_readlink(string $filename): mixed;

/* This function invokes $function with the arguments specified in its
* parameter list. It returns an array of two elements, the first being a
* boolean specifying whether or not the function was invoked, the latter
Expand Down
13 changes: 13 additions & 0 deletions hphp/test/slow/ext_fb/fb_lazy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

$stat = fb_lazy_stat(__FILE__);
var_dump($stat == stat(__FILE__));

$lstat = fb_lazy_lstat(__FILE__);
var_dump($lstat == lstat(__FILE__));

$path = fb_lazy_realpath(__FILE__);
var_dump($path == realpath(__FILE__));

$path = fb_lazy_readlink(__FILE__);
var_dump($path == readlink(__FILE__));
6 changes: 6 additions & 0 deletions hphp/test/slow/ext_fb/fb_lazy.php.expectf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
bool(true)
bool(true)
bool(true)

Warning: readlink(): No such file or directory %s/fb_lazy.php in %s/fb_lazy.php on line 13
bool(true)
2 changes: 2 additions & 0 deletions hphp/test/slow/ext_fb/fb_null_byte.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@

var_dump(fb_lazy_lstat($file));
var_dump(fb_lazy_realpath($file));
var_dump(fb_lazy_stat($file));
var_dump(fb_lazy_readlink($file));
6 changes: 6 additions & 0 deletions hphp/test/slow/ext_fb/fb_null_byte.php.expectf
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ bool(false)

Warning: fb_lazy_realpath() expects parameter 1 to be a valid path, string given in %s/test/slow/ext_fb/fb_null_byte.php on line 6
bool(false)

Warning: fb_lazy_stat() expects parameter 1 to be a valid path, string given in %s/test/slow/ext_fb/fb_null_byte.php on line 7
bool(false)

Warning: fb_lazy_readlink() expects parameter 1 to be a valid path, string given in %s/test/slow/ext_fb/fb_null_byte.php on line 8
bool(false)