From dee490e7eb1d46131cacb6563c217e8d85fb58a7 Mon Sep 17 00:00:00 2001 From: huzhiguang Date: Wed, 26 Jul 2017 20:00:52 +0800 Subject: [PATCH] fix file_exists relative path bug --- hphp/runtime/ext/std/ext_std_file.cpp | 10 +++++++++- hphp/test/slow/file/relative_path.php | 9 +++++++++ hphp/test/slow/file/relative_path.php.expectf | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 hphp/test/slow/file/relative_path.php create mode 100644 hphp/test/slow/file/relative_path.php.expectf diff --git a/hphp/runtime/ext/std/ext_std_file.cpp b/hphp/runtime/ext/std/ext_std_file.cpp index bb28b36cb92a7..e4357544757ec 100644 --- a/hphp/runtime/ext/std/ext_std_file.cpp +++ b/hphp/runtime/ext/std/ext_std_file.cpp @@ -193,7 +193,15 @@ static int accessSyscall( return -1; } } - return ::access(File::TranslatePathWithFileCache(path).data(), mode); + String filepath = path; + if (path.charAt(0) != '/') { + String cwd = g_context->getCwd(); + filepath = cwd + "/" + path; + if (!cwd.empty() && cwd[cwd.length() - 1] == '/') { + filepath = cwd + path; + } + return ::access(filepath.data(),mode); + } } return w->access(uri_or_path, mode); } diff --git a/hphp/test/slow/file/relative_path.php b/hphp/test/slow/file/relative_path.php new file mode 100644 index 0000000000000..ebfbcf121abb4 --- /dev/null +++ b/hphp/test/slow/file/relative_path.php @@ -0,0 +1,9 @@ + diff --git a/hphp/test/slow/file/relative_path.php.expectf b/hphp/test/slow/file/relative_path.php.expectf new file mode 100644 index 0000000000000..5c0c0681d9c1e --- /dev/null +++ b/hphp/test/slow/file/relative_path.php.expectf @@ -0,0 +1 @@ +bool(false)