String FileRepository::translateFileName(StringData *file) { ParsedFilesMap::const_accessor acc; if (!s_files.find(acc, file)) return file; string srcRoot(SourceRootInfo::GetCurrentSourceRoot()); if (srcRoot.empty()) return file; PhpFile *f = acc->second->getPhpFile(); const string &parsedSrcRoot = f->getSrcRoot(); if (srcRoot == parsedSrcRoot) return file; int len = parsedSrcRoot.size(); if (len > 0 && file->size() > len && strncmp(file->data(), parsedSrcRoot.c_str(), len) == 0) { return srcRoot + (file->data() + len); } return file; }
String FileRepository::translateFileName(const string &file) { if (!RuntimeOption::SandboxCheckMd5) return file; hphp_hash_map<string, PhpFileWrapper*, string_hash>::const_iterator iter = s_files.find(file); if (iter == s_files.end()) return file; string srcRoot(SourceRootInfo::GetCurrentSourceRoot()); if (srcRoot.empty()) srcRoot = RuntimeOption::SourceRoot; if (srcRoot.empty()) return file; PhpFile *f = iter->second->getPhpFile(); string parsedSrcRoot = f->getSrcRoot(); if (srcRoot == parsedSrcRoot) return file; unsigned int len = parsedSrcRoot.size(); if (len > 0 && file.size() > len && strncmp(file.data(), parsedSrcRoot.c_str(), len) == 0) { return srcRoot + file.substr(len); } return file; }