Android-cuttlefish cvd tool
fetcher_config.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019 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#pragma once
17
18#include <map>
19#include <memory>
20#include <mutex>
21#include <ostream>
22#include <string>
23#include <string_view>
24
25#include "json/value.h"
26
29
30namespace cuttlefish {
31
32/*
33 * Attempts to answer the general question "where did this file come from, and
34 * what purpose is it serving?
35 */
36struct CvdFile {
38 std::string build_id;
39 std::string build_target;
40 std::string file_path;
41 /* If `cvd fetch` extracted this file from an archive, what was the name of
42 * that archive? */
43 std::string archive_source;
44 /* What was the path that the file was stored at in the archive? */
45 std::string archive_path;
46
47 CvdFile();
48 CvdFile(FileSource source, std::string build_id, std::string build_target,
49 std::string file_path, std::string archive_source,
50 std::string archive_path);
51};
52
53std::ostream& operator<<(std::ostream&, const CvdFile&);
54
71 public:
75
76 bool SaveToFile(const std::string& file) const;
77 bool LoadFromFile(const std::string& file);
78
79 bool add_cvd_file(const CvdFile& file, bool override_entry = false);
80 std::map<std::string, CvdFile> get_cvd_files() const;
81
82 std::string FindCvdFileWithSuffix(FileSource source,
83 std::string_view suffix) const;
84
85 Result<void> RemoveFileFromConfig(const std::string& path);
86
87 private:
88 Json::Value dictionary_;
89 std::unique_ptr<std::mutex> mutex_;
90};
91
93 FileSource purpose, std::string build_id, std::string build_target,
94 std::string path, std::string directory_prefix,
95 std::string archive_source = "", std::string archive_path = "");
96
97} // namespace cuttlefish
Definition: fetcher_config.h:70
bool add_cvd_file(const CvdFile &file, bool override_entry=false)
Definition: fetcher_config.cpp:183
FetcherConfig()
Definition: fetcher_config.cpp:77
std::unique_ptr< std::mutex > mutex_
Definition: fetcher_config.h:89
std::string FindCvdFileWithSuffix(FileSource source, std::string_view suffix) const
Definition: fetcher_config.cpp:211
Json::Value dictionary_
Definition: fetcher_config.h:88
Result< void > RemoveFileFromConfig(const std::string &path)
Definition: fetcher_config.cpp:234
bool LoadFromFile(const std::string &file)
Definition: fetcher_config.cpp:109
std::map< std::string, CvdFile > get_cvd_files() const
Definition: fetcher_config.cpp:197
FetcherConfig & operator=(FetcherConfig &&)
Definition: fetcher_config.cpp:87
bool SaveToFile(const std::string &file) const
Definition: fetcher_config.cpp:97
Definition: alloc_driver.h:20
FileSource
Definition: file_source.h:31
tl::expected< T, StackTraceError > Result
Definition: result_type.h:30
std::ostream & operator<<(std::ostream &out, DeviceType device_type)
Definition: device_type.cpp:72
Result< CvdFile > BuildFetcherConfigMember(FileSource purpose, std::string build_id, std::string build_target, std::string path, std::string directory_prefix, std::string archive_source, std::string archive_path)
Definition: fetcher_config.cpp:247
Definition: fetcher_config.h:36
std::string build_id
Definition: fetcher_config.h:38
std::string archive_path
Definition: fetcher_config.h:45
CvdFile()
Definition: fetcher_config.cpp:54
std::string archive_source
Definition: fetcher_config.h:43
FileSource source
Definition: fetcher_config.h:37
std::string file_path
Definition: fetcher_config.h:40
std::string build_target
Definition: fetcher_config.h:39