blob: ecd0ce252eb6a5f82405be78c526690401042831 [file] [log] [blame]
// Copyright 2018 The Chromium OS 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 <string>
#include <utility>
#include <base/compiler_specific.h>
#include <base/macros.h>
#include "smbprovider/iterator/directory_iterator.h"
#include "smbprovider/metadata_cache.h"
namespace smbprovider {
// Iterator class that wraps a directory iterator and stores each
// entry in a cache as it is iterated over.
class CachingIterator {
CachingIterator(DirectoryIterator it, MetadataCache* cache)
: inner_it_(std::move(it)), cache_(cache) {}
CachingIterator(const std::string& full_path,
SambaInterface* samba_interface,
MetadataCache* cache)
: CachingIterator(DirectoryIterator(full_path, samba_interface), cache) {}
CachingIterator(CachingIterator&& other) = default;
CachingIterator(const CachingIterator&) = delete;
CachingIterator& operator=(const CachingIterator&) = delete;
~CachingIterator() = default;
// Initializes the iterator, setting the first value of current. Returns 0 on
// success, error on failure. Must be called before any other operation.
int32_t Init() WARN_UNUSED_RESULT { return inner_it_.Init(); }
// Advances current to the next entry. Returns 0 on success,
// error on failure.
int32_t Next() WARN_UNUSED_RESULT { return inner_it_.Next(); }
// Returns the current DirectoryEntry.
const DirectoryEntry& Get() {
const DirectoryEntry& entry = inner_it_.Get();
return entry;
// Returns true if there is nothing left to iterate over.
bool IsDone() WARN_UNUSED_RESULT { return inner_it_.IsDone(); }
DirectoryIterator inner_it_;
MetadataCache* cache_ = nullptr; // Not owned.
} // namespace smbprovider