• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "filesystem_explorer.h"
17 
18 #include <set>
19 #include <string>
20 
21 #include <dirent.h>
22 #include <errno.h>
23 #include <sys/types.h>
24 
25 #include <android-base/logging.h>
26 
27 #include "common/libs/utils/files.h"
28 #include "common/libs/utils/environment.h"
29 #include "host/libs/config/fetcher_config.h"
30 
AvailableFilesReport()31 cuttlefish::FetcherConfig AvailableFilesReport() {
32   std::string current_directory = cuttlefish::AbsolutePath(cuttlefish::CurrentDirectory());
33   cuttlefish::FetcherConfig config;
34 
35   if (cuttlefish::FileExists(current_directory + "/fetcher_config.json")) {
36     config.LoadFromFile(current_directory + "/fetcher_config.json");
37     return config;
38   }
39 
40   // If needed check if `fetch_config.json` exists inside the $HOME directory.
41   // `assemble_cvd` will perform a similar check.
42   std::string home_directory =
43       cuttlefish::StringFromEnv("HOME", cuttlefish::CurrentDirectory());
44   std::string fetcher_config_path = home_directory + "/fetcher_config.json";
45   if (cuttlefish::FileExists(fetcher_config_path)) {
46     config.LoadFromFile(fetcher_config_path);
47     return config;
48   }
49 
50   std::set<std::string> files;
51 
52   std::string pseudo_fetcher_dir = cuttlefish::StringFromEnv(
53       "ANDROID_HOST_OUT", cuttlefish::StringFromEnv("HOME", current_directory));
54   std::string pseudo_fetcher_config =
55       pseudo_fetcher_dir + "/launcher_pseudo_fetcher_config.json";
56   files.insert(pseudo_fetcher_config);
57 
58   config.RecordFlags();
59   for (const auto& file : files) {
60     config.add_cvd_file(cuttlefish::CvdFile(cuttlefish::FileSource::LOCAL_FILE, "", "", file));
61   }
62   config.SaveToFile(pseudo_fetcher_config);
63   return config;
64 }
65