chromium/net/disk_cache/simple/simple_file_enumerator.cc

// Copyright 2022 The Chromium Authors
// 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_file_enumerator.h"

#include "base/files/file.h"
#include "base/files/file_util.h"
#include "base/logging.h"

// We have an optimized implementation for POSIX, and a fallback
// implementation for other platforms.

namespace disk_cache {

#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)

SimpleFileEnumerator::SimpleFileEnumerator(const base::FilePath& path)
    :{}
SimpleFileEnumerator::~SimpleFileEnumerator() = default;

bool SimpleFileEnumerator::HasError() const {}

std::optional<SimpleFileEnumerator::Entry> SimpleFileEnumerator::Next() {}

#else
SimpleFileEnumerator::SimpleFileEnumerator(const base::FilePath& path)
    : enumerator_(path,
                  /*recursive=*/false,
                  base::FileEnumerator::FILES) {}
SimpleFileEnumerator::~SimpleFileEnumerator() = default;

bool SimpleFileEnumerator::HasError() const {
  return enumerator_.GetError() != base::File::FILE_OK;
}

std::optional<SimpleFileEnumerator::Entry> SimpleFileEnumerator::Next() {
  base::FilePath path = enumerator_.Next();
  if (path.empty()) {
    return std::nullopt;
  }
  base::FileEnumerator::FileInfo info = enumerator_.GetInfo();
  return std::make_optional<Entry>(std::move(path), info.GetSize(),
                                   /*last_accessed=*/base::Time(),
                                   info.GetLastModifiedTime());
}
#endif  // BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)

}  // namespace disk_cache