• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2022 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 <chrono>
19 #include <string>
20 #include <vector>
21 
22 #include "common/libs/utils/result.h"
23 #include "host/libs/config/cuttlefish_config.h"
24 #include "host/libs/image_aggregator/image_aggregator.h"
25 
26 namespace cuttlefish {
27 
28 class DiskBuilder {
29  public:
30   DiskBuilder& Partitions(std::vector<ImagePartition> partitions) &;
31   DiskBuilder Partitions(std::vector<ImagePartition> partitions) &&;
32 
33   DiskBuilder& HeaderPath(std::string header_path) &;
34   DiskBuilder HeaderPath(std::string header_path) &&;
35 
36   DiskBuilder& FooterPath(std::string footer_path) &;
37   DiskBuilder FooterPath(std::string footer_path) &&;
38 
39   DiskBuilder& CrosvmPath(std::string crosvm_path) &;
40   DiskBuilder CrosvmPath(std::string crosvm_path) &&;
41 
42   DiskBuilder& VmManager(std::string vm_manager) &;
43   DiskBuilder VmManager(std::string vm_manager) &&;
44 
45   DiskBuilder& ConfigPath(std::string config_path) &;
46   DiskBuilder ConfigPath(std::string config_path) &&;
47 
48   DiskBuilder& CompositeDiskPath(std::string composite_disk_path) &;
49   DiskBuilder CompositeDiskPath(std::string composite_disk_path) &&;
50 
51   DiskBuilder& OverlayPath(std::string overlay_path) &;
52   DiskBuilder OverlayPath(std::string overlay_path) &&;
53 
54   DiskBuilder& ResumeIfPossible(bool resume_if_possible) &;
55   DiskBuilder ResumeIfPossible(bool resume_if_possible) &&;
56 
57   Result<bool> WillRebuildCompositeDisk();
58   /** Returns `true` if the file was actually rebuilt. */
59   Result<bool> BuildCompositeDiskIfNecessary();
60   /** Returns `true` if the file was actually rebuilt. */
61   Result<bool> BuildOverlayIfNecessary();
62 
63  private:
64   Result<std::string> TextConfig();
65 
66   std::vector<ImagePartition> partitions_;
67   std::string header_path_;
68   std::string footer_path_;
69   std::string vm_manager_;
70   std::string crosvm_path_;
71   std::string config_path_;
72   std::string composite_disk_path_;
73   std::string overlay_path_;
74   bool resume_if_possible_;
75 };
76 
77 }  // namespace cuttlefish
78