remove default boolean params from File::TranslatePath
Most callsites use the defaults, and I can't figure out which callsites should and should not use it. Lets just have different functions for each use-case.
Esse commit está contido em:
@@ -46,24 +46,10 @@ IMPLEMENT_REQUEST_LOCAL(FileData, s_file_data);
|
||||
|
||||
const int File::USE_INCLUDE_PATH = 1;
|
||||
|
||||
String File::TranslatePath(CStrRef filename, bool useFileCache /* = false */,
|
||||
bool keepRelative /*= false */) {
|
||||
String File::TranslatePathKeepRelative(CStrRef filename) {
|
||||
String canonicalized(Util::canonicalize(filename.data(),
|
||||
filename.size()), AttachString);
|
||||
|
||||
if (useFileCache) {
|
||||
String translated = TranslatePath(canonicalized, false);
|
||||
if (!translated.empty() && access(translated.data(), F_OK) < 0 &&
|
||||
StaticContentCache::TheFileCache) {
|
||||
if (StaticContentCache::TheFileCache->exists(canonicalized.data(),
|
||||
false)) {
|
||||
// we use file cache's file name to make stat() work
|
||||
translated = String(RuntimeOption::FileCache);
|
||||
}
|
||||
}
|
||||
return translated;
|
||||
}
|
||||
|
||||
if (RuntimeOption::SafeFileAccess) {
|
||||
const vector<string> &allowedDirectories =
|
||||
VirtualHost::GetAllowedDirectories();
|
||||
@@ -92,7 +78,13 @@ String File::TranslatePath(CStrRef filename, bool useFileCache /* = false */,
|
||||
}
|
||||
}
|
||||
|
||||
if (canonicalized.charAt(0) == '/' || keepRelative) {
|
||||
return canonicalized;
|
||||
}
|
||||
|
||||
String File::TranslatePath(CStrRef filename) {
|
||||
String canonicalized = TranslatePathKeepRelative(filename);
|
||||
|
||||
if (canonicalized.charAt(0) == '/') {
|
||||
return canonicalized;
|
||||
}
|
||||
|
||||
@@ -103,6 +95,21 @@ String File::TranslatePath(CStrRef filename, bool useFileCache /* = false */,
|
||||
return cwd + "/" + canonicalized;
|
||||
}
|
||||
|
||||
String File::TranslatePathWithFileCache(CStrRef filename) {
|
||||
String canonicalized(Util::canonicalize(filename.data(),
|
||||
filename.size()), AttachString);
|
||||
String translated = TranslatePath(canonicalized);
|
||||
if (!translated.empty() && access(translated.data(), F_OK) < 0 &&
|
||||
StaticContentCache::TheFileCache) {
|
||||
if (StaticContentCache::TheFileCache->exists(canonicalized.data(),
|
||||
false)) {
|
||||
// we use file cache's file name to make stat() work
|
||||
translated = String(RuntimeOption::FileCache);
|
||||
}
|
||||
}
|
||||
return translated;
|
||||
}
|
||||
|
||||
String File::TranslateCommand(CStrRef cmd) {
|
||||
//TODO: security checking
|
||||
return cmd;
|
||||
|
||||
@@ -49,8 +49,11 @@ DECLARE_EXTERN_REQUEST_LOCAL(FileData, s_file_data);
|
||||
*/
|
||||
class File : public SweepableResourceData {
|
||||
public:
|
||||
static String TranslatePath(CStrRef filename, bool useFileCache = false,
|
||||
bool keepRelative = false);
|
||||
static String TranslatePath(CStrRef filename);
|
||||
// Same as TranslatePath except doesn't make paths absolute
|
||||
static String TranslatePathKeepRelative(CStrRef filename);
|
||||
// Same as TranslatePath except checks the file cache on miss
|
||||
static String TranslatePathWithFileCache(CStrRef filename);
|
||||
static String TranslateCommand(CStrRef cmd);
|
||||
static Variant Open(CStrRef filename, CStrRef mode,
|
||||
int options = 0, CVarRef context = uninit_null());
|
||||
|
||||
@@ -494,7 +494,7 @@ static bool findFileWrapper(CStrRef file, void* ctx) {
|
||||
|
||||
// TranslatePath() will canonicalize the path and also check
|
||||
// whether the file is in an allowed directory.
|
||||
String translatedPath = File::TranslatePath(file, false, true);
|
||||
String translatedPath = File::TranslatePathKeepRelative(file);
|
||||
if (file[0] != '/') {
|
||||
if (HPHP::Eval::FileRepository::findFile(translatedPath.get(),
|
||||
context->s)) {
|
||||
|
||||
@@ -1615,7 +1615,7 @@ extern Array stat_impl(struct stat*); // ext_file.cpp
|
||||
template<class Function>
|
||||
static Variant do_lazy_stat(Function dostat, CStrRef filename) {
|
||||
struct stat sb;
|
||||
if (dostat(File::TranslatePath(filename, true).c_str(), &sb)) {
|
||||
if (dostat(File::TranslatePathWithFileCache(filename).c_str(), &sb)) {
|
||||
Logger::Verbose("%s/%d: %s", __FUNCTION__, __LINE__,
|
||||
Util::safe_strerror(errno).c_str());
|
||||
return false;
|
||||
|
||||
@@ -103,8 +103,7 @@ static int accessSyscall(
|
||||
bool useFileCache = false) {
|
||||
Stream::Wrapper* w = Stream::getWrapperFromURI(path);
|
||||
if (useFileCache && dynamic_cast<FileStreamWrapper*>(w)) {
|
||||
// This if block is needed for useFileCache
|
||||
return ::access(File::TranslatePath(path, useFileCache).data(), mode);
|
||||
return ::access(File::TranslatePathWithFileCache(path).data(), mode);
|
||||
}
|
||||
return w->access(path, mode);
|
||||
}
|
||||
@@ -115,8 +114,7 @@ static int statSyscall(
|
||||
bool useFileCache = false) {
|
||||
Stream::Wrapper* w = Stream::getWrapperFromURI(path);
|
||||
if (useFileCache && dynamic_cast<FileStreamWrapper*>(w)) {
|
||||
// This if block is needed for useFileCache
|
||||
return ::stat(File::TranslatePath(path, useFileCache).data(), buf);
|
||||
return ::stat(File::TranslatePathWithFileCache(path).data(), buf);
|
||||
}
|
||||
return w->stat(path, buf);
|
||||
}
|
||||
@@ -127,8 +125,7 @@ static int lstatSyscall(
|
||||
bool useFileCache = false) {
|
||||
Stream::Wrapper* w = Stream::getWrapperFromURI(path);
|
||||
if (useFileCache && dynamic_cast<FileStreamWrapper*>(w)) {
|
||||
// This if block is needed for useFileCache
|
||||
return ::lstat(File::TranslatePath(path, useFileCache).data(), buf);
|
||||
return ::lstat(File::TranslatePathWithFileCache(path).data(), buf);
|
||||
}
|
||||
return w->lstat(path, buf);
|
||||
}
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário