blob: 7a1b1d3154663159f87748efdb8360a467df98fe [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 <memory>
#include <string>
#include "smbprovider/copy_progress_interface.h"
#include "smbprovider/file_copy_progress.h"
#include "smbprovider/iterator/pre_depth_first_iterator.h"
#include "smbprovider/samba_interface.h"
namespace smbprovider {
// Keeps track of the progress of a CopyDirectory operation.
// Each call to ContinueCopy performs one step of the recursive copy progress
// which is either copying a chunk of data in a file or creating a directory.
class RecursiveCopyProgress : public CopyProgressInterface {
explicit RecursiveCopyProgress(SambaInterface* samba_interface);
RecursiveCopyProgress(const RecursiveCopyProgress&) = delete;
RecursiveCopyProgress& operator=(const RecursiveCopyProgress&) = delete;
~RecursiveCopyProgress() override;
// CopyProgressInterface overrides.
bool StartCopy(const std::string& source,
const std::string& target,
int32_t* error) override;
bool ContinueCopy(int32_t* error) override;
void FinishCopy();
int32_t CreateDirectory(const DirectoryEntry& entry);
int32_t StartFileCopy(const DirectoryEntry& entry);
int32_t ContinueFileCopy();
std::string ConvertToTargetPath(const std::string& full_path) const;
// Creates a PreDepthFirstIterator for the source directory at |source_root_|
// and assigns |copy_iterator_| to it.
void CreateCopySourceIterator();
std::unique_ptr<PreDepthFirstIterator> copy_iterator_;
std::unique_ptr<FileCopyProgress> file_progress_;
bool is_started_ = false;
bool is_done_ = false;
SambaInterface* samba_interface_; // not owned.
std::string source_root_;
std::string target_root_;
} // namespace smbprovider