| 37 | } |
| 38 | |
| 39 | common::Cache::Handle* FileCache::FindFile(const std::string& file_path) { |
| 40 | common::Slice key(file_path); |
| 41 | common::Cache::Handle* handle = cache_->Lookup(key); |
| 42 | if (handle == NULL) { |
| 43 | int fd = open(file_path.c_str(), O_RDONLY); |
| 44 | if (fd < 0) { |
| 45 | LOG(WARNING, "File not found: %s", file_path.c_str()); |
| 46 | return NULL; |
| 47 | } |
| 48 | FileEntity* file = new FileEntity; |
| 49 | file->fd = fd; |
| 50 | file->file_name = file_path; |
| 51 | handle = cache_->Insert(key, file, 1, &DeleteEntry); |
| 52 | } |
| 53 | return handle; |
| 54 | } |
| 55 | |
| 56 | int64_t FileCache::ReadFile(const std::string& file_path, char* buf, |
| 57 | int64_t len, int64_t offset) { |