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 <glog/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 cvd::FetcherConfig AvailableFilesReport() {
32   std::string current_directory = cvd::AbsolutePath(cvd::CurrentDirectory());
33   if (cvd::FileExists(current_directory + "/fetcher_config.json")) {
34     cvd::FetcherConfig config;
35     config.LoadFromFile(current_directory + "/fetcher_config.json");
36     return config;
37   }
38 
39   std::set<std::string> files;
40 
41   std::string psuedo_fetcher_dir =
42       cvd::StringFromEnv("ANDROID_HOST_OUT",
43                          cvd::StringFromEnv("HOME", current_directory));
44   std::string psuedo_fetcher_config =
45       psuedo_fetcher_dir + "/launcher_pseudo_fetcher_config.json";
46   files.insert(psuedo_fetcher_config);
47 
48   cvd::FetcherConfig config;
49   config.RecordFlags();
50   for (const auto& file : files) {
51     config.add_cvd_file(cvd::CvdFile(cvd::FileSource::LOCAL_FILE, "", "", file));
52   }
53   config.SaveToFile(psuedo_fetcher_config);
54   return config;
55 }
56