Android-cuttlefish cvd tool
snapshot_utils.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2023 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <functional>
20#include <string>
21
22#include "json/value.h"
23
26
27namespace cuttlefish {
28
29/*
30 * Copy recursively from src_dir_path to dest_dir_path as long as
31 * the predicate function returns true
32 */
33Result<void> CopyDirectoryRecursively(
34 const std::string& src_dir_path, const std::string& dest_dir_path,
35 bool verify_dest_dir_empty = false,
36 std::function<bool(const std::string&)> predicate = [](const std::string&) {
37 return true;
38 });
39
40Result<Json::Value> CreateMetaInfo(const CuttlefishConfig& config,
41 const std::string& snapshot_path);
42
43Result<std::string> InstanceGuestSnapshotPath(const Json::Value& meta_json,
44 const std::string& instance_id);
45std::string SnapshotMetaJsonPath(const std::string& snapshot_path);
46Result<Json::Value> LoadMetaJson(const std::string& snapshot_path);
47
48Result<std::vector<std::string>> GuestSnapshotDirectories(
49 const std::string& snapshot_path);
50
51inline constexpr const char kMetaInfoJsonFileName[] = "snapshot_meta_info.json";
52inline constexpr const char kGuestSnapshotField[] = "guest_snapshot";
53inline constexpr const char kSnapshotPathField[] = "snapshot_path";
54inline constexpr const char kCfHomeField[] = "HOME";
55inline constexpr const char kGuestSnapshotBase[] = "guest_vm";
56
57} // namespace cuttlefish
Definition: alloc_driver.h:20
constexpr const char kSnapshotPathField[]
Definition: snapshot_utils.h:53
std::string SnapshotMetaJsonPath(const std::string &snapshot_path)
Definition: snapshot_utils.cc:257
constexpr const char kGuestSnapshotField[]
Definition: snapshot_utils.h:52
constexpr const char kCfHomeField[]
Definition: snapshot_utils.h:54
Result< Json::Value > LoadMetaJson(const std::string &snapshot_path)
Definition: snapshot_utils.cc:261
constexpr const char kGuestSnapshotBase[]
Definition: snapshot_utils.h:55
Result< void > CopyDirectoryRecursively(const std::string &src_dir_path, const std::string &dest_dir_path, const bool verify_dest_dir_empty, std::function< bool(const std::string &)> predicate)
Definition: snapshot_utils.cc:164
Result< std::vector< std::string > > GuestSnapshotDirectories(const std::string &snapshot_path)
Definition: snapshot_utils.cc:267
Result< std::string > InstanceGuestSnapshotPath(const Json::Value &meta_json, const std::string &instance_id)
Definition: snapshot_utils.cc:197
constexpr const char kMetaInfoJsonFileName[]
Definition: snapshot_utils.h:51
Result< Json::Value > CreateMetaInfo(const CuttlefishConfig &cuttlefish_config, const std::string &snapshot_path)
Definition: snapshot_utils.cc:214