Ted Bauer | 206d44a | 2024-03-15 17:04:06 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2024 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 | //! Library for finding all aconfig on-device protobuf file paths. |
| 18 | |
| 19 | use anyhow::Result; |
| 20 | use std::path::PathBuf; |
| 21 | |
| 22 | use std::fs; |
| 23 | |
| 24 | /// Determine all paths that contain an aconfig protobuf file. |
| 25 | pub fn parsed_flags_proto_paths() -> Result<Vec<PathBuf>> { |
| 26 | let mut result: Vec<PathBuf> = include!("../partition_aconfig_flags_paths.txt") |
| 27 | .map(|s| PathBuf::from(s.to_string())) |
| 28 | .to_vec(); |
| 29 | for dir in fs::read_dir("/apex")? { |
| 30 | let dir = dir?; |
| 31 | |
| 32 | // Only scan the currently active version of each mainline module; skip the @version dirs. |
| 33 | if dir.file_name().as_encoded_bytes().iter().any(|&b| b == b'@') { |
| 34 | continue; |
| 35 | } |
| 36 | |
| 37 | let mut path = PathBuf::from("/apex"); |
| 38 | path.push(dir.path()); |
| 39 | path.push("etc"); |
| 40 | path.push("aconfig_flags.pb"); |
| 41 | if path.exists() { |
| 42 | result.push(path); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | Ok(result) |
| 47 | } |