| Index: net/disk_cache/simple/simple_index_file_posix.cc
|
| diff --git a/net/disk_cache/simple/simple_index_file_posix.cc b/net/disk_cache/simple/simple_index_file_posix.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..377041ebf8203a6eb5d8c862c50d5c4803bbf53c
|
| --- /dev/null
|
| +++ b/net/disk_cache/simple/simple_index_file_posix.cc
|
| @@ -0,0 +1,70 @@
|
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "net/disk_cache/simple/simple_index_file.h"
|
| +
|
| +#include <dirent.h>
|
| +#include <sys/stat.h>
|
| +#include <sys/types.h>
|
| +#include <unistd.h>
|
| +
|
| +#include <cstring>
|
| +#include <string>
|
| +
|
| +#include "base/callback.h"
|
| +#include "base/logging.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| +
|
| +namespace disk_cache {
|
| +namespace {
|
| +
|
| +struct DirCloser {
|
| + void operator()(DIR* dir) { closedir(dir); }
|
| +};
|
| +
|
| +typedef scoped_ptr<DIR, DirCloser> ScopedDir;
|
| +
|
| +} // namespace
|
| +
|
| +// static
|
| +bool SimpleIndexFile::TraverseCacheDirectory(
|
| + const std::string& cache_path,
|
| + const EntryFileCallback& entry_file_callback) {
|
| + const ScopedDir dir(opendir(cache_path.c_str()));
|
| + if (!dir) {
|
| + PLOG(ERROR) << "opendir " << cache_path;
|
| + return false;
|
| + }
|
| + dirent entry, *result;
|
| + while (readdir_r(dir.get(), &entry, &result) == 0) {
|
| + if (!result)
|
| + return true; // The traversal completed successfully.
|
| + if (!strcmp(result->d_name, ".") || !strcmp(result->d_name, ".."))
|
| + continue;
|
| + entry_file_callback.Run(result->d_name);
|
| + }
|
| + PLOG(ERROR) << "readdir_r " << cache_path;
|
| + return false;
|
| +}
|
| +
|
| +// static
|
| +bool SimpleIndexFile::GetPlatformFileInfo(const char* path,
|
| + base::PlatformFileInfo* info) {
|
| + // Note that base::GetPlatformFileInfo() is not used here since it takes a
|
| + // file descriptor in which could be inefficient (due to the extra open() +
|
| + // close()).
|
| + struct stat stat_info;
|
| + if (stat(path, &stat_info) < 0) {
|
| + PLOG(ERROR) << "stat " << path;
|
| + return false;
|
| + }
|
| + memset(info, 0, sizeof(*info));
|
| + info->size = stat_info.st_size;
|
| + info->is_directory = stat_info.st_size;
|
| + info->last_modified = base::Time::FromTimeT(stat_info.st_mtime);
|
| + info->last_accessed = base::Time::FromTimeT(stat_info.st_atime);
|
| + return true;
|
| +}
|
| +
|
| +} // namespace disk_cache
|
|
|