Debian Codegraph @

src/bin/apt-add-repository.rs

raw symbols SCIP
1 use apt_sourcesrust-analyzer cargo apt-sources 0.3.0 crate/::key_managementrust-analyzer cargo apt-sources 0.3.0 key_management/::create_inline_signaturerust-analyzer cargo apt-sources 0.3.0 key_management/create_inline_signature().;
2 use apt_sourcesrust-analyzer cargo apt-sources 0.3.0 crate/::launchpadrust-analyzer cargo apt-sources 0.3.0 launchpad/::{
3 download_ppa_signing_keyrust-analyzer cargo apt-sources 0.3.0 launchpad/download_ppa_signing_key()., validate_pparust-analyzer cargo apt-sources 0.3.0 launchpad/validate_ppa()., validate_ppa_componentsrust-analyzer cargo apt-sources 0.3.0 launchpad/validate_ppa_components()., PpaInforust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#, PpaValidationResultrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaValidationResult#,
4 LAUNCHPAD_PPA_URLrust-analyzer cargo apt-sources 0.3.0 launchpad/LAUNCHPAD_PPA_URL.,
5 };
6 use apt_sourcesrust-analyzer cargo apt-sources 0.3.0 crate/::{
7 distributionrust-analyzer cargo apt-sources 0.3.0 distribution/::{get_system_inforust-analyzer cargo apt-sources 0.3.0 distribution/get_system_info()., Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#},
8 legacyrust-analyzer cargo apt-sources 0.3.0 legacy/::LegacyRepositoriesrust-analyzer cargo apt-sources 0.3.0 legacy/LegacyRepositories#,
9 signaturerust-analyzer cargo apt-sources 0.3.0 signature/::Signaturerust-analyzer cargo apt-sources 0.3.0 signature/Signature#,
10 sources_managerrust-analyzer cargo apt-sources 0.3.0 sources_manager/::{
11 FileFormatrust-analyzer cargo apt-sources 0.3.0 sources_manager/FileFormat# as SourcesFileFormatrust-analyzer cargo apt-sources 0.3.0 sources_manager/FileFormat#, SourcesManagerrust-analyzer cargo apt-sources 0.3.0 sources_manager/SourcesManager#, DEFAULT_KEYRING_PATHrust-analyzer cargo apt-sources 0.3.0 sources_manager/DEFAULT_KEYRING_PATH., DEFAULT_SOURCES_PATHrust-analyzer cargo apt-sources 0.3.0 sources_manager/DEFAULT_SOURCES_PATH.,
12 },
13 utilsrust-analyzer cargo apt-sources 0.3.0 utils/::strip_auth_from_urlrust-analyzer cargo apt-sources 0.3.0 utils/strip_auth_from_url().,
14 Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#, Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#, RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#,
15 };
16 use claprust-analyzer cargo clap 4.6.1 crate/::Parserrust-analyzer cargo clap_builder 4.6.0 derive/Parser#;
17 use coloredrust-analyzer cargo colored 3.1.1 crate/::*;
18 use indicatifrust-analyzer cargo indicatif 0.18.4 crate/::{ProgressBarrust-analyzer cargo indicatif 0.18.4 progress_bar/ProgressBar#, ProgressStylerust-analyzer cargo indicatif 0.18.4 style/ProgressStyle#};
19 use logrust-analyzer cargo log 0.4.29 crate/::{debugrust-analyzer cargo log 0.4.29 macros/debug!, errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/, inforust-analyzer cargo log 0.4.29 macros/info!, warnrust-analyzer cargo log 0.4.29 macros/warn!};
20 use reqwestrust-analyzer cargo reqwest 0.12.28 crate/;
21 #[allow(unused_imports)] // Required for Cert::from_str
22 use sequoia_openpgprust-analyzer cargo sequoia-openpgp 2.3.0 crate/::parserust-analyzer cargo sequoia-openpgp 2.3.0 parse/::Parserust-analyzer cargo sequoia-openpgp 2.3.0 parse/Parse#;
23 use sequoia_openpgprust-analyzer cargo sequoia-openpgp 2.3.0 crate/::Certrust-analyzer cargo sequoia-openpgp 2.3.0 cert/Cert#;
24 use serde_jsonrust-analyzer cargo serde_json 1.0.149 crate/;
25 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#;
26 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/;
27 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{selfrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/, Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#};
28 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::{Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#};
29 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::processrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/;
30 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#;
31 use urlrust-analyzer cargo url 2.5.8 crate/::Urlrust-analyzer cargo url 2.5.8 Url#;
32
33 /// Create HTTP client for making requests
34 fn create_http_clientrust-analyzer cargo apt-sources 0.3.0 create_http_client().() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<reqwestrust-analyzer cargo reqwest 0.12.28 crate/::blockingrust-analyzer cargo reqwest 0.12.28 blocking/::Clientrust-analyzer cargo reqwest 0.12.28 blocking/client/Client#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
35 reqwestrust-analyzer cargo reqwest 0.12.28 crate/::blockingrust-analyzer cargo reqwest 0.12.28 blocking/::Clientrust-analyzer cargo reqwest 0.12.28 blocking/client/Client#::builderrust-analyzer cargo reqwest 0.12.28 blocking/client/impl#[Client]builder().()
36 .timeoutrust-analyzer cargo reqwest 0.12.28 blocking/client/impl#[ClientBuilder]timeout().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_secsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_secs().(30))
37 .buildrust-analyzer cargo reqwest 0.12.28 blocking/client/impl#[ClientBuilder]build().()
38 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to create HTTP client: {}", e))
39 }
40
41 /// Format network errors in a user-friendly way
42 fn format_network_errorrust-analyzer cargo apt-sources 0.3.0 format_network_error().(error: &reqwestrust-analyzer cargo reqwest 0.12.28 crate/::Errorrust-analyzer cargo reqwest 0.12.28 error/Error#) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
43 if error.is_timeoutrust-analyzer cargo reqwest 0.12.28 error/impl#[Error]is_timeout().() {
44 "Connection timeout - please check your internet connection".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
45 } else if error.is_connectrust-analyzer cargo reqwest 0.12.28 error/impl#[Error]is_connect().() {
46 "Failed to connect - please check your internet connection".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
47 } else {
48 error.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
49 }
50 }
51
52 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Parserrust-analyzer cargo clap_derive 4.6.1 Parser:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
53 #[command(
54 name = "apt-add-repository",
55 aboutrust-analyzer cargo clap_builder 4.6.0 builder/command/impl#[Command]about(). = "Add APT repository to sources.list.d",
56 long_aboutrust-analyzer cargo clap_builder 4.6.0 builder/command/impl#[Command]long_about(). = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
57 after_helprust-analyzer cargo clap_builder 4.6.0 builder/command/impl#[Command]after_help(). = "Examples:
58 apt-add-repository ppa:user/ppa-name
59 apt-add-repository http://ppa.launchpad.net/example/ppa/ubuntu
60 apt-add-repository \"deb http://archive.ubuntu.com/ubuntu focal main\"
61 apt-add-repository -s http://archive.ubuntu.com/ubuntu
62 apt-add-repository -s # Enable existing disabled deb-src entries
63 apt-add-repository -ss # Enable + create missing deb-src entries
64 apt-add-repository \"ppa:user/ppa1 ppa:user/ppa2\" # Add multiple repositories
65 echo \"ppa:user/ppa-name\" | apt-add-repository -
66 cat repos.txt | apt-add-repository -"
67 )]
68 struct Argsrust-analyzer cargo apt-sources 0.3.0 Args# {
69 /// Repository specification (PPA, URL, or full line, or '-' to read from stdin)
70 #[argrust-analyzer cargo clap_derive 4.6.1 arg:(required_unless_present_anyrust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]required_unless_present_any(). = ["list", "component", "enable_source"])]
71 repositoryrust-analyzer cargo apt-sources 0.3.0 Args#repository.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
72
73 /// Don't update package cache after adding
74 #[argrust-analyzer cargo clap_derive 4.6.1 arg:(shortrust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]short(). = 'n', longrust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]long(). = "no-update")]
75 no_updaterust-analyzer cargo apt-sources 0.3.0 Args#no_update.: bool,
76
77 /// Enable source repositories (-s to enable existing, -ss to create missing)
78 #[argrust-analyzer cargo clap_derive 4.6.1 arg:(shortrust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]short(). = 's', longrust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]long(). = "source", actionrust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]action(). = claprust-analyzer cargo clap 4.6.1 crate/::ArgActionrust-analyzer cargo clap_builder 4.6.0 builder/action/ArgAction#::Countrust-analyzer cargo clap_builder 4.6.0 builder/action/ArgAction#Count#)]
79 enable_sourcerust-analyzer cargo apt-sources 0.3.0 Args#enable_source.: u8,
80
81 /// Assume yes to all queries
82 #[argrust-analyzer cargo clap_derive 4.6.1 arg:(shortrust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]short(). = 'y', longrust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]long(). = "yes")]
83 assume_yesrust-analyzer cargo apt-sources 0.3.0 Args#assume_yes.: bool,
84
85 /// Remove the repository instead of adding
86 #[argrust-analyzer cargo clap_derive 4.6.1 arg:(shortrust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]short(). = 'r', longrust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]long(). = "remove")]
87 removerust-analyzer cargo apt-sources 0.3.0 Args#remove.: bool,
88
89 /// Directory for sources files
90 #[argrust-analyzer cargo clap_derive 4.6.1 arg:(shortrust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]short(). = 'd', longrust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]long(). = "directory", default_valuerust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]default_value(). = DEFAULT_SOURCES_PATHrust-analyzer cargo apt-sources 0.3.0 sources_manager/DEFAULT_SOURCES_PATH.)]
91 directoryrust-analyzer cargo apt-sources 0.3.0 Args#directory.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
92
93 /// Directory for keyring files
94 #[argrust-analyzer cargo clap_derive 4.6.1 arg:(longrust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]long(). = "keyring-dir", default_valuerust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]default_value(). = DEFAULT_KEYRING_PATHrust-analyzer cargo apt-sources 0.3.0 sources_manager/DEFAULT_KEYRING_PATH.)]
95 keyring_dirrust-analyzer cargo apt-sources 0.3.0 Args#keyring_dir.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
96
97 /// Add repository for specified pocket
98 #[argrust-analyzer cargo clap_derive 4.6.1 arg:(shortrust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]short(). = 'p', longrust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]long(). = "pocket")]
99 pocketrust-analyzer cargo apt-sources 0.3.0 Args#pocket.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
100
101 /// Use specified keyserver URL
102 #[argrust-analyzer cargo clap_derive 4.6.1 arg:(shortrust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]short(). = 'k', longrust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]long(). = "keyserver")]
103 keyserverrust-analyzer cargo apt-sources 0.3.0 Args#keyserver.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
104
105 /// Add component to all matching repositories
106 #[argrust-analyzer cargo clap_derive 4.6.1 arg:(longrust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]long(). = "component", conflicts_withrust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]conflicts_with(). = "remove")]
107 componentrust-analyzer cargo apt-sources 0.3.0 Args#component.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
108
109 /// Output format (deb822 or legacy)
110 #[argrust-analyzer cargo clap_derive 4.6.1 arg:(longrust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]long(). = "format", default_valuerust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]default_value(). = "deb822", value_parserrust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]value_parser(). = claprust-analyzer cargo clap 4.6.1 crate/::value_parserrust-analyzer cargo clap_builder 4.6.0 builder/value_parser/value_parser!!(OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#))]
111 formatrust-analyzer cargo apt-sources 0.3.0 Args#format.: OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#,
112
113 /// Preview changes without applying them
114 #[argrust-analyzer cargo clap_derive 4.6.1 arg:(longrust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]long(). = "dry-run")]
115 dry_runrust-analyzer cargo apt-sources 0.3.0 Args#dry_run.: bool,
116
117 /// Login to Launchpad to access private PPAs
118 #[argrust-analyzer cargo clap_derive 4.6.1 arg:(longrust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]long(). = "login")]
119 loginrust-analyzer cargo apt-sources 0.3.0 Args#login.: bool,
120
121 /// List all configured APT repositories
122 #[argrust-analyzer cargo clap_derive 4.6.1 arg:(longrust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]long(). = "list", conflicts_with_allrust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]conflicts_with_all(). = ["repository", "remove", "component", "pocket"])]
123 listrust-analyzer cargo apt-sources 0.3.0 Args#list.: bool,
124
125 /// Refresh signing keys for all PPAs
126 #[argrust-analyzer cargo clap_derive 4.6.1 arg:(longrust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]long(). = "refresh-keys", conflicts_with_allrust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]conflicts_with_all(). = ["repository", "remove", "component", "pocket", "list"])]
127 refresh_keysrust-analyzer cargo apt-sources 0.3.0 Args#refresh_keys.: bool,
128
129 /// Use inline Signed-By instead of separate keyring files (recommended)
130 #[argrust-analyzer cargo clap_derive 4.6.1 arg:(longrust-analyzer cargo clap_builder 4.6.0 builder/arg/impl#[Arg]long(). = "inline-key")]
131 inline_keyrust-analyzer cargo apt-sources 0.3.0 Args#inline_key.: bool,
132 }
133
134 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
135 struct ParsedRepositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository# {
136 repositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository#repository.: Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#,
137 filenamerust-analyzer cargo apt-sources 0.3.0 ParsedRepository#filename.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
138 ppa_inforust-analyzer cargo apt-sources 0.3.0 ParsedRepository#ppa_info.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<PpaInforust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#>,
139 }
140
141 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
142 enum OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat# {
143 Deb822rust-analyzer cargo apt-sources 0.3.0 OutputFormat#Deb822#,
144 Legacyrust-analyzer cargo apt-sources 0.3.0 OutputFormat#Legacy#,
145 }
146
147 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#> for SourcesFileFormatrust-analyzer cargo apt-sources 0.3.0 sources_manager/FileFormat# {
148 fn fromrust-analyzer cargo apt-sources 0.3.0 impl#[SourcesFileFormat][`From<OutputFormat>`]from().(format: OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#) -> Selfrust-analyzer cargo apt-sources 0.3.0 impl#[SourcesFileFormat][`From<OutputFormat>`] {
149 match format {
150 OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::Deb822rust-analyzer cargo apt-sources 0.3.0 OutputFormat#Deb822# => SourcesFileFormatrust-analyzer cargo apt-sources 0.3.0 sources_manager/FileFormat#::Deb822rust-analyzer cargo apt-sources 0.3.0 sources_manager/FileFormat#Deb822#,
151 OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::Legacyrust-analyzer cargo apt-sources 0.3.0 OutputFormat#Legacy# => SourcesFileFormatrust-analyzer cargo apt-sources 0.3.0 sources_manager/FileFormat#::Legacyrust-analyzer cargo apt-sources 0.3.0 sources_manager/FileFormat#Legacy#,
152 }
153 }
154 }
155
156 impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr# for OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat# {
157 type Errrust-analyzer cargo apt-sources 0.3.0 impl#[OutputFormat][FromStr]Err# = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#;
158
159 fn from_strrust-analyzer cargo apt-sources 0.3.0 impl#[OutputFormat][FromStr]from_str().(s: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo apt-sources 0.3.0 impl#[OutputFormat][FromStr], Selfrust-analyzer cargo apt-sources 0.3.0 impl#[OutputFormat][FromStr]::Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#Err#> {
160 match s.to_lowercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_lowercase().().as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().() {
161 "deb822" | "sources" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::Deb822rust-analyzer cargo apt-sources 0.3.0 OutputFormat#Deb822#),
162 "legacy" | "list" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::Legacyrust-analyzer cargo apt-sources 0.3.0 OutputFormat#Legacy#),
163 _ => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Invalid format: {}. Use 'deb822' or 'legacy'", s)),
164 }
165 }
166 }
167
168 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
169 enum RepositorySpecrust-analyzer cargo apt-sources 0.3.0 RepositorySpec# {
170 Componentrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#Component#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#),
171 Pocketrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#Pocket#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#),
172 Repositoryrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#Repository#(ParsedRepositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository#),
173 }
174
175 // PpaInfo struct is now imported from apt_sources::ppa
176
177 // get_distribution_info is replaced by Distribution::current() from apt_sources::distribution
178
179 // get_system_info is now imported from apt_sources::distribution
180
181 fn get_distribution_specific_filenamerust-analyzer cargo apt-sources 0.3.0 get_distribution_specific_filename().(
182 base_name: &str,
183 extension: &str,
184 distribution: &Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#,
185 ) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
186 let dist_name = distribution.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().to_lowercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_lowercase().();
187 // For main repos (base_name == "custom" or contains the distribution name), use distribution name
188 if base_name rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."custom" || base_name.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().(&dist_name) {
189 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}.{}", dist_name, extension)
190 } else {
191 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}.{}", base_name, extension)
192 }
193 }
194
195 fn determine_repository_filepathrust-analyzer cargo apt-sources 0.3.0 determine_repository_filepath().(
196 parsed: &ParsedRepositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository#,
197 args: &Argsrust-analyzer cargo apt-sources 0.3.0 Args#,
198 distribution: &Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#,
199 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
200 // Check if this is a main distribution repository
201 let is_main_repo = distribution.is_main_repositoryrust-analyzer cargo apt-sources 0.3.0 distribution/impl#[Distribution]is_main_repository().(&parsed.repositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository#repository.);
202
203 if is_main_repo {
204 // For main distribution repositories, prefer to use the main distribution file
205 let main_file = match (&distribution, args.formatrust-analyzer cargo apt-sources 0.3.0 Args#format.) {
206 (Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#::Ubunturust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#Ubuntu#, OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::Deb822rust-analyzer cargo apt-sources 0.3.0 OutputFormat#Deb822#) => {
207 Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(&args.directoryrust-analyzer cargo apt-sources 0.3.0 Args#directory.).joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("ubuntu.sources")
208 }
209 (Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#::Ubunturust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#Ubuntu#, OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::Legacyrust-analyzer cargo apt-sources 0.3.0 OutputFormat#Legacy#) => {
210 get_main_sources_list_pathrust-analyzer cargo apt-sources 0.3.0 get_main_sources_list_path().(&args.directoryrust-analyzer cargo apt-sources 0.3.0 Args#directory.)
211 }
212 (Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#::Debianrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#Debian#, OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::Deb822rust-analyzer cargo apt-sources 0.3.0 OutputFormat#Deb822#) => {
213 Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(&args.directoryrust-analyzer cargo apt-sources 0.3.0 Args#directory.).joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("debian.sources")
214 }
215 (Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#::Debianrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#Debian#, OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::Legacyrust-analyzer cargo apt-sources 0.3.0 OutputFormat#Legacy#) => {
216 get_main_sources_list_pathrust-analyzer cargo apt-sources 0.3.0 get_main_sources_list_path().(&args.directoryrust-analyzer cargo apt-sources 0.3.0 Args#directory.)
217 }
218 _ => {
219 // For other distributions, fall back to sources.list.d
220 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(&args.directoryrust-analyzer cargo apt-sources 0.3.0 Args#directory.).joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(&parsed.filenamerust-analyzer cargo apt-sources 0.3.0 ParsedRepository#filename.));
221 }
222 };
223
224 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(main_file)
225 } else {
226 // For third-party repositories, use sources.list.d
227 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(&args.directoryrust-analyzer cargo apt-sources 0.3.0 Args#directory.).joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(&parsed.filenamerust-analyzer cargo apt-sources 0.3.0 ParsedRepository#filename.))
228 }
229 }
230
231 fn is_main_distribution_filerust-analyzer cargo apt-sources 0.3.0 is_main_distribution_file().(path: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#) -> bool {
232 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(filename) = path.file_namerust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]file_name().().and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|n| n.to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_str().()) {
233 matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(
234 filename,
235 "sources.list" | "ubuntu.sources" | "ubuntu.list" | "debian.sources" | "debian.list"
236 )
237 } else {
238 false
239 }
240 }
241
242 /// Derive the path to sources.list from the sources.list.d directory.
243 /// For example, /etc/apt/sources.list.d -> /etc/apt/sources.list
244 fn get_main_sources_list_pathrust-analyzer cargo apt-sources 0.3.0 get_main_sources_list_path().(sources_dir: &str) -> PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf# {
245 Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(sources_dir)
246 .parentrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]parent().()
247 .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().("/etc/apt"))
248 .joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("sources.list")
249 }
250
251 // download_key_from_keyserver - wrapper with progress indicator
252 fn download_key_from_keyserverrust-analyzer cargo apt-sources 0.3.0 download_key_from_keyserver().(fingerprint: &str, keyserver_url: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
253 let spinner = ProgressBarrust-analyzer cargo indicatif 0.18.4 progress_bar/ProgressBar#::new_spinnerrust-analyzer cargo indicatif 0.18.4 progress_bar/impl#[ProgressBar]new_spinner().();
254 spinner.set_stylerust-analyzer cargo indicatif 0.18.4 progress_bar/impl#[ProgressBar]set_style().(
255 ProgressStylerust-analyzer cargo indicatif 0.18.4 style/ProgressStyle#::default_spinnerrust-analyzer cargo indicatif 0.18.4 style/impl#[ProgressStyle]default_spinner().()
256 .templaterust-analyzer cargo indicatif 0.18.4 style/impl#[ProgressStyle]template().("{spinner:.green} {msg}")
257 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
258 );
259 spinner.set_messagerust-analyzer cargo indicatif 0.18.4 progress_bar/impl#[ProgressBar]set_message().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
260 "Downloading key {} from keyserver {}...",
261 fingerprint, keyserver_url
262 ));
263 spinner.enable_steady_tickrust-analyzer cargo indicatif 0.18.4 progress_bar/impl#[ProgressBar]enable_steady_tick().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_millisrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_millis().(100));
264
265 let result =
266 apt_sourcesrust-analyzer cargo apt-sources 0.3.0 crate/::keyserverrust-analyzer cargo apt-sources 0.3.0 keyserver/::download_key_from_keyserver_syncrust-analyzer cargo apt-sources 0.3.0 keyserver/download_key_from_keyserver_sync().(fingerprint, keyserver_url);
267
268 match result {
269 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(key_data) => {
270 spinner.finish_with_messagerust-analyzer cargo indicatif 0.18.4 progress_bar/impl#[ProgressBar]finish_with_message().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Successfully downloaded key {}", fingerprint));
271 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(key_data)
272 }
273 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
274 spinner.finish_and_clearrust-analyzer cargo indicatif 0.18.4 progress_bar/impl#[ProgressBar]finish_and_clear().();
275 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e)
276 }
277 }
278 }
279
280 #[cfg(feature = "launchpad")]
281 fn validate_ppa_launchpadlibrust-analyzer cargo apt-sources 0.3.0 validate_ppa_launchpadlib().(
282 ppa_info: &PpaInforust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#,
283 auth_required: bool,
284 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<PpaValidationResultrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaValidationResult#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
285 debugrust-analyzer cargo log 0.4.29 macros/debug!!(
286 "Validating PPA {}/{} using launchpadlib",
287 ppa_info.userrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#user., ppa_info.namerust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#name.
288 );
289 validate_pparust-analyzer cargo apt-sources 0.3.0 launchpad/validate_ppa().(ppa_info, auth_required).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| e.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
290 }
291
292 /// Validate PPA and provide user-friendly error messages
293 fn validate_ppa_with_suggestionsrust-analyzer cargo apt-sources 0.3.0 validate_ppa_with_suggestions().(ppa_info: &PpaInforust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<PpaValidationResultrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaValidationResult#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
294 inforust-analyzer cargo log 0.4.29 macros/info!!(
295 "Checking if PPA {}/{} exists...",
296 ppa_info.userrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#user., ppa_info.namerust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#name.
297 );
298
299 let result = validate_pparust-analyzer cargo apt-sources 0.3.0 launchpad/validate_ppa().(ppa_info, false).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| e.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
300
301 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().result.existsrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaValidationResult#exists. {
302 if result.is_privaterust-analyzer cargo apt-sources 0.3.0 launchpad/PpaValidationResult#is_private. {
303 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
304 "PPA {}/{} is private.\n\
305 To access private PPAs:\n\
306 1. Use the --login flag to authenticate with Launchpad\n\
307 2. Ensure you're subscribed to this PPA\n\
308 3. Check that apt-add-repository was built with launchpad support",
309 ppa_info.userrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#user., ppa_info.namerust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#name.
310 ));
311 } else {
312 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
313 "PPA {}/{} not found.\n\
314 Suggestions:\n\
315 - Check the PPA name for typos\n\
316 - Verify the user '{}' exists on Launchpad\n\
317 - Browse available PPAs at https://launchpad.net/~{}/+ppas",
318 ppa_info.userrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#user., ppa_info.namerust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#name., ppa_info.userrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#user., ppa_info.userrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#user.
319 ));
320 }
321 }
322
323 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(result)
324 }
325
326 #[cfg(feature = "launchpad")]
327 fn get_private_ppa_urlrust-analyzer cargo apt-sources 0.3.0 get_private_ppa_url().(ppa_info: &PpaInforust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Urlrust-analyzer cargo url 2.5.8 Url#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
328 debugrust-analyzer cargo log 0.4.29 macros/debug!!(
329 "Getting private PPA URL for {}/{}",
330 ppa_info.userrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#user., ppa_info.namerust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#name.
331 );
332 apt_sourcesrust-analyzer cargo apt-sources 0.3.0 crate/::launchpadrust-analyzer cargo apt-sources 0.3.0 launchpad/::get_private_ppa_urlrust-analyzer cargo apt-sources 0.3.0 launchpad/get_private_ppa_url().(ppa_info).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| e.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
333 }
334
335 #[cfg(feature = "launchpad")]
336 fn download_ppa_key_launchpadlibrust-analyzer cargo apt-sources 0.3.0 download_ppa_key_launchpadlib().(
337 ppa_info: &PpaInforust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#,
338 auth_required: bool,
339 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
340 debugrust-analyzer cargo log 0.4.29 macros/debug!!(
341 "Using launchpadlib to download PPA key for {}/{}",
342 ppa_info.userrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#user., ppa_info.namerust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#name.
343 );
344
345 let signing_key =
346 download_ppa_signing_keyrust-analyzer cargo apt-sources 0.3.0 launchpad/download_ppa_signing_key().(ppa_info, auth_required).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| e.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
347
348 // Additionally check expiration
349 let cert = Certrust-analyzer cargo sequoia-openpgp 2.3.0 cert/Cert#::from_strrust-analyzer cargo sequoia-openpgp 2.3.0 cert/impl#[Cert][FromStr]from_str().(&signing_key.key_datarust-analyzer cargo apt-sources 0.3.0 launchpad/PpaSigningKey#key_data.)
350 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to parse PGP key for expiration check: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
351
352 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(expiration_error) = apt_sourcesrust-analyzer cargo apt-sources 0.3.0 crate/::key_managementrust-analyzer cargo apt-sources 0.3.0 key_management/::check_key_expirationrust-analyzer cargo apt-sources 0.3.0 key_management/check_key_expiration().(&cert) {
353 let expiration_warning = expiration_error.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
354 if expiration_warning.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("expired") {
355 errorrust-analyzer cargo log 0.4.29 macros/error!!("Key expiration: {}", expiration_warning);
356 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Cannot use expired key: {}", expiration_warning));
357 } else {
358 warnrust-analyzer cargo log 0.4.29 macros/warn!!("Key expiration warning: {}", expiration_warning);
359 }
360 }
361
362 inforust-analyzer cargo log 0.4.29 macros/info!!(
363 "Downloaded and verified PPA signing key with fingerprint: {}",
364 signing_key.fingerprintrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaSigningKey#fingerprint.
365 );
366 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(signing_key.key_datarust-analyzer cargo apt-sources 0.3.0 launchpad/PpaSigningKey#key_data.)
367 }
368
369 // verify_key_fingerprint - wrapper that adds expiration check and logging
370 fn verify_key_fingerprintrust-analyzer cargo apt-sources 0.3.0 verify_key_fingerprint().(key_data: &str, expected_fingerprint: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
371 debugrust-analyzer cargo log 0.4.29 macros/debug!!(
372 "Verifying key fingerprint against expected: {}",
373 expected_fingerprint
374 );
375
376 // Use the crate's fingerprint verification
377 apt_sourcesrust-analyzer cargo apt-sources 0.3.0 crate/::key_managementrust-analyzer cargo apt-sources 0.3.0 key_management/::verify_key_fingerprintrust-analyzer cargo apt-sources 0.3.0 key_management/verify_key_fingerprint().(key_data, expected_fingerprint)
378 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| e.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
379
380 // Additionally check expiration
381 let cert = Certrust-analyzer cargo sequoia-openpgp 2.3.0 cert/Cert#::from_strrust-analyzer cargo sequoia-openpgp 2.3.0 cert/impl#[Cert][FromStr]from_str().(key_data)
382 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to parse PGP key for expiration check: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
383
384 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(expiration_error) = apt_sourcesrust-analyzer cargo apt-sources 0.3.0 crate/::key_managementrust-analyzer cargo apt-sources 0.3.0 key_management/::check_key_expirationrust-analyzer cargo apt-sources 0.3.0 key_management/check_key_expiration().(&cert) {
385 let expiration_warning = expiration_error.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
386 if expiration_warning.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("expired") {
387 errorrust-analyzer cargo log 0.4.29 macros/error!!("Key expiration: {}", expiration_warning);
388 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Cannot use expired key: {}", expiration_warning));
389 } else {
390 warnrust-analyzer cargo log 0.4.29 macros/warn!!("Key expiration warning: {}", expiration_warning);
391 }
392 }
393
394 debugrust-analyzer cargo log 0.4.29 macros/debug!!("Key fingerprint verification successful");
395 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
396 }
397
398 fn download_ppa_keyrust-analyzer cargo apt-sources 0.3.0 download_ppa_key().(ppa_info: &PpaInforust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#, keyserver: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
399 inforust-analyzer cargo log 0.4.29 macros/info!!(
400 "Downloading signing key for PPA {}/{}...",
401 ppa_info.userrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#user., ppa_info.namerust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#name.
402 );
403
404 let key_data = if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(keyserver_url) = keyserver {
405 // Use custom keyserver - need to get fingerprint first
406 debugrust-analyzer cargo log 0.4.29 macros/debug!!("Using custom keyserver: {}", keyserver_url);
407 let api_url = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
408 "https://api.launchpad.net/1.0/~{}/+archive/ubuntu/{}",
409 ppa_info.userrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#user., ppa_info.namerust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#name.
410 );
411
412 let client = create_http_clientrust-analyzer cargo apt-sources 0.3.0 create_http_client().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
413 let ppa_response = client
414 .getrust-analyzer cargo reqwest 0.12.28 blocking/client/impl#[Client]get().(&api_url)
415 .headerrust-analyzer cargo reqwest 0.12.28 blocking/request/impl#[RequestBuilder]header().("Accept", "application/json")
416 .sendrust-analyzer cargo reqwest 0.12.28 blocking/request/impl#[RequestBuilder]send().()
417 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to fetch PPA metadata: {}", format_network_errorrust-analyzer cargo apt-sources 0.3.0 format_network_error().(&e)))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
418
419 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().ppa_response.statusrust-analyzer cargo reqwest 0.12.28 blocking/response/impl#[Response]status().().is_successrust-analyzer cargo http 1.4.0 status/impl#[StatusCode]is_success().() {
420 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
421 "PPA not found: {}/{}",
422 ppa_info.userrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#user., ppa_info.namerust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#name.
423 ));
424 }
425
426 let ppa_data: serde_jsonrust-analyzer cargo serde_json 1.0.149 crate/::Valuerust-analyzer cargo serde_json 1.0.149 value/Value# = ppa_response
427 .jsonrust-analyzer cargo reqwest 0.12.28 blocking/response/impl#[Response]json().()
428 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to parse PPA metadata: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
429
430 let fingerprint = ppa_data
431 .getrust-analyzer cargo serde_json 1.0.149 value/impl#[Value]get().("signing_key_fingerprint")
432 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|v| v.as_strrust-analyzer cargo serde_json 1.0.149 value/impl#[Value]as_str().())
433 .ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| "PPA has no signing key configured".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
434
435 let key = download_key_from_keyserverrust-analyzer cargo apt-sources 0.3.0 download_key_from_keyserver().(fingerprint, keyserver_url)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
436
437 // Verify the key fingerprint matches what we expect
438 verify_key_fingerprintrust-analyzer cargo apt-sources 0.3.0 verify_key_fingerprint().(&key, fingerprint)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
439 key
440 } else {
441 // Use library function for default Launchpad download
442 download_ppa_signing_keyrust-analyzer cargo apt-sources 0.3.0 launchpad/download_ppa_signing_key().(ppa_info, false)
443 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| e.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
444 .key_datarust-analyzer cargo apt-sources 0.3.0 launchpad/PpaSigningKey#key_data.
445 };
446
447 inforust-analyzer cargo log 0.4.29 macros/info!!("Downloaded PPA signing key");
448 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(key_data)
449 }
450
451 fn save_key_to_keyringrust-analyzer cargo apt-sources 0.3.0 save_key_to_keyring().(
452 key_data: &str,
453 keyring_dir: &str,
454 ppa_info: &PpaInforust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#,
455 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
456 // The key data from Launchpad is already in armored format,
457 // but let's parse it to validate it's a proper key
458 let cert = Certrust-analyzer cargo sequoia-openpgp 2.3.0 cert/Cert#::from_strrust-analyzer cargo sequoia-openpgp 2.3.0 cert/impl#[Cert][FromStr]from_str().(key_data).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to parse PGP key: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
459
460 // Verify the key is valid
461 let policy = sequoia_openpgprust-analyzer cargo sequoia-openpgp 2.3.0 crate/::policyrust-analyzer cargo sequoia-openpgp 2.3.0 policy/::StandardPolicyrust-analyzer cargo sequoia-openpgp 2.3.0 policy/StandardPolicy#::newrust-analyzer cargo sequoia-openpgp 2.3.0 policy/impl#[`StandardPolicy<'a>`]new().();
462 if cert.with_policyrust-analyzer cargo sequoia-openpgp 2.3.0 cert/impl#[Cert]with_policy().(&policy, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().() {
463 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#("Invalid or expired PGP key".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
464 }
465
466 // Save to keyring directory
467 // Use .asc extension for ASCII-armored keys (apt prefers this)
468 let keyring_path = Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(keyring_dir).joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(ppa_info.keyring_filenamerust-analyzer cargo apt-sources 0.3.0 launchpad/impl#[PpaInfo]keyring_filename().());
469
470 // Check if keyring directory exists
471 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(keyring_dir).existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().() {
472 fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::create_dir_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/create_dir_all().(keyring_dir)
473 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to create keyring directory: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
474 }
475
476 // Write the key in ASCII-armored format
477 // Since the data from Launchpad is already armored, we can write it directly
478 fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/write().(&keyring_path, key_data)
479 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to write key to file: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
480
481 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(keyring_path)
482 }
483
484 /// Save the PPA key and return the appropriate Signature.
485 /// If inline_key is true and format is Deb822, tries inline signature first,
486 /// falling back to keyring file on failure.
487 fn save_ppa_keyrust-analyzer cargo apt-sources 0.3.0 save_ppa_key().(
488 key_data: &str,
489 ppa_info: &PpaInforust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#,
490 keyring_dir: &str,
491 use_inline: bool,
492 ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Signaturerust-analyzer cargo apt-sources 0.3.0 signature/Signature#> {
493 if use_inline {
494 match create_inline_signaturerust-analyzer cargo apt-sources 0.3.0 key_management/create_inline_signature().(key_data) {
495 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(inline_sig) => {
496 inforust-analyzer cargo log 0.4.29 macros/info!!("Using inline Signed-By (embedded key)");
497 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(inline_sig);
498 }
499 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
500 warnrust-analyzer cargo log 0.4.29 macros/warn!!("Failed to create inline signature: {}", e);
501 warnrust-analyzer cargo log 0.4.29 macros/warn!!("Falling back to keyring file");
502 }
503 }
504 }
505
506 match save_key_to_keyringrust-analyzer cargo apt-sources 0.3.0 save_key_to_keyring().(key_data, keyring_dir, ppa_info) {
507 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(keyring_path) => {
508 inforust-analyzer cargo log 0.4.29 macros/info!!("Signing key saved to {}", keyring_path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().());
509 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Signaturerust-analyzer cargo apt-sources 0.3.0 signature/Signature#::KeyPathrust-analyzer cargo apt-sources 0.3.0 signature/Signature#KeyPath#(keyring_path))
510 }
511 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
512 warnrust-analyzer cargo log 0.4.29 macros/warn!!("Failed to save signing key: {}", e);
513 warnrust-analyzer cargo log 0.4.29 macros/warn!!("The repository will be added without signature verification.");
514 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
515 }
516 }
517 }
518
519 fn parse_repository_linerust-analyzer cargo apt-sources 0.3.0 parse_repository_line().(
520 line: &str,
521 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<
522 (
523 Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#>,
524 Urlrust-analyzer cargo url 2.5.8 Url#,
525 Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
526 Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
527 Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#>,
528 ),
529 Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
530 > {
531 let parts: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&str> = line.split_whitespacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_whitespace().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
532
533 if parts.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
534 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#("Empty repository line".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
535 }
536
537 let mut idx = 0;
538 let mut signed_by = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
539 let mut _arch = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
540
541 // Parse repository type
542 let types = match parts[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().idx]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). {
543 "deb" => vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary#],
544 "deb-src" => vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Sourcerust-analyzer cargo apt-sources 0.3.0 RepositoryType#Source#],
545 _ => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#("Repository line must start with 'deb' or 'deb-src'".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()),
546 };
547 idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
548
549 // Parse options if present
550 if idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().parts.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() && parts[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().idx]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().('[') {
551 let options_end = parts
552 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
553 .positionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]position().(|&p| p.ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().(']'))
554 .ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().("Unclosed options bracket")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
555
556 let options_str = parts[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().idx..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#options_end]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..joinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]join().(" ");
557 let options_str = options_str.trim_start_matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim_start_matches().('[').trim_end_matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim_end_matches().(']');
558
559 for option in options_str.split_whitespacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_whitespace().() {
560 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((key, value)) = option.split_oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_once().('=') {
561 match key {
562 "arch" => _arch = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()),
563 "signed-by" => signed_by = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][`From<&T>`]from().(value)),
564 _ => {} // Ignore other options for now
565 }
566 }
567 }
568
569 idx = options_end rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1;
570 }
571
572 if idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().parts.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() {
573 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#("Invalid repository line format".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
574 }
575
576 let uri = Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().(parts[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().idx]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Invalid URL: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
577
578 // Strip auth data from URL for storage
579 let (clean_uri, auth_data) = strip_auth_from_urlrust-analyzer cargo apt-sources 0.3.0 utils/strip_auth_from_url().(&uri);
580 if auth_data.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
581 debugrust-analyzer cargo log 0.4.29 macros/debug!!("Repository URL contains authentication data, stripping for storage");
582 }
583
584 let suite = parts[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
585 let components = parts[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().2..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|&s| s.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
586
587 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((types, clean_uri, suite, components, signed_by))
588 }
589
590 fn parse_repository_specrust-analyzer cargo apt-sources 0.3.0 parse_repository_spec().(
591 spec: &str,
592 enable_source_count: u8,
593 args: &Argsrust-analyzer cargo apt-sources 0.3.0 Args#,
594 distribution: &Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#,
595 codename: &str,
596 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<RepositorySpecrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
597 // Check if it's just a component name (universe, multiverse, etc.)
598 let valid_components = match &distribution {
599 Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#::Ubunturust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#Ubuntu# => vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["main", "universe", "multiverse", "restricted"],
600 Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#::Debianrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#Debian# => vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["main", "contrib", "non-free", "non-free-firmware"],
601 Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#::Otherrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#Other#(_) => vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
602 "main",
603 "universe",
604 "multiverse",
605 "restricted",
606 "contrib",
607 "non-free",
608 "non-free-firmware",
609 ],
610 };
611 if valid_components.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&spec) {
612 debugrust-analyzer cargo log 0.4.29 macros/debug!!(
613 "Adding component {} to existing {} repositories",
614 spec, distribution
615 );
616 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(RepositorySpecrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#::Componentrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#Component#(spec.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
617 }
618
619 // Check if it's a pocket specification (e.g., focal-proposed, bionic-backports)
620 let valid_pockets = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["proposed", "backports", "security", "updates"];
621 for pocket in &valid_pockets {
622 if spec.ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("-{}", pocket)) {
623 debugrust-analyzer cargo log 0.4.29 macros/debug!!("Adding pocket {} repositories", spec);
624 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(RepositorySpecrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#::Pocketrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#Pocket#(spec.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
625 }
626 }
627
628 // Check if it's a PPA
629 if spec.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("ppa:") {
630 let ppa_info = PpaInforust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#::parserust-analyzer cargo apt-sources 0.3.0 launchpad/impl#[PpaInfo]parse().(spec)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
631
632 let types = if enable_source_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().0 {
633 HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`][`From<[T; N]>`]from().([RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary#, RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Sourcerust-analyzer cargo apt-sources 0.3.0 RepositoryType#Source#])
634 } else {
635 HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`][`From<[T; N]>`]from().([RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary#])
636 };
637
638 // Generate PPA URL (with authentication for private PPAs if needed)
639 let uri = if args.loginrust-analyzer cargo apt-sources 0.3.0 Args#login. {
640 // For private PPAs, we need to get the subscription URL from launchpadlib
641 #[cfg(feature = "launchpad")]
642 {
643 get_private_ppa_urlrust-analyzer cargo apt-sources 0.3.0 get_private_ppa_url().(&ppa_info)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
644 }
645 #[cfg(not(feature = "launchpad"))]
646 {
647 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#("Private PPA support requires the 'launchpad' feature".to_string());
648 }
649 } else {
650 Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
651 "{}/{}/{}/ubuntu",
652 LAUNCHPAD_PPA_URLrust-analyzer cargo apt-sources 0.3.0 launchpad/LAUNCHPAD_PPA_URL., ppa_info.userrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#user., ppa_info.namerust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#name.
653 ))
654 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
655 };
656
657 // Validate components for PPA
658 let components = if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref comps) = args.componentrust-analyzer cargo apt-sources 0.3.0 Args#component. {
659 // User specified components - validate them
660 let comp_vec = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![comps.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().()];
661 validate_ppa_componentsrust-analyzer cargo apt-sources 0.3.0 launchpad/validate_ppa_components().(&comp_vec)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
662 comp_vec
663 } else {
664 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["main".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()]
665 };
666
667 let repository = Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository# {
668 enabledrust-analyzer cargo apt-sources 0.3.0 Repository#enabled.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(true),
669 typesrust-analyzer cargo apt-sources 0.3.0 Repository#types.,
670 architecturesrust-analyzer cargo apt-sources 0.3.0 Repository#architectures.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
671 urisrust-analyzer cargo apt-sources 0.3.0 Repository#uris.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![uri],
672 suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![codename.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()],
673 componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(components),
674 signaturerust-analyzer cargo apt-sources 0.3.0 Repository#signature.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, // Will be set after key download
675 x_repolib_namerust-analyzer cargo apt-sources 0.3.0 Repository#x_repolib_name.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("ppa:{}/{}", ppa_info.userrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#user., ppa_info.namerust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#name.)),
676 ..Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Default]default().()
677 };
678
679 let extension = match args.formatrust-analyzer cargo apt-sources 0.3.0 Args#format. {
680 OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::Legacyrust-analyzer cargo apt-sources 0.3.0 OutputFormat#Legacy# => "list",
681 OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::Deb822rust-analyzer cargo apt-sources 0.3.0 OutputFormat#Deb822# => "sources",
682 };
683 let filename = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
684 "{}-ubuntu-{}-{}.{}",
685 ppa_info.userrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#user., ppa_info.namerust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#name., codename, extension
686 );
687
688 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(RepositorySpecrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#::Repositoryrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#Repository#(ParsedRepositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository# {
689 repositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository#repository.,
690 filenamerust-analyzer cargo apt-sources 0.3.0 ParsedRepository#filename.,
691 ppa_inforust-analyzer cargo apt-sources 0.3.0 ParsedRepository#ppa_info.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ppa_info),
692 }));
693 }
694
695 // Check if it's a full deb line
696 if spec.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("deb ") || spec.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("deb-src ") {
697 let (parsed_types, uri, suite, components, signed_by) = parse_repository_linerust-analyzer cargo apt-sources 0.3.0 parse_repository_line().(spec)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
698
699 // Check if this is a PPA URL and validate components
700 if uri
701 .host_strrust-analyzer cargo url 2.5.8 impl#[Url]host_str().()
702 .map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().(false, |h| h.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("ppa.launchpadcontent.net"))
703 {
704 validate_ppa_componentsrust-analyzer cargo apt-sources 0.3.0 launchpad/validate_ppa_components().(&components)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
705 }
706
707 let mut types = HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`]new().();
708 for t in parsed_types {
709 types.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().(t);
710 }
711
712 if enable_source_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().0 {
713 types.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().(RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Sourcerust-analyzer cargo apt-sources 0.3.0 RepositoryType#Source#);
714 }
715
716 let mut repository = Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository# {
717 enabledrust-analyzer cargo apt-sources 0.3.0 Repository#enabled.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(true),
718 typesrust-analyzer cargo apt-sources 0.3.0 Repository#types.,
719 architecturesrust-analyzer cargo apt-sources 0.3.0 Repository#architectures.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
720 urisrust-analyzer cargo apt-sources 0.3.0 Repository#uris.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![uri.clonerust-analyzer cargo url 2.5.8 impl#[Url][Clone]clone().()],
721 suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![suite],
722 componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(components),
723 ..Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Default]default().()
724 };
725
726 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(keypath) = signed_by {
727 repository.signaturerust-analyzer cargo apt-sources 0.3.0 Repository#signature. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Signaturerust-analyzer cargo apt-sources 0.3.0 signature/Signature#::KeyPathrust-analyzer cargo apt-sources 0.3.0 signature/Signature#KeyPath#(keypath));
728 }
729
730 let filename = generate_filenamerust-analyzer cargo apt-sources 0.3.0 generate_filename().(uri.as_strrust-analyzer cargo url 2.5.8 impl#[Url]as_str().(), args.formatrust-analyzer cargo apt-sources 0.3.0 Args#format., &distribution);
731
732 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(RepositorySpecrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#::Repositoryrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#Repository#(ParsedRepositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository# {
733 repositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository#repository.,
734 filenamerust-analyzer cargo apt-sources 0.3.0 ParsedRepository#filename.,
735 ppa_inforust-analyzer cargo apt-sources 0.3.0 ParsedRepository#ppa_info.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
736 }));
737 }
738
739 // Try to parse as URL
740 let uri = Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().(spec).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| {
741 "Invalid repository specification. Expected PPA, URL, or full deb line".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
742 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
743
744 // Strip auth data from URL for storage
745 let (clean_uri, auth_data) = strip_auth_from_urlrust-analyzer cargo apt-sources 0.3.0 utils/strip_auth_from_url().(&uri);
746 if auth_data.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
747 inforust-analyzer cargo log 0.4.29 macros/info!!("Repository URL contains authentication data, which will be stored securely");
748 }
749
750 // Use system codename and default to 'main' component
751 let (suite, components) = default_suite_componentsrust-analyzer cargo apt-sources 0.3.0 default_suite_components().(&codename);
752
753 let types = if enable_source_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().0 {
754 HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`][`From<[T; N]>`]from().([RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary#, RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Sourcerust-analyzer cargo apt-sources 0.3.0 RepositoryType#Source#])
755 } else {
756 HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`][`From<[T; N]>`]from().([RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary#])
757 };
758
759 let repository = Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository# {
760 enabledrust-analyzer cargo apt-sources 0.3.0 Repository#enabled.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(true),
761 typesrust-analyzer cargo apt-sources 0.3.0 Repository#types.,
762 architecturesrust-analyzer cargo apt-sources 0.3.0 Repository#architectures.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
763 urisrust-analyzer cargo apt-sources 0.3.0 Repository#uris.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![clean_uri.clonerust-analyzer cargo url 2.5.8 impl#[Url][Clone]clone().()],
764 suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![suite],
765 componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(components),
766 ..Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Default]default().()
767 };
768
769 let filename = generate_filenamerust-analyzer cargo apt-sources 0.3.0 generate_filename().(uri.as_strrust-analyzer cargo url 2.5.8 impl#[Url]as_str().(), args.formatrust-analyzer cargo apt-sources 0.3.0 Args#format., &distribution);
770
771 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(RepositorySpecrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#::Repositoryrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#Repository#(ParsedRepositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository# {
772 repositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository#repository.,
773 filenamerust-analyzer cargo apt-sources 0.3.0 ParsedRepository#filename.,
774 ppa_inforust-analyzer cargo apt-sources 0.3.0 ParsedRepository#ppa_info.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
775 }))
776 }
777
778 fn default_suite_componentsrust-analyzer cargo apt-sources 0.3.0 default_suite_components().(system_codename: &str) -> (Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>) {
779 // Match original apt-add-repository behavior:
780 // - Suite defaults to system codename
781 // - Components default to 'main'
782 (system_codename.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["main".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()])
783 }
784
785 fn generate_filenamerust-analyzer cargo apt-sources 0.3.0 generate_filename().(url: &str, format: OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#, distribution: &Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
786 let extension = match format {
787 OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::Legacyrust-analyzer cargo apt-sources 0.3.0 OutputFormat#Legacy# => "list",
788 OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::Deb822rust-analyzer cargo apt-sources 0.3.0 OutputFormat#Deb822# => "sources",
789 };
790
791 let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(parsed_url) = Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().(url) else {
792 return get_distribution_specific_filenamerust-analyzer cargo apt-sources 0.3.0 get_distribution_specific_filename().("custom", extension, distribution);
793 };
794
795 // Check if this is a main distribution repository
796 if distribution.is_main_repositoryrust-analyzer cargo apt-sources 0.3.0 distribution/impl#[Distribution]is_main_repository().(&Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository# {
797 urisrust-analyzer cargo apt-sources 0.3.0 Repository#uris.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![parsed_url.clonerust-analyzer cargo url 2.5.8 impl#[Url][Clone]clone().()],
798 ..Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Default]default().()
799 }) {
800 return get_distribution_specific_filenamerust-analyzer cargo apt-sources 0.3.0 get_distribution_specific_filename().("custom", extension, distribution);
801 }
802
803 // Use library function for non-main repos
804 apt_sourcesrust-analyzer cargo apt-sources 0.3.0 crate/::utilsrust-analyzer cargo apt-sources 0.3.0 utils/::generate_filename_from_urlrust-analyzer cargo apt-sources 0.3.0 utils/generate_filename_from_url().(&parsed_url, extension)
805 }
806
807 fn add_pocket_repositoryrust-analyzer cargo apt-sources 0.3.0 add_pocket_repository().(
808 pocket_spec: &str,
809 args: &Argsrust-analyzer cargo apt-sources 0.3.0 Args#,
810 enable_source_count: u8,
811 distribution: &Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#,
812 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
813 inforust-analyzer cargo log 0.4.29 macros/info!!("Adding pocket repository: {}", pocket_spec);
814
815 // Parse the pocket specification (e.g., "focal-proposed" -> suite="focal-proposed", pocket="proposed")
816 let parts: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&str> = pocket_spec.rsplitnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]rsplitn().(2, '-').collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
817 if parts.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().2 {
818 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#("Invalid pocket specification".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
819 }
820
821 let pocket = parts[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().;
822 let _base_suite = parts[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().;
823
824 // Create repository for the pocket
825 let types = if enable_source_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().0 {
826 HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`][`From<[T; N]>`]from().([RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary#, RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Sourcerust-analyzer cargo apt-sources 0.3.0 RepositoryType#Source#])
827 } else {
828 HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`][`From<[T; N]>`]from().([RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary#])
829 };
830
831 // Determine components based on distribution
832 // All pockets (proposed, backports, security, updates) use the same components
833 let components: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = match &distribution {
834 Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#::Ubunturust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#Ubuntu# => vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["main", "universe", "multiverse", "restricted"],
835 Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#::Debianrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#Debian# => vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["main", "contrib", "non-free"],
836 Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#::Otherrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#Other#(_) => distribution.default_componentsrust-analyzer cargo apt-sources 0.3.0 distribution/impl#[Distribution]default_components().(),
837 }
838 .into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().()
839 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|s| s.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
840 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
841
842 // Use distribution-specific mirror URLs
843 let mirror_url = match &distribution {
844 Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#::Ubunturust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#Ubuntu# => "http://archive.ubuntu.com/ubuntu/",
845 Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#::Debianrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#Debian# => "http://deb.debian.org/debian/",
846 Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#::Otherrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#Other#(name) => {
847 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
848 "Pocket repository support not available for distribution '{}'",
849 name
850 ));
851 }
852 };
853
854 let repository = Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository# {
855 enabledrust-analyzer cargo apt-sources 0.3.0 Repository#enabled.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(true),
856 typesrust-analyzer cargo apt-sources 0.3.0 Repository#types.,
857 architecturesrust-analyzer cargo apt-sources 0.3.0 Repository#architectures.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
858 urisrust-analyzer cargo apt-sources 0.3.0 Repository#uris.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().(mirror_url).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()],
859 suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![pocket_spec.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()],
860 componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(components),
861 ..Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Default]default().()
862 };
863
864 let extension = match args.formatrust-analyzer cargo apt-sources 0.3.0 Args#format. {
865 OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::Legacyrust-analyzer cargo apt-sources 0.3.0 OutputFormat#Legacy# => "list",
866 OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::Deb822rust-analyzer cargo apt-sources 0.3.0 OutputFormat#Deb822# => "sources",
867 };
868
869 // Use distribution-specific filename
870 let filename = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
871 "{}-{}.{}",
872 distribution.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().to_lowercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_lowercase().(),
873 pocket,
874 extension
875 );
876 let parsed = ParsedRepositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository# {
877 repositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository#repository.,
878 filenamerust-analyzer cargo apt-sources 0.3.0 ParsedRepository#filename.,
879 ppa_inforust-analyzer cargo apt-sources 0.3.0 ParsedRepository#ppa_info.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
880 };
881
882 add_parsed_repositoryrust-analyzer cargo apt-sources 0.3.0 add_parsed_repository().(parsed, args, distribution)
883 }
884
885 fn add_component_to_existing_reposrust-analyzer cargo apt-sources 0.3.0 add_component_to_existing_repos().(
886 component: &str,
887 directory: &str,
888 dry_run: bool,
889 distribution: &Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#,
890 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
891 inforust-analyzer cargo log 0.4.29 macros/info!!(
892 "Adding component '{}' to existing {} repositories",
893 component, distribution
894 );
895
896 // Find all .sources files that contain distribution repositories
897 let sources_dir = Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(directory);
898 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().sources_dir.existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().() {
899 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Sources directory {} does not exist", directory));
900 }
901
902 let mut modified_count = 0;
903
904 for entry in
905 fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_dir().(sources_dir).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to read directory: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
906 {
907 let entry = entry.map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to read directory entry: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
908 let path = entry.pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]path().();
909
910 if path.extensionrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]extension().().and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|s| s.to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_str().()) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("sources") {
911 continue;
912 }
913
914 // Read and parse the repository file
915 let content = fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_to_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_to_string().(&path)
916 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to read {}: {}", path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().(), e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
917
918 let repos = Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#::from_strrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories][FromStr]from_str().(&content)
919 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to parse {}: {}", path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().(), e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
920
921 let mut modified = false;
922 let mut updated_repos = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
923
924 for repo in repos.iterrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]iter().() {
925 let mut repo_clone = repo.clonerust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Clone]clone().();
926
927 // Check if this is a main distribution repository and doesn't already have the component
928 let dominated = distribution.is_main_repositoryrust-analyzer cargo apt-sources 0.3.0 distribution/impl#[Distribution]is_main_repository().(repo)
929 && repo_clone
930 .componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components.
931 .as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().()
932 .map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().(false, |c| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().c.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&component.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
933
934 if dominated {
935 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(components) = &mut repo_clone.componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components. {
936 if dry_run {
937 inforust-analyzer cargo log 0.4.29 macros/info!!("Would add component '{}' to {}", component, path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().());
938 } else {
939 components.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(component.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
940 inforust-analyzer cargo log 0.4.29 macros/info!!("Adding component '{}' to {}", component, path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().());
941 }
942 modified = true;
943 }
944 }
945
946 updated_repos.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(repo_clone);
947 }
948
949 if modified && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().dry_run {
950 let updated_repositories = Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#::newrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]new().(updated_repos);
951 let output = updated_repositories.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
952 fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/write().(&path, output)
953 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to write {}: {}", path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().(), e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
954 modified_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().1;
955 }
956 }
957
958 if modified_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().0 && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().dry_run {
959 warnrust-analyzer cargo log 0.4.29 macros/warn!!(
960 "No {} repositories found to add component '{}' to",
961 distribution, component
962 );
963 } else if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().dry_run {
964 inforust-analyzer cargo log 0.4.29 macros/info!!("Modified {} repository file(s)", modified_count);
965 }
966
967 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
968 }
969
970 fn enable_sources_globallyrust-analyzer cargo apt-sources 0.3.0 enable_sources_globally().(args: &Argsrust-analyzer cargo apt-sources 0.3.0 Args#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
971 inforust-analyzer cargo log 0.4.29 macros/info!!(
972 "Enabling source repositories globally (level: {})",
973 args.enable_sourcerust-analyzer cargo apt-sources 0.3.0 Args#enable_source.
974 );
975
976 let mut enabled_count = 0;
977 let mut created_count = 0;
978 let mut warned_count = 0;
979 let mut errors = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
980
981 // Scan both .sources and .list files
982 let sources_dir = Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(&args.directoryrust-analyzer cargo apt-sources 0.3.0 Args#directory.);
983 if sources_dir.existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().() {
984 for entry in
985 fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_dir().(sources_dir).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to read directory: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
986 {
987 let entry = entry.map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to read directory entry: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
988 let path = entry.pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]path().();
989
990 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().path.is_filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]is_file().() {
991 continue;
992 }
993
994 // Handle .sources files (DEB822 format)
995 if path.extensionrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]extension().().and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|s| s.to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_str().()) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("sources") {
996 match enable_sources_in_deb822_filerust-analyzer cargo apt-sources 0.3.0 enable_sources_in_deb822_file().(&path, args.enable_sourcerust-analyzer cargo apt-sources 0.3.0 Args#enable_source., args.dry_runrust-analyzer cargo apt-sources 0.3.0 Args#dry_run.) {
997 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((enabled, created)) => {
998 enabled_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().enabled;
999 created_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().created;
1000 }
1001 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
1002 errors.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}: {}", path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().(), e));
1003 }
1004 }
1005 }
1006 // Handle .list files (legacy format)
1007 else if path.extensionrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]extension().().and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|s| s.to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_str().()) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("list") {
1008 match enable_sources_in_legacy_filerust-analyzer cargo apt-sources 0.3.0 enable_sources_in_legacy_file().(&path, args.enable_sourcerust-analyzer cargo apt-sources 0.3.0 Args#enable_source., args.dry_runrust-analyzer cargo apt-sources 0.3.0 Args#dry_run.) {
1009 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((enabled, created, warned)) => {
1010 enabled_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().enabled;
1011 created_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().created;
1012 warned_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().warned;
1013 }
1014 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
1015 errors.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}: {}", path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().(), e));
1016 }
1017 }
1018 }
1019 }
1020 }
1021
1022 // Also handle main sources.list
1023 let main_sources = get_main_sources_list_pathrust-analyzer cargo apt-sources 0.3.0 get_main_sources_list_path().(&args.directoryrust-analyzer cargo apt-sources 0.3.0 Args#directory.);
1024 if main_sources.existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().() {
1025 match enable_sources_in_legacy_filerust-analyzer cargo apt-sources 0.3.0 enable_sources_in_legacy_file().(&main_sources, args.enable_sourcerust-analyzer cargo apt-sources 0.3.0 Args#enable_source., args.dry_runrust-analyzer cargo apt-sources 0.3.0 Args#dry_run.) {
1026 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((enabled, created, warned)) => {
1027 enabled_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().enabled;
1028 created_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().created;
1029 warned_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().warned;
1030 }
1031 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
1032 errors.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("sources.list: {}", e));
1033 }
1034 }
1035 }
1036
1037 // Report results
1038 if args.dry_runrust-analyzer cargo apt-sources 0.3.0 Args#dry_run. {
1039 inforust-analyzer cargo log 0.4.29 macros/info!!("Dry run complete - would have:");
1040 } else {
1041 inforust-analyzer cargo log 0.4.29 macros/info!!("Source enablement complete:");
1042 }
1043
1044 if enabled_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt().0 {
1045 inforust-analyzer cargo log 0.4.29 macros/info!!(" Enabled {} disabled deb-src entries", enabled_count);
1046 }
1047 if created_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt().0 {
1048 inforust-analyzer cargo log 0.4.29 macros/info!!(" Created {} new deb-src entries", created_count);
1049 }
1050 if warned_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt().0 && args.enable_sourcerust-analyzer cargo apt-sources 0.3.0 Args#enable_source. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().1 {
1051 inforust-analyzer cargo log 0.4.29 macros/info!!(
1052 " Found {} missing deb-src entries (use -ss to create them)",
1053 warned_count
1054 );
1055 }
1056
1057 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().errors.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
1058 errorrust-analyzer cargo log 0.4.29 macros/error!!("Errors encountered:");
1059 for err in errors {
1060 errorrust-analyzer cargo log 0.4.29 macros/error!!(" {}", err);
1061 }
1062 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#("Some operations failed".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
1063 }
1064
1065 if enabled_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().0 && created_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().0 && warned_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().0 {
1066 inforust-analyzer cargo log 0.4.29 macros/info!!("No source repositories needed enabling or creation");
1067 }
1068
1069 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
1070 }
1071
1072 fn enable_sources_in_deb822_filerust-analyzer cargo apt-sources 0.3.0 enable_sources_in_deb822_file().(
1073 file_path: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#,
1074 enable_source_count: u8,
1075 dry_run: bool,
1076 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(u32, u32), Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
1077 debugrust-analyzer cargo log 0.4.29 macros/debug!!("Processing DEB822 file: {}", file_path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().());
1078
1079 let content =
1080 fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_to_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_to_string().(file_path).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to read file: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1081
1082 let repos = Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#::from_strrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories][FromStr]from_str().(&content)
1083 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to parse DEB822 file: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1084
1085 let mut enabled_count = 0;
1086 let mut created_count = 0;
1087 let mut modified = false;
1088 let mut updated_repos = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
1089
1090 // First pass: Enable disabled deb-src entries that have matching enabled deb entries
1091 for repo in repos.iterrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]iter().() {
1092 let mut repo_clone = repo.clonerust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Clone]clone().();
1093
1094 // Only process disabled source-only repos with a matching binary repo
1095 let dominated = !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().repo.enabledrust-analyzer cargo apt-sources 0.3.0 Repository#enabled..unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(true)
1096 && repo.typesrust-analyzer cargo apt-sources 0.3.0 Repository#types..containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Sourcerust-analyzer cargo apt-sources 0.3.0 RepositoryType#Source#)
1097 && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().repo.typesrust-analyzer cargo apt-sources 0.3.0 Repository#types..containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary#)
1098 && find_matching_binary_reporust-analyzer cargo apt-sources 0.3.0 find_matching_binary_repo().(&repos, repo).is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().();
1099
1100 if dominated {
1101 if dry_run {
1102 inforust-analyzer cargo log 0.4.29 macros/info!!("Would enable disabled deb-src in {}", file_path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().());
1103 } else {
1104 repo_clone.enabledrust-analyzer cargo apt-sources 0.3.0 Repository#enabled. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(true);
1105 inforust-analyzer cargo log 0.4.29 macros/info!!("Enabled disabled deb-src in {}", file_path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().());
1106 }
1107 enabled_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().1;
1108 modified = true;
1109 }
1110
1111 updated_repos.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(repo_clone);
1112 }
1113
1114 // Second pass: Create missing deb-src entries if enable_source > 1
1115 if enable_source_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().1 {
1116 let mut new_repos = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
1117
1118 for repo in repos.iterrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]iter().() {
1119 // Only process enabled binary-only repos without a matching source repo
1120 let dominated = repo.enabledrust-analyzer cargo apt-sources 0.3.0 Repository#enabled..unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(true)
1121 && repo.typesrust-analyzer cargo apt-sources 0.3.0 Repository#types..containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary#)
1122 && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().repo.typesrust-analyzer cargo apt-sources 0.3.0 Repository#types..containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Sourcerust-analyzer cargo apt-sources 0.3.0 RepositoryType#Source#)
1123 && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().has_matching_source_reporust-analyzer cargo apt-sources 0.3.0 has_matching_source_repo().(&repos, repo);
1124
1125 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().dominated {
1126 continue;
1127 }
1128
1129 // Create a new source repository
1130 let mut source_repo = repo.clonerust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Clone]clone().();
1131 source_repo.typesrust-analyzer cargo apt-sources 0.3.0 Repository#types. = HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`][`From<[T; N]>`]from().([RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Sourcerust-analyzer cargo apt-sources 0.3.0 RepositoryType#Source#]);
1132
1133 if dry_run {
1134 inforust-analyzer cargo log 0.4.29 macros/info!!(
1135 "Would create missing deb-src for binary repo in {}",
1136 file_path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().()
1137 );
1138 } else {
1139 new_repos.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(source_repo);
1140 inforust-analyzer cargo log 0.4.29 macros/info!!(
1141 "Created missing deb-src for binary repo in {}",
1142 file_path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().()
1143 );
1144 }
1145 created_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().1;
1146 modified = true;
1147 }
1148
1149 // Add new repositories to updated list
1150 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().dry_run {
1151 updated_repos.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(new_repos);
1152 }
1153 }
1154
1155 // Write changes if modified and not dry run
1156 if modified && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().dry_run {
1157 let updated_repositories = Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#::newrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]new().(updated_repos);
1158 let output = updated_repositories.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
1159 fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/write().(file_path, output).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to write file: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1160 }
1161
1162 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((enabled_count, created_count))
1163 }
1164
1165 fn enable_sources_in_legacy_filerust-analyzer cargo apt-sources 0.3.0 enable_sources_in_legacy_file().(
1166 file_path: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#,
1167 enable_source_count: u8,
1168 dry_run: bool,
1169 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(u32, u32, u32), Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
1170 debugrust-analyzer cargo log 0.4.29 macros/debug!!("Processing legacy file: {}", file_path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().());
1171
1172 let content =
1173 fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_to_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_to_string().(file_path).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to read file: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1174
1175 let mut lines: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = content.linesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]lines().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|s| s.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1176 let mut enabled_count = 0;
1177 let mut created_count = 0;
1178 let mut warned_count = 0;
1179 let mut modified = false;
1180
1181 // First pass: Enable disabled deb-src lines
1182 for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#lines.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() {
1183 let trimmed = lines[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().();
1184 if trimmed.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("# deb-src ") || trimmed.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("#deb-src ") {
1185 // This is a commented-out deb-src line
1186 let uncommented = trimmed.trim_start_matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim_start_matches().("# ").trim_start_matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim_start_matches().("#");
1187
1188 // Check if there's a matching enabled deb line
1189 let lines_refs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&str> = lines.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|s| s.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1190 if has_matching_deb_linerust-analyzer cargo apt-sources 0.3.0 has_matching_deb_line().(&lines_refs, uncommented) {
1191 if dry_run {
1192 inforust-analyzer cargo log 0.4.29 macros/info!!(
1193 "Would enable disabled deb-src line in {}",
1194 file_path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().()
1195 );
1196 } else {
1197 lines[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). = uncommented.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
1198 inforust-analyzer cargo log 0.4.29 macros/info!!("Enabled disabled deb-src line in {}", file_path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().());
1199 }
1200 enabled_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().1;
1201 modified = true;
1202 }
1203 }
1204 }
1205
1206 // Second pass: Handle missing deb-src entries
1207 let mut new_lines = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
1208 for line in &lines {
1209 let trimmed = line.trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().();
1210 if trimmed.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("deb ") && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().trimmed.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("deb-src ") {
1211 // This is an enabled deb line
1212 let source_line = trimmed.replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().("deb ", "deb-src ");
1213
1214 // Check if there's already a matching deb-src line
1215 let lines_refs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&str> = lines.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|s| s.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1216 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().has_matching_source_linerust-analyzer cargo apt-sources 0.3.0 has_matching_source_line().(&lines_refs, &source_line) {
1217 if enable_source_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().1 {
1218 // Just warn about missing source
1219 debugrust-analyzer cargo log 0.4.29 macros/debug!!("Missing deb-src for: {}", trimmed);
1220 warned_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().1;
1221 } else if enable_source_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().1 {
1222 // Create the missing deb-src line
1223 if dry_run {
1224 inforust-analyzer cargo log 0.4.29 macros/info!!(
1225 "Would create missing deb-src line in {}",
1226 file_path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().()
1227 );
1228 } else {
1229 new_lines.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(source_line);
1230 inforust-analyzer cargo log 0.4.29 macros/info!!("Created missing deb-src line in {}", file_path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().());
1231 }
1232 created_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().1;
1233 modified = true;
1234 }
1235 }
1236 }
1237 }
1238
1239 // Add new lines
1240 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().new_lines.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().dry_run {
1241 lines.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(new_lines);
1242 modified = true;
1243 }
1244
1245 // Write changes if modified and not dry run
1246 if modified && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().dry_run {
1247 let output = lines.joinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]join().("\n") rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().+rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add()."\n";
1248 fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/write().(file_path, output).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to write file: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1249 }
1250
1251 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((enabled_count, created_count, warned_count))
1252 }
1253
1254 fn find_matching_binary_reporust-analyzer cargo apt-sources 0.3.0 find_matching_binary_repo().<'a>(
1255 repos: &'a Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#,
1256 source_repo: &Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#,
1257 ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#> {
1258 for repo in repos.iterrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]iter().() {
1259 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().repo.enabledrust-analyzer cargo apt-sources 0.3.0 Repository#enabled..unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(true) {
1260 continue; // Skip disabled repositories
1261 }
1262
1263 // Check if this is a binary repository with matching URIs, suites, and components
1264 if repo.typesrust-analyzer cargo apt-sources 0.3.0 Repository#types..containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary#)
1265 && repo.urisrust-analyzer cargo apt-sources 0.3.0 Repository#uris. rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Vec<T, A1>`][`PartialEq<Vec<U, A2>>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Vec<T, A1>`][`PartialEq<Vec<U, A2>>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Vec<T, A1>`][`PartialEq<Vec<U, A2>>`]eq().source_repo.urisrust-analyzer cargo apt-sources 0.3.0 Repository#uris.
1266 && repo.suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites. rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Vec<T, A1>`][`PartialEq<Vec<U, A2>>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Vec<T, A1>`][`PartialEq<Vec<U, A2>>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Vec<T, A1>`][`PartialEq<Vec<U, A2>>`]eq().source_repo.suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites.
1267 && repo.componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().source_repo.componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components.
1268 {
1269 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(repo);
1270 }
1271 }
1272 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
1273 }
1274
1275 fn has_matching_source_reporust-analyzer cargo apt-sources 0.3.0 has_matching_source_repo().(repos: &Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#, binary_repo: &Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#) -> bool {
1276 for repo in repos.iterrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]iter().() {
1277 // Check if this is a source repository with matching URIs, suites, and components
1278 if repo.typesrust-analyzer cargo apt-sources 0.3.0 Repository#types..containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Sourcerust-analyzer cargo apt-sources 0.3.0 RepositoryType#Source#)
1279 && repo.urisrust-analyzer cargo apt-sources 0.3.0 Repository#uris. rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Vec<T, A1>`][`PartialEq<Vec<U, A2>>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Vec<T, A1>`][`PartialEq<Vec<U, A2>>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Vec<T, A1>`][`PartialEq<Vec<U, A2>>`]eq().binary_repo.urisrust-analyzer cargo apt-sources 0.3.0 Repository#uris.
1280 && repo.suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites. rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Vec<T, A1>`][`PartialEq<Vec<U, A2>>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Vec<T, A1>`][`PartialEq<Vec<U, A2>>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Vec<T, A1>`][`PartialEq<Vec<U, A2>>`]eq().binary_repo.suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites.
1281 && repo.componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().binary_repo.componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components.
1282 {
1283 return true;
1284 }
1285 }
1286 false
1287 }
1288
1289 fn has_matching_deb_linerust-analyzer cargo apt-sources 0.3.0 has_matching_deb_line().(lines: &[&str], deb_src_line: &str) -> bool {
1290 // Convert deb-src line to equivalent deb line
1291 let deb_line = deb_src_line.replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().("deb-src ", "deb ");
1292
1293 for line in lines {
1294 let trimmed = line.trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().();
1295 if trimmed rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[`&str`][`PartialEq<String>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[`&str`][`PartialEq<String>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[`&str`][`PartialEq<String>`]eq().deb_line {
1296 return true;
1297 }
1298 }
1299 false
1300 }
1301
1302 fn has_matching_source_linerust-analyzer cargo apt-sources 0.3.0 has_matching_source_line().(lines: &[&str], source_line: &str) -> bool {
1303 for line in lines {
1304 let trimmed = line.trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().();
1305 // Check both enabled and disabled source lines
1306 if trimmed rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().source_line
1307 || trimmed rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[`&str`][`PartialEq<String>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[`&str`][`PartialEq<String>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[`&str`][`PartialEq<String>`]eq().formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("# {}", source_line)
1308 || trimmed rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[`&str`][`PartialEq<String>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[`&str`][`PartialEq<String>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[`&str`][`PartialEq<String>`]eq().formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("#{}", source_line)
1309 {
1310 return true;
1311 }
1312 }
1313 false
1314 }
1315
1316 fn add_repositories_from_stdinrust-analyzer cargo apt-sources 0.3.0 add_repositories_from_stdin().(
1317 args: &Argsrust-analyzer cargo apt-sources 0.3.0 Args#,
1318 distribution: &Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#,
1319 codename: &str,
1320 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
1321 inforust-analyzer cargo log 0.4.29 macros/info!!("Reading repository specifications from stdin...");
1322
1323 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{BufReadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead#, BufReaderrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/BufReader#};
1324
1325 let stdin = iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::stdinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stdin().();
1326 let reader = BufReaderrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/BufReader#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/impl#[`BufReader<R>`]new().(stdin);
1327
1328 let mut success_count = 0;
1329 let mut error_count = 0;
1330 let mut errors = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
1331
1332 for (line_num, line_result) in reader.linesrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead#lines().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
1333 let line = match line_result {
1334 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(l) => l,
1335 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
1336 errorrust-analyzer cargo log 0.4.29 macros/error!!("Failed to read line {}: {}", line_num +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). 1, e);
1337 error_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().1;
1338 continue;
1339 }
1340 };
1341
1342 // Skip empty lines and comments
1343 let trimmed = line.trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().();
1344 if trimmed.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() || trimmed.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().('#') {
1345 continue;
1346 }
1347
1348 inforust-analyzer cargo log 0.4.29 macros/info!!("Processing: {}", trimmed);
1349
1350 // Create a temporary args with the repository from stdin
1351 let mut temp_args = args.clonerust-analyzer cargo apt-sources 0.3.0 impl#[Args][Clone]clone().();
1352 temp_args.repositoryrust-analyzer cargo apt-sources 0.3.0 Args#repository. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(trimmed.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
1353
1354 // Process this repository
1355 match add_single_repositoryrust-analyzer cargo apt-sources 0.3.0 add_single_repository().(&temp_args, distribution, codename) {
1356 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) => {
1357 success_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().1;
1358 }
1359 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
1360 error_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().1;
1361 errors.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Line {}: {} - {}", line_num +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). 1, trimmed, e));
1362 }
1363 }
1364 }
1365
1366 // Report results
1367 if error_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().0 {
1368 errorrust-analyzer cargo log 0.4.29 macros/error!!(
1369 "Added {} repositories, {} failed:",
1370 success_count, error_count
1371 );
1372 for err in errors {
1373 errorrust-analyzer cargo log 0.4.29 macros/error!!(" {}", err);
1374 }
1375 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{} repositories failed to add", error_count));
1376 } else if success_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().0 {
1377 warnrust-analyzer cargo log 0.4.29 macros/warn!!("No repositories were added (empty input or all lines were comments)");
1378 } else {
1379 inforust-analyzer cargo log 0.4.29 macros/info!!("Successfully added {} repositories", success_count);
1380 }
1381
1382 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
1383 }
1384
1385 fn add_single_repositoryrust-analyzer cargo apt-sources 0.3.0 add_single_repository().(
1386 args: &Argsrust-analyzer cargo apt-sources 0.3.0 Args#,
1387 distribution: &Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#,
1388 codename: &str,
1389 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
1390 let repository = args
1391 .repositoryrust-analyzer cargo apt-sources 0.3.0 Args#repository.
1392 .as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().()
1393 .ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| "Repository specification required".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1394
1395 debugrust-analyzer cargo log 0.4.29 macros/debug!!("Adding repository: {}", repository);
1396
1397 // Handle -p/--pocket flag
1398 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(pocket) = &args.pocketrust-analyzer cargo apt-sources 0.3.0 Args#pocket. {
1399 let pocket_spec = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}-{}", codename, pocket);
1400 return add_pocket_repositoryrust-analyzer cargo apt-sources 0.3.0 add_pocket_repository().(&pocket_spec, args, args.enable_sourcerust-analyzer cargo apt-sources 0.3.0 Args#enable_source., distribution);
1401 }
1402
1403 let spec = parse_repository_specrust-analyzer cargo apt-sources 0.3.0 parse_repository_spec().(repository, args.enable_sourcerust-analyzer cargo apt-sources 0.3.0 Args#enable_source., args, distribution, codename)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1404
1405 match spec {
1406 RepositorySpecrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#::Componentrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#Component#(component) => {
1407 add_component_to_existing_reposrust-analyzer cargo apt-sources 0.3.0 add_component_to_existing_repos().(&component, &args.directoryrust-analyzer cargo apt-sources 0.3.0 Args#directory., args.dry_runrust-analyzer cargo apt-sources 0.3.0 Args#dry_run., distribution)
1408 }
1409 RepositorySpecrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#::Pocketrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#Pocket#(pocket_spec) => {
1410 add_pocket_repositoryrust-analyzer cargo apt-sources 0.3.0 add_pocket_repository().(&pocket_spec, args, args.enable_sourcerust-analyzer cargo apt-sources 0.3.0 Args#enable_source., distribution)
1411 }
1412 RepositorySpecrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#::Repositoryrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#Repository#(parsed) => add_parsed_repositoryrust-analyzer cargo apt-sources 0.3.0 add_parsed_repository().(parsed, args, distribution),
1413 }
1414 }
1415
1416 fn add_repositoryrust-analyzer cargo apt-sources 0.3.0 add_repository().(args: &Argsrust-analyzer cargo apt-sources 0.3.0 Args#, distribution: &Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#, codename: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
1417 let repository = args
1418 .repositoryrust-analyzer cargo apt-sources 0.3.0 Args#repository.
1419 .as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().()
1420 .ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| "Repository specification required".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1421
1422 // Check if we should read from stdin
1423 if repository rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."-" {
1424 return add_repositories_from_stdinrust-analyzer cargo apt-sources 0.3.0 add_repositories_from_stdin().(args, distribution, codename);
1425 }
1426
1427 // Check if multiple repositories are specified (space-separated)
1428 let repositories: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&str> = repository.split_whitespacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_whitespace().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1429 if repositories.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().1 {
1430 inforust-analyzer cargo log 0.4.29 macros/info!!("Adding {} repositories...", repositories.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().());
1431 return add_multiple_repositoriesrust-analyzer cargo apt-sources 0.3.0 add_multiple_repositories().(&repositories, args, distribution, codename);
1432 }
1433
1434 // Otherwise, add single repository
1435 add_single_repositoryrust-analyzer cargo apt-sources 0.3.0 add_single_repository().(args, distribution, codename)
1436 }
1437
1438 fn add_multiple_repositoriesrust-analyzer cargo apt-sources 0.3.0 add_multiple_repositories().(
1439 repositories: &[&str],
1440 args: &Argsrust-analyzer cargo apt-sources 0.3.0 Args#,
1441 distribution: &Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#,
1442 codename: &str,
1443 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
1444 let mut success_count = 0;
1445 let mut error_count = 0;
1446 let mut errors = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
1447
1448 // Create progress bar
1449 let pb = ProgressBarrust-analyzer cargo indicatif 0.18.4 progress_bar/ProgressBar#::newrust-analyzer cargo indicatif 0.18.4 progress_bar/impl#[ProgressBar]new().(repositories.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() as u64);
1450 pb.set_stylerust-analyzer cargo indicatif 0.18.4 progress_bar/impl#[ProgressBar]set_style().(
1451 ProgressStylerust-analyzer cargo indicatif 0.18.4 style/ProgressStyle#::default_barrust-analyzer cargo indicatif 0.18.4 style/impl#[ProgressStyle]default_bar().()
1452 .templaterust-analyzer cargo indicatif 0.18.4 style/impl#[ProgressStyle]template().("{spinner:.green} [{bar:40.cyan/blue}] {pos}/{len} ({percent}%) {msg}")
1453 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
1454 .progress_charsrust-analyzer cargo indicatif 0.18.4 style/impl#[ProgressStyle]progress_chars().("#>-"),
1455 );
1456 pb.set_messagerust-analyzer cargo indicatif 0.18.4 progress_bar/impl#[ProgressBar]set_message().("Adding repositories...");
1457
1458 for (_index, repo_spec) in repositories.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
1459 pb.set_messagerust-analyzer cargo indicatif 0.18.4 progress_bar/impl#[ProgressBar]set_message().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Processing: {}", repo_spec));
1460
1461 // Create a temporary args with the current repository
1462 let mut temp_args = args.clonerust-analyzer cargo apt-sources 0.3.0 impl#[Args][Clone]clone().();
1463 temp_args.repositoryrust-analyzer cargo apt-sources 0.3.0 Args#repository. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(repo_spec.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
1464
1465 // Add this repository
1466 match add_single_repositoryrust-analyzer cargo apt-sources 0.3.0 add_single_repository().(&temp_args, distribution, codename) {
1467 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) => {
1468 success_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().1;
1469 pb.printlnrust-analyzer cargo indicatif 0.18.4 progress_bar/impl#[ProgressBar]println().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("✓ Successfully added: {}", repo_spec));
1470 }
1471 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
1472 error_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().1;
1473 errors.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Repository '{}': {}", repo_spec, e));
1474 pb.printlnrust-analyzer cargo indicatif 0.18.4 progress_bar/impl#[ProgressBar]println().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("✗ Failed to add '{}': {}", repo_spec, e));
1475 }
1476 }
1477
1478 pb.incrust-analyzer cargo indicatif 0.18.4 progress_bar/impl#[ProgressBar]inc().(1);
1479 }
1480
1481 pb.finish_with_messagerust-analyzer cargo indicatif 0.18.4 progress_bar/impl#[ProgressBar]finish_with_message().("Done");
1482
1483 // Summary
1484 inforust-analyzer cargo log 0.4.29 macros/info!!(
1485 "\nSummary: {} succeeded, {} failed",
1486 success_count, error_count
1487 );
1488
1489 if error_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().0 {
1490 errorrust-analyzer cargo log 0.4.29 macros/error!!("\nThe following repositories failed to add:");
1491 for err in &errors {
1492 errorrust-analyzer cargo log 0.4.29 macros/error!!(" - {}", err);
1493 }
1494 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
1495 "{} out of {} repositories failed to add",
1496 error_count,
1497 repositories.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()
1498 ));
1499 }
1500
1501 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
1502 }
1503
1504 /// Check a DEB822 sources file for duplicate repositories
1505 fn check_deb822_for_duplicaterust-analyzer cargo apt-sources 0.3.0 check_deb822_for_duplicate().(
1506 path: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#,
1507 new_uris: &HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
1508 new_suites: &HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
1509 new_components: &HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
1510 new_types: &HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#>,
1511 ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#)> {
1512 let content = match fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_to_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_to_string().(path) {
1513 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(c) => c,
1514 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
1515 debugrust-analyzer cargo log 0.4.29 macros/debug!!("Failed to read {}: {}", path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().(), e);
1516 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
1517 }
1518 };
1519
1520 let repos = match Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#::from_strrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories][FromStr]from_str().(&content) {
1521 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(r) => r,
1522 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
1523 debugrust-analyzer cargo log 0.4.29 macros/debug!!("Failed to parse {}: {}", path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().(), e);
1524 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
1525 }
1526 };
1527
1528 for repo in repos.iterrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]iter().() {
1529 if is_duplicate_repositoryrust-analyzer cargo apt-sources 0.3.0 is_duplicate_repository().(repo, new_uris, new_suites, new_components, new_types) {
1530 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((
1531 path.to_path_bufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]to_path_buf().(),
1532 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("DEB822 format in {}", path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().()),
1533 ));
1534 }
1535 }
1536 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
1537 }
1538
1539 /// Check a legacy .list file for duplicate repositories
1540 fn check_legacy_for_duplicaterust-analyzer cargo apt-sources 0.3.0 check_legacy_for_duplicate().(
1541 path: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#,
1542 new_uris: &HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
1543 new_suites: &HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
1544 new_components: &HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
1545 new_types: &HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#>,
1546 ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#)> {
1547 let content = match fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_to_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_to_string().(path) {
1548 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(c) => c,
1549 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
1550 debugrust-analyzer cargo log 0.4.29 macros/debug!!("Failed to read {}: {}", path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().(), e);
1551 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
1552 }
1553 };
1554
1555 for (line_num, line) in content.linesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]lines().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
1556 let line = line.trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().();
1557 if line.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() || line.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().('#') {
1558 continue;
1559 }
1560
1561 let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(repos) = line.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<LegacyRepositoriesrust-analyzer cargo apt-sources 0.3.0 legacy/LegacyRepositories#>() else {
1562 continue;
1563 };
1564
1565 for legacy_repo in repos.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() {
1566 let repo = Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#::fromrust-analyzer cargo apt-sources 0.3.0 legacy/impl#[`crate::Repository`][`From<&LegacyRepository>`]from().(legacy_repo);
1567 if is_duplicate_repositoryrust-analyzer cargo apt-sources 0.3.0 is_duplicate_repository().(&repo, new_uris, new_suites, new_components, new_types) {
1568 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((
1569 path.to_path_bufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]to_path_buf().(),
1570 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
1571 "Legacy format in {} at line {}",
1572 path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().(),
1573 line_num +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). 1
1574 ),
1575 ));
1576 }
1577 }
1578 }
1579 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
1580 }
1581
1582 fn find_duplicate_repositoryrust-analyzer cargo apt-sources 0.3.0 find_duplicate_repository().(
1583 new_repo: &Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#,
1584 sources_dir: &str,
1585 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#)>, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
1586 debugrust-analyzer cargo log 0.4.29 macros/debug!!("Checking for duplicate repositories");
1587
1588 // Normalize the new repository for comparison
1589 let new_uris: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = new_repo.urisrust-analyzer cargo apt-sources 0.3.0 Repository#uris..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|u| u.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1590 let new_suites: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = new_repo.suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1591 let new_components: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = new_repo
1592 .componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components.
1593 .as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().()
1594 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|c| c.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().())
1595 .unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_default().();
1596 let new_types: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#> = new_repo.typesrust-analyzer cargo apt-sources 0.3.0 Repository#types..clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`][Clone]clone().();
1597
1598 // Scan sources.list.d directory
1599 let sources_path = Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(sources_dir);
1600 if sources_path.existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().() {
1601 for entry in
1602 fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_dir().(sources_path).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to read directory: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
1603 {
1604 let entry = entry.map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to read directory entry: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1605 let path = entry.pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]path().();
1606
1607 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().path.is_filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]is_file().() {
1608 continue;
1609 }
1610
1611 let ext = path.extensionrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]extension().().and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|s| s.to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_str().());
1612 let result = match ext {
1613 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("sources") => check_deb822_for_duplicaterust-analyzer cargo apt-sources 0.3.0 check_deb822_for_duplicate().(
1614 &path,
1615 &new_uris,
1616 &new_suites,
1617 &new_components,
1618 &new_types,
1619 ),
1620 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("list") => check_legacy_for_duplicaterust-analyzer cargo apt-sources 0.3.0 check_legacy_for_duplicate().(
1621 &path,
1622 &new_uris,
1623 &new_suites,
1624 &new_components,
1625 &new_types,
1626 ),
1627 _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
1628 };
1629
1630 if result.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
1631 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(result);
1632 }
1633 }
1634 }
1635
1636 // Also check main sources.list
1637 let main_sources = get_main_sources_list_pathrust-analyzer cargo apt-sources 0.3.0 get_main_sources_list_path().(sources_dir);
1638 if main_sources.existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().() {
1639 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(result) = check_legacy_for_duplicaterust-analyzer cargo apt-sources 0.3.0 check_legacy_for_duplicate().(
1640 &main_sources,
1641 &new_uris,
1642 &new_suites,
1643 &new_components,
1644 &new_types,
1645 ) {
1646 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(result));
1647 }
1648 }
1649
1650 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)
1651 }
1652
1653 fn is_duplicate_repositoryrust-analyzer cargo apt-sources 0.3.0 is_duplicate_repository().(
1654 existing: &Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#,
1655 new_uris: &HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
1656 new_suites: &HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
1657 new_components: &HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
1658 new_types: &HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#>,
1659 ) -> bool {
1660 // Check if disabled
1661 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().existing.enabledrust-analyzer cargo apt-sources 0.3.0 Repository#enabled..unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(true) {
1662 return false;
1663 }
1664
1665 // Compare URIs (must have at least one matching URI)
1666 let existing_uris: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = existing.urisrust-analyzer cargo apt-sources 0.3.0 Repository#uris..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|u| u.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1667 if existing_uris.is_disjointrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]is_disjoint().(new_uris) {
1668 return false;
1669 }
1670
1671 // Compare suites (must have at least one matching suite)
1672 let existing_suites: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = existing.suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1673 if existing_suites.is_disjointrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]is_disjoint().(new_suites) {
1674 return false;
1675 }
1676
1677 // Compare components (must have overlapping components)
1678 let existing_components: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = existing
1679 .componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components.
1680 .as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().()
1681 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|c| c.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().())
1682 .unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_default().();
1683 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().existing_components.is_emptyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]is_empty().()
1684 && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().new_components.is_emptyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]is_empty().()
1685 && existing_components.is_disjointrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]is_disjoint().(new_components)
1686 {
1687 return false;
1688 }
1689
1690 // Compare types (must have at least one matching type)
1691 let existing_types: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#> = existing.typesrust-analyzer cargo apt-sources 0.3.0 Repository#types..clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`][Clone]clone().();
1692 !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().existing_types.is_disjointrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]is_disjoint().(new_types)
1693 }
1694
1695 fn add_parsed_repositoryrust-analyzer cargo apt-sources 0.3.0 add_parsed_repository().(
1696 mut parsed: ParsedRepositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository#,
1697 args: &Argsrust-analyzer cargo apt-sources 0.3.0 Args#,
1698 distribution: &Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#,
1699 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
1700 // Check for duplicate repository before proceeding
1701 debugrust-analyzer cargo log 0.4.29 macros/debug!!("Checking for duplicate repository");
1702 match find_duplicate_repositoryrust-analyzer cargo apt-sources 0.3.0 find_duplicate_repository().(&parsed.repositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository#repository., &args.directoryrust-analyzer cargo apt-sources 0.3.0 Args#directory.) {
1703 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((_file_path, location))) => {
1704 if args.assume_yesrust-analyzer cargo apt-sources 0.3.0 Args#assume_yes. {
1705 warnrust-analyzer cargo log 0.4.29 macros/warn!!("Repository already exists in {}", location);
1706 warnrust-analyzer cargo log 0.4.29 macros/warn!!("Skipping duplicate repository");
1707 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(());
1708 } else {
1709 eprintrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprint!!(
1710 "Repository already exists in {}.\nAdd it anyway? [y/N] ",
1711 location
1712 );
1713 iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stdout().().flushrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/impl#[Stdout][Write]flush().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1714 let mut input = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().();
1715 iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::stdinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stdin().().read_linerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/impl#[Stdin]read_line().(&mut input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1716 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().input.trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().().eq_ignore_ascii_caserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]eq_ignore_ascii_case().("y") {
1717 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#("Repository already exists, not adding duplicate".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
1718 }
1719 inforust-analyzer cargo log 0.4.29 macros/info!!("Adding duplicate repository as requested");
1720 }
1721 }
1722 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) => {
1723 debugrust-analyzer cargo log 0.4.29 macros/debug!!("No duplicate repository found");
1724 }
1725 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
1726 warnrust-analyzer cargo log 0.4.29 macros/warn!!("Error checking for duplicates: {}", e);
1727 // Continue anyway - better to add a potential duplicate than fail
1728 }
1729 }
1730
1731 // Handle PPA key download
1732 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref ppa_info) = parsed.ppa_inforust-analyzer cargo apt-sources 0.3.0 ParsedRepository#ppa_info. {
1733 // Validate PPA first
1734 inforust-analyzer cargo log 0.4.29 macros/info!!("Checking PPA availability...");
1735
1736 #[cfg(feature = "launchpad")]
1737 let validation_result = if args.loginrust-analyzer cargo apt-sources 0.3.0 Args#login. || args.keyserverrust-analyzer cargo apt-sources 0.3.0 Args#keyserver..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() {
1738 validate_ppa_launchpadlibrust-analyzer cargo apt-sources 0.3.0 validate_ppa_launchpadlib().(ppa_info, args.loginrust-analyzer cargo apt-sources 0.3.0 Args#login.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
1739 } else {
1740 validate_ppa_with_suggestionsrust-analyzer cargo apt-sources 0.3.0 validate_ppa_with_suggestions().(ppa_info)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
1741 };
1742
1743 #[cfg(not(feature = "launchpad"))]
1744 let validation_result = validate_ppa_with_suggestionsrust-analyzer cargo apt-sources 0.3.0 validate_ppa_with_suggestions().(ppa_info)?;
1745
1746 // Inform about debug symbols if available
1747 if validation_result.publishes_debug_symbolsrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaValidationResult#publishes_debug_symbols. {
1748 inforust-analyzer cargo log 0.4.29 macros/info!!("This PPA publishes debug symbols. To enable debug symbols, add the component 'main/debug'.");
1749 }
1750
1751 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().args.assume_yesrust-analyzer cargo apt-sources 0.3.0 Args#assume_yes. && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().args.dry_runrust-analyzer cargo apt-sources 0.3.0 Args#dry_run. {
1752 eprintrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprint!!(
1753 "You are about to add the following PPA:
1754 {}
1755 More info: https://launchpad.net/~{}/+archive/ubuntu/{}
1756 Press [ENTER] to continue or Ctrl-c to cancel.",
1757 validation_result.display_namerust-analyzer cargo apt-sources 0.3.0 launchpad/PpaValidationResult#display_name., ppa_info.userrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#user., ppa_info.namerust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#name.
1758 );
1759 iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stdout().().flushrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/impl#[Stdout][Write]flush().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1760 let mut input = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().();
1761 iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::stdinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stdin().().read_linerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/impl#[Stdin]read_line().(&mut input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1762 }
1763
1764 // Download and save the PPA signing key
1765 if args.dry_runrust-analyzer cargo apt-sources 0.3.0 Args#dry_run. {
1766 inforust-analyzer cargo log 0.4.29 macros/info!!("Would download and verify PPA signing key");
1767 let keyring_path = Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(&args.keyring_dirrust-analyzer cargo apt-sources 0.3.0 Args#keyring_dir.).joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(ppa_info.keyring_filenamerust-analyzer cargo apt-sources 0.3.0 launchpad/impl#[PpaInfo]keyring_filename().());
1768 inforust-analyzer cargo log 0.4.29 macros/info!!("Would save signing key to {}", keyring_path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().());
1769 parsed.repositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository#repository..signaturerust-analyzer cargo apt-sources 0.3.0 Repository#signature. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Signaturerust-analyzer cargo apt-sources 0.3.0 signature/Signature#::KeyPathrust-analyzer cargo apt-sources 0.3.0 signature/Signature#KeyPath#(keyring_path));
1770 } else {
1771 inforust-analyzer cargo log 0.4.29 macros/info!!("Getting signing key for PPA...");
1772
1773 // Use launchpadlib if available and needed
1774 #[cfg(feature = "launchpad")]
1775 let key_result = if args.loginrust-analyzer cargo apt-sources 0.3.0 Args#login. || args.keyserverrust-analyzer cargo apt-sources 0.3.0 Args#keyserver..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() {
1776 download_ppa_key_launchpadlibrust-analyzer cargo apt-sources 0.3.0 download_ppa_key_launchpadlib().(ppa_info, args.loginrust-analyzer cargo apt-sources 0.3.0 Args#login.)
1777 } else {
1778 download_ppa_keyrust-analyzer cargo apt-sources 0.3.0 download_ppa_key().(ppa_info, args.keyserverrust-analyzer cargo apt-sources 0.3.0 Args#keyserver..as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().())
1779 };
1780
1781 #[cfg(not(feature = "launchpad"))]
1782 let key_result = download_ppa_keyrust-analyzer cargo apt-sources 0.3.0 download_ppa_key().(ppa_info, args.keyserver.as_deref());
1783
1784 match key_result {
1785 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(key_data) => {
1786 let use_inline = args.inline_keyrust-analyzer cargo apt-sources 0.3.0 Args#inline_key. && args.formatrust-analyzer cargo apt-sources 0.3.0 Args#format. rust-analyzer cargo apt-sources 0.3.0 impl#[OutputFormat][`PartialEq<Self>`]eq().==rust-analyzer cargo apt-sources 0.3.0 impl#[OutputFormat][`PartialEq<Self>`]eq(). rust-analyzer cargo apt-sources 0.3.0 impl#[OutputFormat][`PartialEq<Self>`]eq().OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::Deb822rust-analyzer cargo apt-sources 0.3.0 OutputFormat#Deb822#;
1787 parsed.repositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository#repository..signaturerust-analyzer cargo apt-sources 0.3.0 Repository#signature. =
1788 save_ppa_keyrust-analyzer cargo apt-sources 0.3.0 save_ppa_key().(&key_data, ppa_info, &args.keyring_dirrust-analyzer cargo apt-sources 0.3.0 Args#keyring_dir., use_inline);
1789 }
1790 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
1791 warnrust-analyzer cargo log 0.4.29 macros/warn!!("Failed to download PPA signing key: {}", e);
1792 warnrust-analyzer cargo log 0.4.29 macros/warn!!("The repository will be added without signature verification.");
1793 }
1794 }
1795 }
1796 }
1797
1798 // Determine the appropriate file path
1799 let filepath = determine_repository_filepathrust-analyzer cargo apt-sources 0.3.0 determine_repository_filepath().(&parsed, args, distribution)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1800
1801 // Check if directory exists
1802 let parent_dir = filepath
1803 .parentrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]parent().()
1804 .ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| "Invalid file path".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1805 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().parent_dir.existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().() {
1806 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
1807 "Directory {} does not exist.\n\
1808 Suggestions:\n\
1809 - Create the directory with: sudo mkdir -p {}\n\
1810 - Check if you have the correct permissions\n\
1811 - Verify the path is correct",
1812 parent_dir.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().(),
1813 parent_dir.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().()
1814 ));
1815 }
1816
1817 // Check if file already exists
1818 let file_exists = filepath.existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().();
1819 let is_main_file = is_main_distribution_filerust-analyzer cargo apt-sources 0.3.0 is_main_distribution_file().(&filepath);
1820
1821 if file_exists && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_main_file && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().args.assume_yesrust-analyzer cargo apt-sources 0.3.0 Args#assume_yes. {
1822 eprintrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprint!!(
1823 "Repository file {} already exists. Overwrite? [y/N] ",
1824 filepath.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().()
1825 );
1826 iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stdout().().flushrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/impl#[Stdout][Write]flush().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1827 let mut input = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().();
1828 iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::stdinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stdin().().read_linerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/impl#[Stdin]read_line().(&mut input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1829 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().input.trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().().eq_ignore_ascii_caserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]eq_ignore_ascii_case().("y") {
1830 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#("Aborted".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
1831 }
1832 }
1833
1834 // Create content based on format
1835 let content = match args.formatrust-analyzer cargo apt-sources 0.3.0 Args#format. {
1836 OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::Legacyrust-analyzer cargo apt-sources 0.3.0 OutputFormat#Legacy# => {
1837 // Generate legacy .list format
1838 LegacyRepositoriesrust-analyzer cargo apt-sources 0.3.0 legacy/LegacyRepositories#::fromrust-analyzer cargo apt-sources 0.3.0 legacy/impl#[LegacyRepositories][`From<&crate::Repository>`]from().(&parsed.repositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository#repository.).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
1839 }
1840 OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::Deb822rust-analyzer cargo apt-sources 0.3.0 OutputFormat#Deb822# => {
1841 // Create Repositories container and serialize to DEB822 format
1842 let repos = Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#::newrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]new().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![parsed.repositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository#repository..clonerust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Clone]clone().()]);
1843 repos.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
1844 }
1845 };
1846
1847 if args.dry_runrust-analyzer cargo apt-sources 0.3.0 Args#dry_run. {
1848 // Show what would be written
1849 if file_exists && is_main_file {
1850 inforust-analyzer cargo log 0.4.29 macros/info!!(
1851 "Would append repository to existing file {}",
1852 filepath.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().()
1853 );
1854 } else {
1855 inforust-analyzer cargo log 0.4.29 macros/info!!("Would write repository to {}", filepath.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().());
1856 }
1857 inforust-analyzer cargo log 0.4.29 macros/info!!("Repository content that would be written:");
1858 for line in content.linesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]lines().() {
1859 inforust-analyzer cargo log 0.4.29 macros/info!!(" {}", line);
1860 }
1861
1862 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().args.no_updaterust-analyzer cargo apt-sources 0.3.0 Args#no_update. {
1863 inforust-analyzer cargo log 0.4.29 macros/info!!("Would run: apt update");
1864 }
1865 } else {
1866 // Write to file - append if it's a main distribution file, otherwise overwrite
1867 if file_exists && is_main_file {
1868 // For main distribution files, append the repository
1869 match args.formatrust-analyzer cargo apt-sources 0.3.0 Args#format. {
1870 OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::Legacyrust-analyzer cargo apt-sources 0.3.0 OutputFormat#Legacy# => {
1871 // For legacy format, just append the lines
1872 let mut file = fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::OpenOptionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/OpenOptions#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]new().()
1873 .appendrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]append().(true)
1874 .openrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]open().(&filepath)
1875 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to open file for appending: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1876
1877 // Add a newline if the file doesn't end with one
1878 let existing_content = fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_to_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_to_string().(&filepath)
1879 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to read existing file: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1880 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().existing_content.ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().('\n') {
1881 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#;
1882 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(file).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to write newline: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1883 }
1884
1885 // Write the new content
1886 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(file, "{}", content)
1887 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to append to file: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1888 }
1889 OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::Deb822rust-analyzer cargo apt-sources 0.3.0 OutputFormat#Deb822# => {
1890 // For DEB822 format, we need to merge repositories
1891 let existing_content = fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_to_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_to_string().(&filepath)
1892 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to read existing file: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1893
1894 let repos = Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#::from_strrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories][FromStr]from_str().(&existing_content)
1895 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to parse existing repositories: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1896
1897 // Create a new vector with existing repos plus the new one
1898 let mut all_repos: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#> = repos.iterrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1899 all_repos.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(parsed.repositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository#repository..clonerust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Clone]clone().());
1900
1901 // Write the merged content
1902 let merged_repos = Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#::newrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]new().(all_repos);
1903 fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/write().(&filepath, merged_repos.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
1904 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to write merged repositories: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1905 }
1906 }
1907 inforust-analyzer cargo log 0.4.29 macros/info!!("Repository appended to {}", filepath.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().());
1908 } else {
1909 // For non-main files, just write/overwrite
1910 fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/write().(&filepath, &content).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to write file: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1911 inforust-analyzer cargo log 0.4.29 macros/info!!("Repository added to {}", filepath.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().());
1912 }
1913
1914 // Update package cache unless disabled
1915 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().args.no_updaterust-analyzer cargo apt-sources 0.3.0 Args#no_update. {
1916 let spinner = ProgressBarrust-analyzer cargo indicatif 0.18.4 progress_bar/ProgressBar#::new_spinnerrust-analyzer cargo indicatif 0.18.4 progress_bar/impl#[ProgressBar]new_spinner().();
1917 spinner.set_stylerust-analyzer cargo indicatif 0.18.4 progress_bar/impl#[ProgressBar]set_style().(
1918 ProgressStylerust-analyzer cargo indicatif 0.18.4 style/ProgressStyle#::default_spinnerrust-analyzer cargo indicatif 0.18.4 style/impl#[ProgressStyle]default_spinner().()
1919 .templaterust-analyzer cargo indicatif 0.18.4 style/impl#[ProgressStyle]template().("{spinner:.green} {msg}")
1920 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
1921 );
1922 spinner.set_messagerust-analyzer cargo indicatif 0.18.4 progress_bar/impl#[ProgressBar]set_message().("Updating package cache...");
1923 spinner.enable_steady_tickrust-analyzer cargo indicatif 0.18.4 progress_bar/impl#[ProgressBar]enable_steady_tick().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_millisrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_millis().(100));
1924
1925 let status = processrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/::Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]new().("apt")
1926 .argrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]arg().("update")
1927 .statusrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]status().()
1928 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| {
1929 spinner.finish_and_clearrust-analyzer cargo indicatif 0.18.4 progress_bar/impl#[ProgressBar]finish_and_clear().();
1930 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to run apt update: {}", e)
1931 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1932
1933 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().status.successrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[ExitStatus]success().() {
1934 spinner.finish_with_messagerust-analyzer cargo indicatif 0.18.4 progress_bar/impl#[ProgressBar]finish_with_message().("apt update failed");
1935 warnrust-analyzer cargo log 0.4.29 macros/warn!!("apt update failed");
1936 } else {
1937 spinner.finish_with_messagerust-analyzer cargo indicatif 0.18.4 progress_bar/impl#[ProgressBar]finish_with_message().("Package cache updated successfully");
1938 }
1939 }
1940 }
1941
1942 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
1943 }
1944
1945 /// Warn about key expiration if applicable
1946 fn warn_key_expirationrust-analyzer cargo apt-sources 0.3.0 warn_key_expiration().(key_data: &str, ppa_info: &PpaInforust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#) {
1947 let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(cert) = Certrust-analyzer cargo sequoia-openpgp 2.3.0 cert/Cert#::from_strrust-analyzer cargo sequoia-openpgp 2.3.0 cert/impl#[Cert][FromStr]from_str().(key_data) else {
1948 return;
1949 };
1950 let policy = sequoia_openpgprust-analyzer cargo sequoia-openpgp 2.3.0 crate/::policyrust-analyzer cargo sequoia-openpgp 2.3.0 policy/::StandardPolicyrust-analyzer cargo sequoia-openpgp 2.3.0 policy/StandardPolicy#::newrust-analyzer cargo sequoia-openpgp 2.3.0 policy/impl#[`StandardPolicy<'a>`]new().();
1951 let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(valid_cert) = cert.with_policyrust-analyzer cargo sequoia-openpgp 2.3.0 cert/impl#[Cert]with_policy().(&policy, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) else {
1952 return;
1953 };
1954 let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(expiration) = valid_cert.primary_keyrust-analyzer cargo sequoia-openpgp 2.3.0 cert/impl#[`ValidCert<'a>`]primary_key().().key_expiration_timerust-analyzer cargo sequoia-openpgp 2.3.0 cert/amalgamation/key/impl#[`ValidKeyAmalgamation<'a, P, R, R2>`]key_expiration_time().() else {
1955 return;
1956 };
1957
1958 let now = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::SystemTimerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/SystemTime#::nowrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[SystemTime]now().();
1959 if expiration rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#lt().now {
1960 warnrust-analyzer cargo log 0.4.29 macros/warn!!("Key for {}/{} has expired!", ppa_info.userrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#user., ppa_info.namerust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#name.);
1961 } else if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(duration) = expiration.duration_sincerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[SystemTime]duration_since().(now) {
1962 let days = duration.as_secsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]as_secs().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div().86400;
1963 if days rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]lt().30 {
1964 warnrust-analyzer cargo log 0.4.29 macros/warn!!(
1965 "Key for {}/{} expires in {} days",
1966 ppa_info.userrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#user., ppa_info.namerust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#name., days
1967 );
1968 }
1969 }
1970 }
1971
1972 /// Collect PPAs from DEB822 sources file
1973 fn collect_ppas_from_deb822rust-analyzer cargo apt-sources 0.3.0 collect_ppas_from_deb822().(
1974 path: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#,
1975 ppa_repos: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#, PpaInforust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Signaturerust-analyzer cargo apt-sources 0.3.0 signature/Signature#>)>,
1976 ) {
1977 let content = match fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_to_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_to_string().(path) {
1978 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(c) => c,
1979 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
1980 warnrust-analyzer cargo log 0.4.29 macros/warn!!("Failed to read {}: {}", path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().(), e);
1981 return;
1982 }
1983 };
1984
1985 let repos = match Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#::from_strrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories][FromStr]from_str().(&content) {
1986 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(r) => r,
1987 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
1988 warnrust-analyzer cargo log 0.4.29 macros/warn!!("Failed to parse {}: {}", path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().(), e);
1989 return;
1990 }
1991 };
1992
1993 for repo in repos.iterrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]iter().() {
1994 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ppa_info) = PpaInforust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#::from_repositoryrust-analyzer cargo apt-sources 0.3.0 launchpad/impl#[PpaInfo]from_repository().(repo) {
1995 ppa_repos.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().((path.to_path_bufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]to_path_buf().(), ppa_info, repo.signaturerust-analyzer cargo apt-sources 0.3.0 Repository#signature..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Clone]clone().()));
1996 }
1997 }
1998 }
1999
2000 /// Collect PPAs from legacy .list file
2001 fn collect_ppas_from_legacyrust-analyzer cargo apt-sources 0.3.0 collect_ppas_from_legacy().(
2002 path: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#,
2003 keyring_dir: &str,
2004 ppa_repos: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#, PpaInforust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Signaturerust-analyzer cargo apt-sources 0.3.0 signature/Signature#>)>,
2005 ) {
2006 let content = match fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_to_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_to_string().(path) {
2007 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(c) => c,
2008 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
2009 warnrust-analyzer cargo log 0.4.29 macros/warn!!("Failed to read {}: {}", path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().(), e);
2010 return;
2011 }
2012 };
2013
2014 for line in content.linesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]lines().() {
2015 let line = line.trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().();
2016 if line.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() || line.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().('#') {
2017 continue;
2018 }
2019
2020 let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(repos) = line.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<LegacyRepositoriesrust-analyzer cargo apt-sources 0.3.0 legacy/LegacyRepositories#>() else {
2021 continue;
2022 };
2023
2024 for legacy_repo in repos.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() {
2025 let repo = Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#::fromrust-analyzer cargo apt-sources 0.3.0 legacy/impl#[`crate::Repository`][`From<&LegacyRepository>`]from().(legacy_repo);
2026 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ppa_info) = PpaInforust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#::from_repositoryrust-analyzer cargo apt-sources 0.3.0 launchpad/impl#[PpaInfo]from_repository().(&repo) {
2027 let keyring_path = Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(keyring_dir).joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(ppa_info.keyring_filenamerust-analyzer cargo apt-sources 0.3.0 launchpad/impl#[PpaInfo]keyring_filename().());
2028 let signature = if keyring_path.existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().() {
2029 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Signaturerust-analyzer cargo apt-sources 0.3.0 signature/Signature#::KeyPathrust-analyzer cargo apt-sources 0.3.0 signature/Signature#KeyPath#(keyring_path))
2030 } else {
2031 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
2032 };
2033 ppa_repos.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().((path.to_path_bufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]to_path_buf().(), ppa_info, signature));
2034 break; // Only one PPA per line
2035 }
2036 }
2037 }
2038 }
2039
2040 fn refresh_ppa_keysrust-analyzer cargo apt-sources 0.3.0 refresh_ppa_keys().(args: &Argsrust-analyzer cargo apt-sources 0.3.0 Args#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
2041 inforust-analyzer cargo log 0.4.29 macros/info!!("Refreshing signing keys for all PPAs...");
2042
2043 let mut ppa_repos = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
2044
2045 // Scan sources.list.d directory for PPAs
2046 let sources_dir = Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(&args.directoryrust-analyzer cargo apt-sources 0.3.0 Args#directory.);
2047 if sources_dir.existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().() {
2048 for entry in
2049 fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_dir().(sources_dir).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to read directory: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
2050 {
2051 let entry = entry.map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to read directory entry: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
2052 let path = entry.pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]path().();
2053
2054 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().path.is_filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]is_file().() {
2055 continue;
2056 }
2057
2058 match path.extensionrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]extension().().and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|s| s.to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_str().()) {
2059 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("sources") => collect_ppas_from_deb822rust-analyzer cargo apt-sources 0.3.0 collect_ppas_from_deb822().(&path, &mut ppa_repos),
2060 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("list") => collect_ppas_from_legacyrust-analyzer cargo apt-sources 0.3.0 collect_ppas_from_legacy().(&path, &args.keyring_dirrust-analyzer cargo apt-sources 0.3.0 Args#keyring_dir., &mut ppa_repos),
2061 _ => {}
2062 }
2063 }
2064 }
2065
2066 if ppa_repos.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
2067 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("No PPAs found to refresh keys for.");
2068 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(());
2069 }
2070
2071 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Found {} PPA(s) to refresh keys for", ppa_repos.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().());
2072
2073 let mut updated_count = 0;
2074 let mut failed_count = 0;
2075 let mut errors = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
2076
2077 for (_source_file, ppa_info, _existing_signature) in &ppa_repos {
2078 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(
2079 "\nRefreshing key for PPA: {}/{}",
2080 ppa_info.userrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#user., ppa_info.namerust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#name.
2081 );
2082
2083 // Download the new key
2084 #[cfg(feature = "launchpad")]
2085 let key_result = if args.keyserverrust-analyzer cargo apt-sources 0.3.0 Args#keyserver..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() {
2086 download_ppa_key_launchpadlibrust-analyzer cargo apt-sources 0.3.0 download_ppa_key_launchpadlib().(ppa_info, false)
2087 } else {
2088 download_ppa_keyrust-analyzer cargo apt-sources 0.3.0 download_ppa_key().(ppa_info, args.keyserverrust-analyzer cargo apt-sources 0.3.0 Args#keyserver..as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().())
2089 };
2090
2091 #[cfg(not(feature = "launchpad"))]
2092 let key_result = download_ppa_keyrust-analyzer cargo apt-sources 0.3.0 download_ppa_key().(ppa_info, args.keyserver.as_deref());
2093
2094 let key_data = match key_result {
2095 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(data) => data,
2096 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
2097 failed_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
2098 errors.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}/{}: {}", ppa_info.userrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#user., ppa_info.namerust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#name., e));
2099 continue;
2100 }
2101 };
2102
2103 // Check if we have an existing keyring file
2104 let keyring_path = Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(&args.keyring_dirrust-analyzer cargo apt-sources 0.3.0 Args#keyring_dir.).joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(ppa_info.keyring_filenamerust-analyzer cargo apt-sources 0.3.0 launchpad/impl#[PpaInfo]keyring_filename().());
2105
2106 // Check if the key has changed
2107 let key_changed = match fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_to_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_to_string().(&keyring_path) {
2108 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(existing_key) => existing_key rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().key_data,
2109 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => true,
2110 };
2111
2112 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().key_changed {
2113 debugrust-analyzer cargo log 0.4.29 macros/debug!!("Key for {}/{} is up to date", ppa_info.userrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#user., ppa_info.namerust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#name.);
2114 continue;
2115 }
2116
2117 if args.dry_runrust-analyzer cargo apt-sources 0.3.0 Args#dry_run. {
2118 inforust-analyzer cargo log 0.4.29 macros/info!!(
2119 "Would update signing key for {}/{}",
2120 ppa_info.userrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#user., ppa_info.namerust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#name.
2121 );
2122 updated_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
2123 warn_key_expirationrust-analyzer cargo apt-sources 0.3.0 warn_key_expiration().(&key_data, ppa_info);
2124 continue;
2125 }
2126
2127 // Save the new key
2128 match save_key_to_keyringrust-analyzer cargo apt-sources 0.3.0 save_key_to_keyring().(&key_data, &args.keyring_dirrust-analyzer cargo apt-sources 0.3.0 Args#keyring_dir., ppa_info) {
2129 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(new_keyring_path) => {
2130 inforust-analyzer cargo log 0.4.29 macros/info!!(
2131 "Updated signing key saved to {}",
2132 new_keyring_path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().()
2133 );
2134 updated_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
2135 warn_key_expirationrust-analyzer cargo apt-sources 0.3.0 warn_key_expiration().(&key_data, ppa_info);
2136 }
2137 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
2138 failed_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
2139 errors.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
2140 "{}/{}: Failed to save key - {}",
2141 ppa_info.userrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#user., ppa_info.namerust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#name., e
2142 ));
2143 }
2144 }
2145 }
2146
2147 // Report results
2148 if args.dry_runrust-analyzer cargo apt-sources 0.3.0 Args#dry_run. {
2149 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("\nDry run - Key refresh summary:");
2150 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(" Would update: {}", updated_count);
2151 } else {
2152 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("\nKey refresh complete:");
2153 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(" Updated: {}", updated_count);
2154 }
2155 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(
2156 " Up to date: {}",
2157 ppa_repos.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). updated_count -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). failed_count
2158 );
2159 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(
2160 " {}: {}",
2161 if args.dry_runrust-analyzer cargo apt-sources 0.3.0 Args#dry_run. {
2162 "Failed to check"
2163 } else {
2164 "Failed"
2165 },
2166 failed_count
2167 );
2168
2169 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().errors.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
2170 errorrust-analyzer cargo log 0.4.29 macros/error!!("\nErrors encountered:");
2171 for err in errors {
2172 errorrust-analyzer cargo log 0.4.29 macros/error!!(" {}", err);
2173 }
2174 }
2175
2176 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
2177 }
2178
2179 /// Collect repositories from a legacy sources.list file
2180 fn collect_repos_from_sources_listrust-analyzer cargo apt-sources 0.3.0 collect_repos_from_sources_list().(
2181 path: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#,
2182 all_repos: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#, RepoFormatrust-analyzer cargo apt-sources 0.3.0 RepoFormat#, Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#)>,
2183 ) {
2184 let content = match fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_to_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_to_string().(path) {
2185 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(c) => c,
2186 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
2187 warnrust-analyzer cargo log 0.4.29 macros/warn!!("Failed to read {}: {}", path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().(), e);
2188 return;
2189 }
2190 };
2191
2192 for (line_num, line) in content.linesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]lines().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
2193 let line = line.trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().();
2194 if line.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() || line.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().('#') {
2195 continue;
2196 }
2197
2198 let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(repos) = line.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<LegacyRepositoriesrust-analyzer cargo apt-sources 0.3.0 legacy/LegacyRepositories#>() else {
2199 debugrust-analyzer cargo log 0.4.29 macros/debug!!(
2200 "Failed to parse line {} in {}",
2201 line_num +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). 1,
2202 path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().()
2203 );
2204 continue;
2205 };
2206
2207 for legacy_repo in repos.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() {
2208 all_repos.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().((
2209 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("sources.list:{}", line_num +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). 1),
2210 path.to_path_bufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]to_path_buf().(),
2211 RepoFormatrust-analyzer cargo apt-sources 0.3.0 RepoFormat#::Legacyrust-analyzer cargo apt-sources 0.3.0 RepoFormat#Legacy#,
2212 Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#::fromrust-analyzer cargo apt-sources 0.3.0 legacy/impl#[`crate::Repository`][`From<&LegacyRepository>`]from().(legacy_repo),
2213 ));
2214 }
2215 }
2216 }
2217
2218 /// Print details of a single repository
2219 fn print_repository_detailsrust-analyzer cargo apt-sources 0.3.0 print_repository_details().(source: &str, path: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, format: RepoFormatrust-analyzer cargo apt-sources 0.3.0 RepoFormat#, repo: &Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#) {
2220 let format_str = match format {
2221 RepoFormatrust-analyzer cargo apt-sources 0.3.0 RepoFormat#::Deb822rust-analyzer cargo apt-sources 0.3.0 RepoFormat#Deb822# => "DEB822".greenrust-analyzer cargo colored 3.1.1 Colorize#green().(),
2222 RepoFormatrust-analyzer cargo apt-sources 0.3.0 RepoFormat#::Legacyrust-analyzer cargo apt-sources 0.3.0 RepoFormat#Legacy# => "Legacy".yellowrust-analyzer cargo colored 3.1.1 Colorize#yellow().(),
2223 };
2224 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(
2225 "{} {} [{}]",
2226 "Source:".boldrust-analyzer cargo colored 3.1.1 impl#[`&str`][Colorize]bold().(),
2227 source.bright_bluerust-analyzer cargo colored 3.1.1 Colorize#bright_blue().(),
2228 format_str
2229 );
2230 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(
2231 " {}: {}",
2232 "File".dimmedrust-analyzer cargo colored 3.1.1 impl#[`&str`][Colorize]dimmed().(),
2233 path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().bright_cyanrust-analyzer cargo colored 3.1.1 Colorize#bright_cyan().()
2234 );
2235
2236 let enabled_str = if repo.enabledrust-analyzer cargo apt-sources 0.3.0 Repository#enabled..unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(true) {
2237 "enabled".greenrust-analyzer cargo colored 3.1.1 Colorize#green().()
2238 } else {
2239 "disabled".redrust-analyzer cargo colored 3.1.1 Colorize#red().()
2240 };
2241 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(" {}: {}", "Status".dimmedrust-analyzer cargo colored 3.1.1 impl#[`&str`][Colorize]dimmed().(), enabled_str);
2242
2243 let types: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&str> = repo
2244 .typesrust-analyzer cargo apt-sources 0.3.0 Repository#types.
2245 .iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]iter().()
2246 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|t| match t {
2247 RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary# => "deb",
2248 RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Sourcerust-analyzer cargo apt-sources 0.3.0 RepositoryType#Source# => "deb-src",
2249 })
2250 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
2251 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(" Types: {}", types.joinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]join().(", "));
2252
2253 for uri in &repo.urisrust-analyzer cargo apt-sources 0.3.0 Repository#uris. {
2254 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(" URI: {}", uri);
2255 }
2256
2257 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(" Suites: {}", repo.suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites..joinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]join().(", "));
2258
2259 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(components) = &repo.componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components. {
2260 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(" Components: {}", components.joinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]join().(" "));
2261 }
2262
2263 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().repo.architecturesrust-analyzer cargo apt-sources 0.3.0 impl#[Repository]architectures().().is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() {
2264 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(" Architectures: {}", repo.architecturesrust-analyzer cargo apt-sources 0.3.0 impl#[Repository]architectures().().joinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]join().(" "));
2265 }
2266
2267 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(signature) = &repo.signaturerust-analyzer cargo apt-sources 0.3.0 Repository#signature. {
2268 match signature {
2269 Signaturerust-analyzer cargo apt-sources 0.3.0 signature/Signature#::KeyPathrust-analyzer cargo apt-sources 0.3.0 signature/Signature#KeyPath#(p) => printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(" Signed-By: {}", p.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().()),
2270 Signaturerust-analyzer cargo apt-sources 0.3.0 signature/Signature#::KeyBlockrust-analyzer cargo apt-sources 0.3.0 signature/Signature#KeyBlock#(_) => printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(" Signed-By: [embedded key]"),
2271 }
2272 }
2273
2274 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(); // Empty line between repositories
2275 }
2276
2277 fn list_repositoriesrust-analyzer cargo apt-sources 0.3.0 list_repositories().(args: &Argsrust-analyzer cargo apt-sources 0.3.0 Args#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
2278 inforust-analyzer cargo log 0.4.29 macros/info!!("Listing all configured APT repositories");
2279
2280 let mut all_repos = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
2281 let sources_manager = SourcesManagerrust-analyzer cargo apt-sources 0.3.0 sources_manager/SourcesManager#::newrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]new().(&args.directoryrust-analyzer cargo apt-sources 0.3.0 Args#directory., &args.keyring_dirrust-analyzer cargo apt-sources 0.3.0 Args#keyring_dir.);
2282
2283 // Scan all repository files using SourcesManager
2284 let repo_files = sources_manager.scan_all_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]scan_all_repositories().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
2285
2286 for (path, repositories) in repo_files {
2287 let filename = path.file_namerust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]file_name().().unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_default().().to_string_lossyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_string_lossy().();
2288 let format = if path.extensionrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]extension().().and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|s| s.to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_str().()) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("sources") {
2289 RepoFormatrust-analyzer cargo apt-sources 0.3.0 RepoFormat#::Deb822rust-analyzer cargo apt-sources 0.3.0 RepoFormat#Deb822#
2290 } else {
2291 RepoFormatrust-analyzer cargo apt-sources 0.3.0 RepoFormat#::Legacyrust-analyzer cargo apt-sources 0.3.0 RepoFormat#Legacy#
2292 };
2293
2294 for repo in repositories.iterrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]iter().() {
2295 all_repos.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().((filename.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), path.clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][Clone]clone().(), format, repo.clonerust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Clone]clone().()));
2296 }
2297 }
2298
2299 // Also check sources.list if it exists
2300 let sources_list = get_main_sources_list_pathrust-analyzer cargo apt-sources 0.3.0 get_main_sources_list_path().(&args.directoryrust-analyzer cargo apt-sources 0.3.0 Args#directory.);
2301 if sources_list.existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().() {
2302 collect_repos_from_sources_listrust-analyzer cargo apt-sources 0.3.0 collect_repos_from_sources_list().(&sources_list, &mut all_repos);
2303 }
2304
2305 // Display the repositories
2306 if all_repos.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
2307 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("No repositories configured.");
2308 } else {
2309 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("\n{}\n", "Configured APT repositories:".boldrust-analyzer cargo colored 3.1.1 impl#[`&str`][Colorize]bold().());
2310 for (source, path, format, repo) in &all_repos {
2311 print_repository_detailsrust-analyzer cargo apt-sources 0.3.0 print_repository_details().(source, path, *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().format, repo);
2312 }
2313 }
2314
2315 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
2316 }
2317
2318 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:)]
2319 enum RepoFormatrust-analyzer cargo apt-sources 0.3.0 RepoFormat# {
2320 Deb822rust-analyzer cargo apt-sources 0.3.0 RepoFormat#Deb822#,
2321 Legacyrust-analyzer cargo apt-sources 0.3.0 RepoFormat#Legacy#,
2322 }
2323
2324 fn remove_repositoryrust-analyzer cargo apt-sources 0.3.0 remove_repository().(
2325 args: &Argsrust-analyzer cargo apt-sources 0.3.0 Args#,
2326 distribution: &Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#,
2327 codename: &str,
2328 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
2329 let repository = args
2330 .repositoryrust-analyzer cargo apt-sources 0.3.0 Args#repository.
2331 .as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().()
2332 .ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| "Repository specification required".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
2333
2334 inforust-analyzer cargo log 0.4.29 macros/info!!("Removing repository: {}", repository);
2335
2336 let spec = parse_repository_specrust-analyzer cargo apt-sources 0.3.0 parse_repository_spec().(repository, 0, args, distribution, codename)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
2337
2338 let parsed = match spec {
2339 RepositorySpecrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#::Componentrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#Component#(_) => {
2340 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(
2341 "Cannot remove individual components. Remove the entire repository instead."
2342 .to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
2343 )
2344 }
2345 RepositorySpecrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#::Pocketrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#Pocket#(_) => {
2346 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(
2347 "Cannot remove individual pockets. Remove the entire repository instead."
2348 .to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
2349 )
2350 }
2351 RepositorySpecrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#::Repositoryrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#Repository#(parsed) => parsed,
2352 };
2353
2354 // Determine where the repository should be located
2355 let filepath = determine_repository_filepathrust-analyzer cargo apt-sources 0.3.0 determine_repository_filepath().(&parsed, args, distribution)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
2356
2357 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().filepath.existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().() {
2358 // If the expected file doesn't exist, also check the standard location
2359 let fallback_path = Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(&args.directoryrust-analyzer cargo apt-sources 0.3.0 Args#directory.).joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(&parsed.filenamerust-analyzer cargo apt-sources 0.3.0 ParsedRepository#filename.);
2360 if fallback_path.existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().() && fallback_path rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().filepath {
2361 return remove_repository_from_filerust-analyzer cargo apt-sources 0.3.0 remove_repository_from_file().(&fallback_path, &parsed, args);
2362 }
2363
2364 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
2365 "Repository not found in {} or {}",
2366 filepath.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().(),
2367 fallback_path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().()
2368 ));
2369 }
2370
2371 remove_repository_from_filerust-analyzer cargo apt-sources 0.3.0 remove_repository_from_file().(&filepath, &parsed, args)
2372 }
2373
2374 /// Log what keyring files would be or were removed for a PPA
2375 fn handle_ppa_keyring_removalrust-analyzer cargo apt-sources 0.3.0 handle_ppa_keyring_removal().(ppa_info: &PpaInforust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#, keyring_dir: &str, dry_run: bool) {
2376 for ext in ["asc", "gpg"] {
2377 let keyring_filename = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}-{}-keyring.{}", ppa_info.userrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#user., ppa_info.namerust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#name., ext);
2378 let keyring_path = Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(keyring_dir).joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(&keyring_filename);
2379
2380 if keyring_path.existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().() {
2381 if dry_run {
2382 inforust-analyzer cargo log 0.4.29 macros/info!!(
2383 "Would remove associated keyring: {}",
2384 keyring_path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().()
2385 );
2386 } else {
2387 fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::remove_filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/remove_file().(&keyring_path).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().(); // Ignore errors
2388 inforust-analyzer cargo log 0.4.29 macros/info!!("Associated keyring removed from {}", keyring_path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().());
2389 }
2390 }
2391 }
2392 }
2393
2394 /// Run apt update with a spinner
2395 fn run_apt_updaterust-analyzer cargo apt-sources 0.3.0 run_apt_update().() {
2396 let spinner = ProgressBarrust-analyzer cargo indicatif 0.18.4 progress_bar/ProgressBar#::new_spinnerrust-analyzer cargo indicatif 0.18.4 progress_bar/impl#[ProgressBar]new_spinner().();
2397 spinner.set_stylerust-analyzer cargo indicatif 0.18.4 progress_bar/impl#[ProgressBar]set_style().(
2398 ProgressStylerust-analyzer cargo indicatif 0.18.4 style/ProgressStyle#::default_spinnerrust-analyzer cargo indicatif 0.18.4 style/impl#[ProgressStyle]default_spinner().()
2399 .templaterust-analyzer cargo indicatif 0.18.4 style/impl#[ProgressStyle]template().("{spinner:.green} {msg}")
2400 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
2401 );
2402 spinner.set_messagerust-analyzer cargo indicatif 0.18.4 progress_bar/impl#[ProgressBar]set_message().("Updating package cache...");
2403 spinner.enable_steady_tickrust-analyzer cargo indicatif 0.18.4 progress_bar/impl#[ProgressBar]enable_steady_tick().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_millisrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_millis().(100));
2404
2405 match processrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/::Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]new().("apt").argrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]arg().("update").statusrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]status().() {
2406 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(status) if status.successrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[ExitStatus]success().() => {
2407 spinner.finish_with_messagerust-analyzer cargo indicatif 0.18.4 progress_bar/impl#[ProgressBar]finish_with_message().("Package cache updated successfully");
2408 }
2409 _ => {
2410 spinner.finish_with_messagerust-analyzer cargo indicatif 0.18.4 progress_bar/impl#[ProgressBar]finish_with_message().("apt update failed");
2411 warnrust-analyzer cargo log 0.4.29 macros/warn!!("apt update failed");
2412 }
2413 }
2414 }
2415
2416 /// Remove repository entry from a DEB822 format file
2417 fn remove_from_deb822_filerust-analyzer cargo apt-sources 0.3.0 remove_from_deb822_file().(filepath: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, target: &Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
2418 let content =
2419 fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_to_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_to_string().(filepath).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to read file: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
2420
2421 let repos = Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#::from_strrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories][FromStr]from_str().(&content)
2422 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to parse repositories: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
2423
2424 let all_repos: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#> = repos.iterrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
2425 let initial_count = all_repos.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().();
2426 let filtered_repos: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#> = all_repos
2427 .into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().()
2428 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|repo| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().repositories_matchrust-analyzer cargo apt-sources 0.3.0 repositories_match().(repo, target))
2429 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
2430
2431 if filtered_repos.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().initial_count {
2432 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#("Repository not found in file".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
2433 }
2434
2435 let remaining_repos = Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#::newrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]new().(filtered_repos);
2436 fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/write().(filepath, remaining_repos.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
2437 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to write file: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
2438
2439 inforust-analyzer cargo log 0.4.29 macros/info!!("Repository removed from {}", filepath.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().());
2440 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
2441 }
2442
2443 /// Remove repository entry from a legacy format file
2444 fn remove_from_legacy_filerust-analyzer cargo apt-sources 0.3.0 remove_from_legacy_file().(filepath: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, target: &Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
2445 let content =
2446 fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_to_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_to_string().(filepath).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to read file: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
2447
2448 let to_remove = LegacyRepositoriesrust-analyzer cargo apt-sources 0.3.0 legacy/LegacyRepositories#::fromrust-analyzer cargo apt-sources 0.3.0 legacy/impl#[LegacyRepositories][`From<&crate::Repository>`]from().(target).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
2449 let remove_lines: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = to_remove.linesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]lines().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|s| s.trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
2450
2451 let mut new_lines = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
2452 let mut removed = false;
2453
2454 for line in content.linesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]lines().() {
2455 if remove_lines.containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(line.trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().()) {
2456 removed = true;
2457 } else {
2458 new_lines.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(line);
2459 }
2460 }
2461
2462 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().removed {
2463 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#("Repository not found in file".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
2464 }
2465
2466 let new_content = new_lines.joinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]join().("\n") rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().+rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add()."\n";
2467 fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/write().(filepath, new_content).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to write file: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
2468
2469 inforust-analyzer cargo log 0.4.29 macros/info!!("Repository removed from {}", filepath.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().());
2470 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
2471 }
2472
2473 fn remove_repository_from_filerust-analyzer cargo apt-sources 0.3.0 remove_repository_from_file().(
2474 filepath: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#,
2475 parsed: &ParsedRepositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository#,
2476 args: &Argsrust-analyzer cargo apt-sources 0.3.0 Args#,
2477 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
2478 let is_main_file = is_main_distribution_filerust-analyzer cargo apt-sources 0.3.0 is_main_distribution_file().(filepath);
2479
2480 // Confirm with user if needed
2481 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().args.assume_yesrust-analyzer cargo apt-sources 0.3.0 Args#assume_yes. && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().args.dry_runrust-analyzer cargo apt-sources 0.3.0 Args#dry_run. {
2482 let prompt = if is_main_file {
2483 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Remove repository from {}? [y/N] ", filepath.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().())
2484 } else {
2485 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Remove repository file {}? [y/N] ", filepath.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().())
2486 };
2487 eprintrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprint!!("{}", prompt);
2488 iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stdout().().flushrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/impl#[Stdout][Write]flush().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2489 let mut input = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().();
2490 iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::stdinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stdin().().read_linerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/impl#[Stdin]read_line().(&mut input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2491 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().input.trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().().eq_ignore_ascii_caserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]eq_ignore_ascii_case().("y") {
2492 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#("Aborted".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
2493 }
2494 }
2495
2496 // Handle dry run
2497 if args.dry_runrust-analyzer cargo apt-sources 0.3.0 Args#dry_run. {
2498 if is_main_file {
2499 inforust-analyzer cargo log 0.4.29 macros/info!!("Would remove repository entry from {}", filepath.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().());
2500 inforust-analyzer cargo log 0.4.29 macros/info!!("Repository to remove:");
2501 let content = match args.formatrust-analyzer cargo apt-sources 0.3.0 Args#format. {
2502 OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::Legacyrust-analyzer cargo apt-sources 0.3.0 OutputFormat#Legacy# => LegacyRepositoriesrust-analyzer cargo apt-sources 0.3.0 legacy/LegacyRepositories#::fromrust-analyzer cargo apt-sources 0.3.0 legacy/impl#[LegacyRepositories][`From<&crate::Repository>`]from().(&parsed.repositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository#repository.).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
2503 OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::Deb822rust-analyzer cargo apt-sources 0.3.0 OutputFormat#Deb822# => {
2504 Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#::newrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]new().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![parsed.repositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository#repository..clonerust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Clone]clone().()]).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
2505 }
2506 };
2507 for line in content.linesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]lines().() {
2508 inforust-analyzer cargo log 0.4.29 macros/info!!(" {}", line);
2509 }
2510 } else {
2511 inforust-analyzer cargo log 0.4.29 macros/info!!("Would remove repository file: {}", filepath.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().());
2512 }
2513
2514 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref ppa_info) = parsed.ppa_inforust-analyzer cargo apt-sources 0.3.0 ParsedRepository#ppa_info. {
2515 handle_ppa_keyring_removalrust-analyzer cargo apt-sources 0.3.0 handle_ppa_keyring_removal().(ppa_info, &args.keyring_dirrust-analyzer cargo apt-sources 0.3.0 Args#keyring_dir., true);
2516 }
2517
2518 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().args.no_updaterust-analyzer cargo apt-sources 0.3.0 Args#no_update. {
2519 inforust-analyzer cargo log 0.4.29 macros/info!!("Would run: apt update");
2520 }
2521 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(());
2522 }
2523
2524 // Actual removal
2525 if is_main_file {
2526 let extension = filepath.extensionrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]extension().().and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|s| s.to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_str().()).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().("");
2527 match extension {
2528 "sources" => remove_from_deb822_filerust-analyzer cargo apt-sources 0.3.0 remove_from_deb822_file().(filepath, &parsed.repositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository#repository.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
2529 _ => remove_from_legacy_filerust-analyzer cargo apt-sources 0.3.0 remove_from_legacy_file().(filepath, &parsed.repositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository#repository.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
2530 }
2531 } else {
2532 fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::remove_filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/remove_file().(filepath).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to remove file: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
2533 inforust-analyzer cargo log 0.4.29 macros/info!!("Repository file removed: {}", filepath.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().());
2534 }
2535
2536 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref ppa_info) = parsed.ppa_inforust-analyzer cargo apt-sources 0.3.0 ParsedRepository#ppa_info. {
2537 handle_ppa_keyring_removalrust-analyzer cargo apt-sources 0.3.0 handle_ppa_keyring_removal().(ppa_info, &args.keyring_dirrust-analyzer cargo apt-sources 0.3.0 Args#keyring_dir., false);
2538 }
2539
2540 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().args.no_updaterust-analyzer cargo apt-sources 0.3.0 Args#no_update. {
2541 run_apt_updaterust-analyzer cargo apt-sources 0.3.0 run_apt_update().();
2542 }
2543
2544 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
2545 }
2546
2547 fn repositories_matchrust-analyzer cargo apt-sources 0.3.0 repositories_match().(repo1: &Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#, repo2: &Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#) -> bool {
2548 // Compare repositories for equality
2549 repo1.typesrust-analyzer cargo apt-sources 0.3.0 Repository#types. rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`][`PartialEq<Self>`]eq().==rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`][`PartialEq<Self>`]eq(). rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`][`PartialEq<Self>`]eq().repo2.typesrust-analyzer cargo apt-sources 0.3.0 Repository#types.
2550 && repo1.urisrust-analyzer cargo apt-sources 0.3.0 Repository#uris. rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Vec<T, A1>`][`PartialEq<Vec<U, A2>>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Vec<T, A1>`][`PartialEq<Vec<U, A2>>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Vec<T, A1>`][`PartialEq<Vec<U, A2>>`]eq().repo2.urisrust-analyzer cargo apt-sources 0.3.0 Repository#uris.
2551 && repo1.suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites. rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Vec<T, A1>`][`PartialEq<Vec<U, A2>>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Vec<T, A1>`][`PartialEq<Vec<U, A2>>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Vec<T, A1>`][`PartialEq<Vec<U, A2>>`]eq().repo2.suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites.
2552 && repo1.componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().repo2.componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components.
2553 && repo1.architecturesrust-analyzer cargo apt-sources 0.3.0 Repository#architectures. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().repo2.architecturesrust-analyzer cargo apt-sources 0.3.0 Repository#architectures.
2554 }
2555
2556 fn mainrust-analyzer cargo apt-sources 0.3.0 main().() {
2557 env_loggerrust-analyzer cargo env_logger 0.11.10 crate/::initrust-analyzer cargo env_logger 0.11.10 logger/init().();
2558 let args = Argsrust-analyzer cargo apt-sources 0.3.0 Args#::parserust-analyzer cargo clap_builder 4.6.0 derive/Parser#parse().();
2559
2560 // Check if login is requested without launchpad feature
2561 #[cfg(not(feature = "launchpad"))]
2562 if args.login {
2563 errorrust-analyzer cargo log 0.4.29 macros/error!!("Private PPA support requires building with the 'launchpad' feature");
2564 errorrust-analyzer cargo log 0.4.29 macros/error!!("Rebuild with: cargo build --features launchpad");
2565 processrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/::exitrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/exit().(1);
2566 }
2567
2568 // Detect distribution and codename once at startup
2569 let distribution = Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#::currentrust-analyzer cargo apt-sources 0.3.0 distribution/impl#[Distribution]current().().unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#::Debianrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#Debian#);
2570 let (codename, _arch) =
2571 get_system_inforust-analyzer cargo apt-sources 0.3.0 distribution/get_system_info().().unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| ("stable".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().()));
2572
2573 let result = if args.listrust-analyzer cargo apt-sources 0.3.0 Args#list. {
2574 list_repositoriesrust-analyzer cargo apt-sources 0.3.0 list_repositories().(&args)
2575 } else if args.refresh_keysrust-analyzer cargo apt-sources 0.3.0 Args#refresh_keys. {
2576 refresh_ppa_keysrust-analyzer cargo apt-sources 0.3.0 refresh_ppa_keys().(&args)
2577 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(component) = &args.componentrust-analyzer cargo apt-sources 0.3.0 Args#component. {
2578 // Handle --component flag
2579 add_component_to_existing_reposrust-analyzer cargo apt-sources 0.3.0 add_component_to_existing_repos().(component, &args.directoryrust-analyzer cargo apt-sources 0.3.0 Args#directory., args.dry_runrust-analyzer cargo apt-sources 0.3.0 Args#dry_run., &distribution)
2580 } else if args.enable_sourcerust-analyzer cargo apt-sources 0.3.0 Args#enable_source. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().0 && args.repositoryrust-analyzer cargo apt-sources 0.3.0 Args#repository..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() {
2581 // Handle global source enablement when no repository is specified
2582 enable_sources_globallyrust-analyzer cargo apt-sources 0.3.0 enable_sources_globally().(&args)
2583 } else if args.removerust-analyzer cargo apt-sources 0.3.0 Args#remove. {
2584 remove_repositoryrust-analyzer cargo apt-sources 0.3.0 remove_repository().(&args, &distribution, &codename)
2585 } else {
2586 add_repositoryrust-analyzer cargo apt-sources 0.3.0 add_repository().(&args, &distribution, &codename)
2587 };
2588
2589 if let Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) = result {
2590 errorrust-analyzer cargo log 0.4.29 macros/error!!("{}", e);
2591 processrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/::exitrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/exit().(1);
2592 }
2593 }
2594
2595 #[cfg(test)]
2596 mod testsrust-analyzer cargo apt-sources 0.3.0 tests/ {
2597 use superrust-analyzer cargo apt-sources 0.3.0 crate/::*;
2598 use sequoia_openpgprust-analyzer cargo sequoia-openpgp 2.3.0 crate/::certrust-analyzer cargo sequoia-openpgp 2.3.0 cert/::CertBuilderrust-analyzer cargo sequoia-openpgp 2.3.0 cert/builder/CertBuilder#;
2599 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#;
2600
2601 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
2602 fn test_create_inline_signaturerust-analyzer cargo apt-sources 0.3.0 tests/test_create_inline_signature().() {
2603 // Use a minimal valid PGP key structure
2604 let key_data = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n\nmQENBFXbjPUBCADRje\n=ABCD\n-----END PGP PUBLIC KEY BLOCK-----";
2605
2606 // The create_inline_signature now validates the key, so we expect it to fail
2607 // with this truncated test key
2608 let result = create_inline_signaturerust-analyzer cargo apt-sources 0.3.0 key_management/create_inline_signature().(key_data);
2609
2610 // For now, just check that the function exists and can be called
2611 // In real usage, it would have a valid key
2612 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(result.is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().() || result.is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
2613 }
2614
2615 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
2616 fn test_format_network_errorrust-analyzer cargo apt-sources 0.3.0 tests/test_format_network_error().() {
2617 // We can't easily create actual reqwest errors, but we can test the function exists
2618 // and returns reasonable strings for the error types we can simulate
2619
2620 // In a real test environment, you would mock the reqwest errors
2621 // For now, we just verify the function compiles
2622 // Note: We can't call the function without a real reqwest::Error instance
2623 }
2624
2625 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
2626 fn test_is_main_distribution_filerust-analyzer cargo apt-sources 0.3.0 tests/test_is_main_distribution_file().() {
2627 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(is_main_distribution_filerust-analyzer cargo apt-sources 0.3.0 is_main_distribution_file().(Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(
2628 "/etc/apt/sources.list"
2629 )));
2630 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(is_main_distribution_filerust-analyzer cargo apt-sources 0.3.0 is_main_distribution_file().(Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(
2631 "/etc/apt/sources.list.d/ubuntu.sources"
2632 )));
2633 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(is_main_distribution_filerust-analyzer cargo apt-sources 0.3.0 is_main_distribution_file().(Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(
2634 "/etc/apt/sources.list.d/debian.sources"
2635 )));
2636 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(is_main_distribution_filerust-analyzer cargo apt-sources 0.3.0 is_main_distribution_file().(Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().("/path/to/ubuntu.list")));
2637 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(is_main_distribution_filerust-analyzer cargo apt-sources 0.3.0 is_main_distribution_file().(Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().("/path/to/debian.list")));
2638
2639 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_main_distribution_filerust-analyzer cargo apt-sources 0.3.0 is_main_distribution_file().(Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(
2640 "/etc/apt/sources.list.d/ppa.sources"
2641 )));
2642 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_main_distribution_filerust-analyzer cargo apt-sources 0.3.0 is_main_distribution_file().(Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(
2643 "/etc/apt/sources.list.d/custom.list"
2644 )));
2645 }
2646
2647 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
2648 fn test_repositories_matchrust-analyzer cargo apt-sources 0.3.0 tests/test_repositories_match().() {
2649 let repo1 = Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository# {
2650 typesrust-analyzer cargo apt-sources 0.3.0 Repository#types.: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`][`From<[T; N]>`]from().([RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary#]),
2651 urisrust-analyzer cargo apt-sources 0.3.0 Repository#uris.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().("http://example.com/repo").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()],
2652 suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["focal".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()],
2653 componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["main".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()]),
2654 architecturesrust-analyzer cargo apt-sources 0.3.0 Repository#architectures.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["amd64".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()]),
2655 ..Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Default]default().()
2656 };
2657
2658 let repo2 = repo1.clonerust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Clone]clone().();
2659 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(repositories_matchrust-analyzer cargo apt-sources 0.3.0 repositories_match().(&repo1, &repo2));
2660
2661 // Different URIs
2662 let mut repo3 = repo1.clonerust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Clone]clone().();
2663 repo3.urisrust-analyzer cargo apt-sources 0.3.0 Repository#uris. = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().("http://different.com/repo").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()];
2664 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().repositories_matchrust-analyzer cargo apt-sources 0.3.0 repositories_match().(&repo1, &repo3));
2665
2666 // Different components
2667 let mut repo4 = repo1.clonerust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Clone]clone().();
2668 repo4.componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["universe".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()]);
2669 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().repositories_matchrust-analyzer cargo apt-sources 0.3.0 repositories_match().(&repo1, &repo4));
2670 }
2671
2672 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
2673 fn test_get_distribution_inforust-analyzer cargo apt-sources 0.3.0 tests/test_get_distribution_info().() {
2674 // This test will depend on the system it's run on
2675 // We just verify it returns a valid Distribution enum when available
2676 let dist = Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#::currentrust-analyzer cargo apt-sources 0.3.0 distribution/impl#[Distribution]current().();
2677
2678 // On systems with /etc/os-release (Linux), we should get Some
2679 // On systems without it (macOS), we get None - both are acceptable
2680 if stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().("/etc/os-release").existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().() {
2681 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(dist.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().());
2682 match dist.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().() {
2683 Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#::Ubunturust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#Ubuntu# | Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#::Debianrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#Debian# | Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#::Otherrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#Other#(_) => {
2684 // All valid variants
2685 }
2686 }
2687 } else {
2688 // On macOS or other systems without /etc/os-release, None is expected
2689 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(dist.is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().());
2690 }
2691 }
2692
2693 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
2694 fn test_check_key_expirationrust-analyzer cargo apt-sources 0.3.0 tests/test_check_key_expiration().() {
2695 // Create a cert that's valid for 60 days
2696 let (cert, _) = CertBuilderrust-analyzer cargo sequoia-openpgp 2.3.0 cert/builder/CertBuilder#::newrust-analyzer cargo sequoia-openpgp 2.3.0 cert/builder/impl#[`CertBuilder<'_>`]new().()
2697 .set_validity_periodrust-analyzer cargo sequoia-openpgp 2.3.0 cert/builder/impl#[`CertBuilder<'_>`]set_validity_period().(Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_secsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_secs().(60 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().24 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().60 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().60))
2698 .generaterust-analyzer cargo sequoia-openpgp 2.3.0 cert/builder/impl#[`CertBuilder<'_>`]generate().()
2699 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2700
2701 let warning = apt_sourcesrust-analyzer cargo apt-sources 0.3.0 crate/::key_managementrust-analyzer cargo apt-sources 0.3.0 key_management/::check_key_expirationrust-analyzer cargo apt-sources 0.3.0 key_management/check_key_expiration().(&cert);
2702 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(warning.is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().());
2703
2704 // Note: Testing expired certs would require creating a cert with
2705 // a past expiration date, which CertBuilder doesn't easily support
2706 // The function only checks if a cert is currently expired, not if it's expiring soon
2707 }
2708
2709 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
2710 fn test_generate_filenamerust-analyzer cargo apt-sources 0.3.0 tests/test_generate_filename().() {
2711 let dist = Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#::Ubunturust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#Ubuntu#;
2712
2713 // Test PPA URL
2714 let filename = generate_filenamerust-analyzer cargo apt-sources 0.3.0 generate_filename().(
2715 "https://ppa.launchpad.net/user/ppa/ubuntu",
2716 OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::Deb822rust-analyzer cargo apt-sources 0.3.0 OutputFormat#Deb822#,
2717 &dist,
2718 );
2719 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(filename.ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().(".sources"));
2720
2721 // Test main Ubuntu repository
2722 let filename = generate_filenamerust-analyzer cargo apt-sources 0.3.0 generate_filename().(
2723 "http://archive.ubuntu.com/ubuntu",
2724 OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::Deb822rust-analyzer cargo apt-sources 0.3.0 OutputFormat#Deb822#,
2725 &dist,
2726 );
2727 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(filename, "ubuntu.sources");
2728
2729 // Test main Ubuntu repository with legacy format
2730 let filename = generate_filenamerust-analyzer cargo apt-sources 0.3.0 generate_filename().(
2731 "http://archive.ubuntu.com/ubuntu",
2732 OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::Legacyrust-analyzer cargo apt-sources 0.3.0 OutputFormat#Legacy#,
2733 &dist,
2734 );
2735 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(filename, "ubuntu.list");
2736
2737 // Test third-party repository
2738 let filename = generate_filenamerust-analyzer cargo apt-sources 0.3.0 generate_filename().("https://example.com/repo", OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::Deb822rust-analyzer cargo apt-sources 0.3.0 OutputFormat#Deb822#, &dist);
2739 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(filename.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("example.com"));
2740 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(filename.ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().(".sources"));
2741 }
2742
2743 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
2744 fn test_default_suite_componentsrust-analyzer cargo apt-sources 0.3.0 tests/test_default_suite_components().() {
2745 let (suite, components) = default_suite_componentsrust-analyzer cargo apt-sources 0.3.0 default_suite_components().("focal");
2746 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(suite, "focal");
2747 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(components, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["main".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()]);
2748 }
2749
2750 fn create_test_argsrust-analyzer cargo apt-sources 0.3.0 tests/create_test_args().() -> Argsrust-analyzer cargo apt-sources 0.3.0 Args# {
2751 Argsrust-analyzer cargo apt-sources 0.3.0 Args# {
2752 repositoryrust-analyzer cargo apt-sources 0.3.0 Args#repository.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
2753 no_updaterust-analyzer cargo apt-sources 0.3.0 Args#no_update.: false,
2754 enable_sourcerust-analyzer cargo apt-sources 0.3.0 Args#enable_source.: 0,
2755 assume_yesrust-analyzer cargo apt-sources 0.3.0 Args#assume_yes.: false,
2756 removerust-analyzer cargo apt-sources 0.3.0 Args#remove.: false,
2757 directoryrust-analyzer cargo apt-sources 0.3.0 Args#directory.: DEFAULT_SOURCES_PATHrust-analyzer cargo apt-sources 0.3.0 sources_manager/DEFAULT_SOURCES_PATH..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
2758 keyring_dirrust-analyzer cargo apt-sources 0.3.0 Args#keyring_dir.: DEFAULT_KEYRING_PATHrust-analyzer cargo apt-sources 0.3.0 sources_manager/DEFAULT_KEYRING_PATH..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
2759 pocketrust-analyzer cargo apt-sources 0.3.0 Args#pocket.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
2760 keyserverrust-analyzer cargo apt-sources 0.3.0 Args#keyserver.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
2761 componentrust-analyzer cargo apt-sources 0.3.0 Args#component.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
2762 listrust-analyzer cargo apt-sources 0.3.0 Args#list.: false,
2763 loginrust-analyzer cargo apt-sources 0.3.0 Args#login.: false,
2764 dry_runrust-analyzer cargo apt-sources 0.3.0 Args#dry_run.: false,
2765 formatrust-analyzer cargo apt-sources 0.3.0 Args#format.: OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::Legacyrust-analyzer cargo apt-sources 0.3.0 OutputFormat#Legacy#,
2766 refresh_keysrust-analyzer cargo apt-sources 0.3.0 Args#refresh_keys.: false,
2767 inline_keyrust-analyzer cargo apt-sources 0.3.0 Args#inline_key.: false,
2768 }
2769 }
2770
2771 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
2772 fn test_parse_repository_specrust-analyzer cargo apt-sources 0.3.0 tests/test_parse_repository_spec().() {
2773 let args = create_test_argsrust-analyzer cargo apt-sources 0.3.0 tests/create_test_args().();
2774 let distribution = Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#::Ubunturust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#Ubuntu#;
2775 let codename = "noble";
2776
2777 // Test PPA format
2778 let spec =
2779 parse_repository_specrust-analyzer cargo apt-sources 0.3.0 parse_repository_spec().("ppa:user/repo", 0, &args, &distribution, codename).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2780 match spec {
2781 RepositorySpecrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#::Repositoryrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#Repository#(parsed) => {
2782 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parsed.ppa_inforust-analyzer cargo apt-sources 0.3.0 ParsedRepository#ppa_info..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().());
2783 let ppa = parsed.ppa_inforust-analyzer cargo apt-sources 0.3.0 ParsedRepository#ppa_info..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
2784 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ppa.userrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#user., "user");
2785 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ppa.namerust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#name., "repo");
2786 }
2787 _ => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected Repository spec with PPA info"),
2788 }
2789
2790 // NOTE: Component and pocket tests require real system info from get_system_info()
2791 // These tests are skipped as they depend on the runtime environment
2792
2793 let distribution = Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#::Debianrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#Debian#;
2794 let codename = "stable";
2795
2796 // Test full deb line
2797 let spec = parse_repository_specrust-analyzer cargo apt-sources 0.3.0 parse_repository_spec().(
2798 "deb http://example.com focal main",
2799 0,
2800 &args,
2801 &distribution,
2802 codename,
2803 )
2804 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2805 match spec {
2806 RepositorySpecrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#::Repositoryrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#Repository#(parsed) => {
2807 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parsed.repositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository#repository..urisrust-analyzer cargo apt-sources 0.3.0 Repository#uris.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().
2808 .as_strrust-analyzer cargo url 2.5.8 impl#[Url]as_str().()
2809 .containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("http://example.com"));
2810 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parsed.repositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository#repository..suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites., vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["focal"]);
2811 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parsed.repositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository#repository..componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components., Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["main".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()]));
2812 }
2813 _ => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected Repository spec"),
2814 }
2815 }
2816
2817 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
2818 fn test_parse_repository_linerust-analyzer cargo apt-sources 0.3.0 tests/test_parse_repository_line().() {
2819 // Test basic deb line
2820 let (types, uri, suite, components, signed_by) =
2821 parse_repository_linerust-analyzer cargo apt-sources 0.3.0 parse_repository_line().("deb http://example.com focal main universe").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2822 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(types.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary#));
2823 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(uri.as_strrust-analyzer cargo url 2.5.8 impl#[Url]as_str().(), "http://example.com/");
2824 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(suite, "focal");
2825 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(components, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["main", "universe"]);
2826 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(signed_by.is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().());
2827
2828 // Test deb-src line
2829 let (types, uri, suite, components, signed_by) =
2830 parse_repository_linerust-analyzer cargo apt-sources 0.3.0 parse_repository_line().("deb-src http://example.com focal main").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2831 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(types.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Sourcerust-analyzer cargo apt-sources 0.3.0 RepositoryType#Source#));
2832 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(uri.as_strrust-analyzer cargo url 2.5.8 impl#[Url]as_str().(), "http://example.com/");
2833 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(suite, "focal");
2834 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(components, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["main"]);
2835 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(signed_by.is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().());
2836
2837 // Test with trailing slash
2838 let (types, uri, suite, components, signed_by) =
2839 parse_repository_linerust-analyzer cargo apt-sources 0.3.0 parse_repository_line().("deb http://example.com/ focal main").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2840 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(types.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary#));
2841 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(uri.as_strrust-analyzer cargo url 2.5.8 impl#[Url]as_str().(), "http://example.com/");
2842 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(suite, "focal");
2843 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(components, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["main"]);
2844 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(signed_by.is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().());
2845
2846 // Test invalid line
2847 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parse_repository_linerust-analyzer cargo apt-sources 0.3.0 parse_repository_line().("invalid line").is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
2848 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parse_repository_linerust-analyzer cargo apt-sources 0.3.0 parse_repository_line().("deb").is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
2849 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parse_repository_linerust-analyzer cargo apt-sources 0.3.0 parse_repository_line().("deb http://example.com").is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
2850 }
2851
2852 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
2853 fn test_find_matching_binary_reporust-analyzer cargo apt-sources 0.3.0 tests/test_find_matching_binary_repo().() {
2854 // Create a binary repository
2855 let binary_repo = Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository# {
2856 typesrust-analyzer cargo apt-sources 0.3.0 Repository#types.: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`][`From<[T; N]>`]from().([RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary#]),
2857 urisrust-analyzer cargo apt-sources 0.3.0 Repository#uris.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().("http://example.com/repo").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()],
2858 suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["focal".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()],
2859 componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["main".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()]),
2860 ..Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Default]default().()
2861 };
2862
2863 // Create a source repository
2864 let source_repo = Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository# {
2865 typesrust-analyzer cargo apt-sources 0.3.0 Repository#types.: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`][`From<[T; N]>`]from().([RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Sourcerust-analyzer cargo apt-sources 0.3.0 RepositoryType#Source#]),
2866 urisrust-analyzer cargo apt-sources 0.3.0 Repository#uris.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().("http://example.com/repo").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()],
2867 suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["focal".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()],
2868 componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["main".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()]),
2869 ..Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Default]default().()
2870 };
2871
2872 let repos = Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#::newrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]new().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![binary_repo.clonerust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Clone]clone().(), source_repo.clonerust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Clone]clone().()]);
2873
2874 // Test finding matching binary repo
2875 let match_found = find_matching_binary_reporust-analyzer cargo apt-sources 0.3.0 find_matching_binary_repo().(&repos, &source_repo);
2876 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(match_found.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().());
2877 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
2878 match_found.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().typesrust-analyzer cargo apt-sources 0.3.0 Repository#types.,
2879 HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`][`From<[T; N]>`]from().([RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary#])
2880 );
2881
2882 // Test with non-matching source repo
2883 let non_matching = Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository# {
2884 typesrust-analyzer cargo apt-sources 0.3.0 Repository#types.: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`][`From<[T; N]>`]from().([RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Sourcerust-analyzer cargo apt-sources 0.3.0 RepositoryType#Source#]),
2885 urisrust-analyzer cargo apt-sources 0.3.0 Repository#uris.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().("http://different.com/repo").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()],
2886 suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["focal".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()],
2887 componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["main".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()]),
2888 ..Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Default]default().()
2889 };
2890 let match_found = find_matching_binary_reporust-analyzer cargo apt-sources 0.3.0 find_matching_binary_repo().(&repos, &non_matching);
2891 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(match_found.is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().());
2892 }
2893
2894 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
2895 fn test_is_duplicate_repositoryrust-analyzer cargo apt-sources 0.3.0 tests/test_is_duplicate_repository().() {
2896 let repo1 = Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository# {
2897 typesrust-analyzer cargo apt-sources 0.3.0 Repository#types.: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`][`From<[T; N]>`]from().([RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary#]),
2898 urisrust-analyzer cargo apt-sources 0.3.0 Repository#uris.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().("http://example.com/repo").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()],
2899 suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["focal".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()],
2900 componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["main".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()]),
2901 ..Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Default]default().()
2902 };
2903
2904 // Test exact duplicate
2905 let uris: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`][`From<[T; N]>`]from().(["http://example.com/repo".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()]);
2906 let suites: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`][`From<[T; N]>`]from().(["focal".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()]);
2907 let components: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`][`From<[T; N]>`]from().(["main".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()]);
2908 let types = HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`][`From<[T; N]>`]from().([RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary#]);
2909
2910 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(is_duplicate_repositoryrust-analyzer cargo apt-sources 0.3.0 is_duplicate_repository().(
2911 &repo1,
2912 &uris,
2913 &suites,
2914 &components,
2915 &types
2916 ));
2917
2918 // Different types
2919 let different_types = HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`][`From<[T; N]>`]from().([RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Sourcerust-analyzer cargo apt-sources 0.3.0 RepositoryType#Source#]);
2920 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_duplicate_repositoryrust-analyzer cargo apt-sources 0.3.0 is_duplicate_repository().(
2921 &repo1,
2922 &uris,
2923 &suites,
2924 &components,
2925 &different_types
2926 ));
2927
2928 // Different URIs
2929 let different_uris = HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`][`From<[T; N]>`]from().(["http://different.com/repo".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()]);
2930 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_duplicate_repositoryrust-analyzer cargo apt-sources 0.3.0 is_duplicate_repository().(
2931 &repo1,
2932 &different_uris,
2933 &suites,
2934 &components,
2935 &types
2936 ));
2937
2938 // Different suites
2939 let different_suites = HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`][`From<[T; N]>`]from().(["jammy".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()]);
2940 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_duplicate_repositoryrust-analyzer cargo apt-sources 0.3.0 is_duplicate_repository().(
2941 &repo1,
2942 &uris,
2943 &different_suites,
2944 &components,
2945 &types
2946 ));
2947 }
2948
2949 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
2950 fn test_determine_repository_filepathrust-analyzer cargo apt-sources 0.3.0 tests/test_determine_repository_filepath().() {
2951 let args = create_test_argsrust-analyzer cargo apt-sources 0.3.0 tests/create_test_args().();
2952 let distribution = Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#::Debianrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#Debian#;
2953
2954 // Test PPA repository
2955 let ppa_repo = ParsedRepositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository# {
2956 repositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository#repository.: Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository# {
2957 enabledrust-analyzer cargo apt-sources 0.3.0 Repository#enabled.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(true),
2958 typesrust-analyzer cargo apt-sources 0.3.0 Repository#types.: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`][`From<[T; N]>`]from().([RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary#]),
2959 urisrust-analyzer cargo apt-sources 0.3.0 Repository#uris.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().("http://ppa.launchpad.net/user/ppa/ubuntu").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()],
2960 suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["focal".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()],
2961 componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["main".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()]),
2962 ..Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Default]default().()
2963 },
2964 filenamerust-analyzer cargo apt-sources 0.3.0 ParsedRepository#filename.: "user-ubuntu-ppa-focal.list".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
2965 ppa_inforust-analyzer cargo apt-sources 0.3.0 ParsedRepository#ppa_info.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(PpaInforust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo# {
2966 userrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#user.: "user".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
2967 namerust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#name.: "ppa".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
2968 }),
2969 };
2970 let path = determine_repository_filepathrust-analyzer cargo apt-sources 0.3.0 determine_repository_filepath().(&ppa_repo, &args, &distribution).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2971 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(path.to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]to_str().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().(".list")); // Legacy format is default in test args
2972 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(path.to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]to_str().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("user"));
2973
2974 // Test non-PPA repository
2975 let url_repo = ParsedRepositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository# {
2976 repositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository#repository.: Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository# {
2977 enabledrust-analyzer cargo apt-sources 0.3.0 Repository#enabled.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(true),
2978 typesrust-analyzer cargo apt-sources 0.3.0 Repository#types.: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`][`From<[T; N]>`]from().([RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary#]),
2979 urisrust-analyzer cargo apt-sources 0.3.0 Repository#uris.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().("https://example.com/repo").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()],
2980 suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["focal".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()],
2981 componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["main".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()]),
2982 ..Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Default]default().()
2983 },
2984 filenamerust-analyzer cargo apt-sources 0.3.0 ParsedRepository#filename.: "example.com.list".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
2985 ppa_inforust-analyzer cargo apt-sources 0.3.0 ParsedRepository#ppa_info.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
2986 };
2987 let path = determine_repository_filepathrust-analyzer cargo apt-sources 0.3.0 determine_repository_filepath().(&url_repo, &args, &distribution).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2988 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(path.to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]to_str().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().(".list")); // Legacy format is default in test args
2989 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(path.to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]to_str().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("example.com"));
2990
2991 // Test with deb822 format
2992 let mut args_deb822 = create_test_argsrust-analyzer cargo apt-sources 0.3.0 tests/create_test_args().();
2993 args_deb822.formatrust-analyzer cargo apt-sources 0.3.0 Args#format. = OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::Deb822rust-analyzer cargo apt-sources 0.3.0 OutputFormat#Deb822#;
2994 let mut url_repo_deb822 = url_repo.clonerust-analyzer cargo apt-sources 0.3.0 impl#[ParsedRepository][Clone]clone().();
2995 url_repo_deb822.filenamerust-analyzer cargo apt-sources 0.3.0 ParsedRepository#filename. = "example.com.sources".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
2996 let path =
2997 determine_repository_filepathrust-analyzer cargo apt-sources 0.3.0 determine_repository_filepath().(&url_repo_deb822, &args_deb822, &distribution).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2998 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(path.to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]to_str().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().(".sources"));
2999 }
3000
3001 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
3002 fn test_verify_key_fingerprintrust-analyzer cargo apt-sources 0.3.0 tests/test_verify_key_fingerprint().() {
3003 // This test needs a real PGP key to work properly
3004 // For unit testing, we'll verify the function handles invalid input correctly
3005 let invalid_key = "not a valid key";
3006 let result = verify_key_fingerprintrust-analyzer cargo apt-sources 0.3.0 verify_key_fingerprint().(invalid_key, "1234567890ABCDEF");
3007 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(result.is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
3008
3009 // Test with empty fingerprint
3010 let result = verify_key_fingerprintrust-analyzer cargo apt-sources 0.3.0 verify_key_fingerprint().(invalid_key, "");
3011 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(result.is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
3012 }
3013
3014 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
3015 fn test_get_distribution_specific_filenamerust-analyzer cargo apt-sources 0.3.0 tests/test_get_distribution_specific_filename().() {
3016 // Test Ubuntu
3017 let ubuntu_file =
3018 get_distribution_specific_filenamerust-analyzer cargo apt-sources 0.3.0 get_distribution_specific_filename().("ubuntu", "sources", &Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#::Ubunturust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#Ubuntu#);
3019 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ubuntu_file, "ubuntu.sources");
3020
3021 let ubuntu_legacy =
3022 get_distribution_specific_filenamerust-analyzer cargo apt-sources 0.3.0 get_distribution_specific_filename().("ubuntu", "list", &Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#::Ubunturust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#Ubuntu#);
3023 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ubuntu_legacy, "ubuntu.list");
3024
3025 // Test custom base name for Ubuntu
3026 let ubuntu_custom =
3027 get_distribution_specific_filenamerust-analyzer cargo apt-sources 0.3.0 get_distribution_specific_filename().("custom", "sources", &Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#::Ubunturust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#Ubuntu#);
3028 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ubuntu_custom, "ubuntu.sources");
3029
3030 // Test Debian
3031 let debian_file =
3032 get_distribution_specific_filenamerust-analyzer cargo apt-sources 0.3.0 get_distribution_specific_filename().("debian", "sources", &Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#::Debianrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#Debian#);
3033 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(debian_file, "debian.sources");
3034
3035 let debian_legacy =
3036 get_distribution_specific_filenamerust-analyzer cargo apt-sources 0.3.0 get_distribution_specific_filename().("debian", "list", &Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#::Debianrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#Debian#);
3037 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(debian_legacy, "debian.list");
3038
3039 // Test custom base name for Debian
3040 let debian_custom =
3041 get_distribution_specific_filenamerust-analyzer cargo apt-sources 0.3.0 get_distribution_specific_filename().("custom", "sources", &Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#::Debianrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#Debian#);
3042 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(debian_custom, "debian.sources");
3043
3044 // Test Other
3045 let other_file = get_distribution_specific_filenamerust-analyzer cargo apt-sources 0.3.0 get_distribution_specific_filename().(
3046 "myrepo",
3047 "sources",
3048 &Distributionrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#::Otherrust-analyzer cargo apt-sources 0.3.0 distribution/Distribution#Other#("custom".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()),
3049 );
3050 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(other_file, "myrepo.sources");
3051 }
3052
3053 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
3054 fn test_output_format_from_strrust-analyzer cargo apt-sources 0.3.0 tests/test_output_format_from_str().() {
3055 // Test valid formats
3056 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
3057 OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::from_strrust-analyzer cargo apt-sources 0.3.0 impl#[OutputFormat][FromStr]from_str().("deb822").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
3058 OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::Deb822rust-analyzer cargo apt-sources 0.3.0 OutputFormat#Deb822#
3059 );
3060 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
3061 OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::from_strrust-analyzer cargo apt-sources 0.3.0 impl#[OutputFormat][FromStr]from_str().("sources").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
3062 OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::Deb822rust-analyzer cargo apt-sources 0.3.0 OutputFormat#Deb822#
3063 );
3064 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
3065 OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::from_strrust-analyzer cargo apt-sources 0.3.0 impl#[OutputFormat][FromStr]from_str().("legacy").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
3066 OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::Legacyrust-analyzer cargo apt-sources 0.3.0 OutputFormat#Legacy#
3067 );
3068 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
3069 OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::from_strrust-analyzer cargo apt-sources 0.3.0 impl#[OutputFormat][FromStr]from_str().("list").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
3070 OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::Legacyrust-analyzer cargo apt-sources 0.3.0 OutputFormat#Legacy#
3071 );
3072
3073 // Test case insensitive
3074 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
3075 OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::from_strrust-analyzer cargo apt-sources 0.3.0 impl#[OutputFormat][FromStr]from_str().("DEB822").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
3076 OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::Deb822rust-analyzer cargo apt-sources 0.3.0 OutputFormat#Deb822#
3077 );
3078 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
3079 OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::from_strrust-analyzer cargo apt-sources 0.3.0 impl#[OutputFormat][FromStr]from_str().("LEGACY").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
3080 OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::Legacyrust-analyzer cargo apt-sources 0.3.0 OutputFormat#Legacy#
3081 );
3082
3083 // Test invalid formats
3084 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::from_strrust-analyzer cargo apt-sources 0.3.0 impl#[OutputFormat][FromStr]from_str().("invalid").is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
3085 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(OutputFormatrust-analyzer cargo apt-sources 0.3.0 OutputFormat#::from_strrust-analyzer cargo apt-sources 0.3.0 impl#[OutputFormat][FromStr]from_str().("").is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
3086 }
3087
3088 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
3089 fn test_get_system_inforust-analyzer cargo apt-sources 0.3.0 tests/test_get_system_info().() {
3090 // This test might fail on non-Linux systems
3091 if stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().("/etc/os-release").existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().() {
3092 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((codename, arch)) = get_system_inforust-analyzer cargo apt-sources 0.3.0 distribution/get_system_info().() {
3093 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().codename.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().());
3094 // arch is now empty - APT will use system default
3095 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(arch.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().());
3096 }
3097 // It's okay if this returns None on systems without VERSION_CODENAME
3098 }
3099 }
3100
3101 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
3102 fn test_has_matching_source_linerust-analyzer cargo apt-sources 0.3.0 tests/test_has_matching_source_line().() {
3103 let lines = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
3104 "deb http://example.com focal main",
3105 "deb-src http://example.com focal main",
3106 "deb http://other.com focal universe",
3107 ];
3108
3109 // Test exact match
3110 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(has_matching_source_linerust-analyzer cargo apt-sources 0.3.0 has_matching_source_line().(
3111 &lines,
3112 "deb-src http://example.com focal main"
3113 ));
3114
3115 // Test no match
3116 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().has_matching_source_linerust-analyzer cargo apt-sources 0.3.0 has_matching_source_line().(
3117 &lines,
3118 "deb-src http://other.com focal main"
3119 ));
3120 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().has_matching_source_linerust-analyzer cargo apt-sources 0.3.0 has_matching_source_line().(
3121 &lines,
3122 "deb-src http://example.com focal universe"
3123 ));
3124 }
3125
3126 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
3127 fn test_has_matching_deb_linerust-analyzer cargo apt-sources 0.3.0 tests/test_has_matching_deb_line().() {
3128 let lines = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
3129 "deb http://example.com focal main",
3130 "deb-src http://example.com focal main",
3131 "deb http://other.com focal universe",
3132 ];
3133
3134 // Test conversion from deb-src to deb
3135 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(has_matching_deb_linerust-analyzer cargo apt-sources 0.3.0 has_matching_deb_line().(
3136 &lines,
3137 "deb-src http://example.com focal main"
3138 ));
3139
3140 // Test no match
3141 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().has_matching_deb_linerust-analyzer cargo apt-sources 0.3.0 has_matching_deb_line().(
3142 &lines,
3143 "deb-src http://other.com focal main"
3144 ));
3145 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().has_matching_deb_linerust-analyzer cargo apt-sources 0.3.0 has_matching_deb_line().(
3146 &lines,
3147 "deb-src http://example.com focal universe"
3148 ));
3149 }
3150
3151 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
3152 fn test_has_matching_source_reporust-analyzer cargo apt-sources 0.3.0 tests/test_has_matching_source_repo().() {
3153 // Create binary repo
3154 let binary_repo = Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository# {
3155 typesrust-analyzer cargo apt-sources 0.3.0 Repository#types.: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`][`From<[T; N]>`]from().([RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary#]),
3156 urisrust-analyzer cargo apt-sources 0.3.0 Repository#uris.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().("http://example.com").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()],
3157 suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["focal".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()],
3158 componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["main".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()]),
3159 ..Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Default]default().()
3160 };
3161
3162 // Create matching source repo
3163 let source_repo = Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository# {
3164 typesrust-analyzer cargo apt-sources 0.3.0 Repository#types.: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`][`From<[T; N]>`]from().([RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Sourcerust-analyzer cargo apt-sources 0.3.0 RepositoryType#Source#]),
3165 urisrust-analyzer cargo apt-sources 0.3.0 Repository#uris.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().("http://example.com").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()],
3166 suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["focal".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()],
3167 componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["main".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()]),
3168 ..Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Default]default().()
3169 };
3170
3171 // Create repos with both
3172 let repos = Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#::newrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]new().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![binary_repo.clonerust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Clone]clone().(), source_repo]);
3173
3174 // Test match found
3175 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(has_matching_source_reporust-analyzer cargo apt-sources 0.3.0 has_matching_source_repo().(&repos, &binary_repo));
3176
3177 // Test no match with different components
3178 let different_repo = Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository# {
3179 typesrust-analyzer cargo apt-sources 0.3.0 Repository#types.: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`][`From<[T; N]>`]from().([RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary#]),
3180 urisrust-analyzer cargo apt-sources 0.3.0 Repository#uris.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().("http://example.com").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()],
3181 suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["focal".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()],
3182 componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["universe".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()]),
3183 ..Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Default]default().()
3184 };
3185 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().has_matching_source_reporust-analyzer cargo apt-sources 0.3.0 has_matching_source_repo().(&repos, &different_repo));
3186 }
3187
3188 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
3189 fn test_ppa_inforust-analyzer cargo apt-sources 0.3.0 tests/test_ppa_info().() {
3190 let ppa = PpaInforust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo# {
3191 userrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#user.: "test-user".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
3192 namerust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#name.: "test-ppa".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
3193 };
3194
3195 // Test Debug trait implementation
3196 let debug_str = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:?}", ppa);
3197 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(debug_str.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("test-user"));
3198 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(debug_str.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("test-ppa"));
3199 }
3200
3201 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
3202 fn test_repository_spec_enumrust-analyzer cargo apt-sources 0.3.0 tests/test_repository_spec_enum().() {
3203 // Test Component variant
3204 let comp_spec = RepositorySpecrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#::Componentrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#Component#("main".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
3205 match comp_spec {
3206 RepositorySpecrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#::Componentrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#Component#(c) => assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(c, "main"),
3207 _ => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected Component variant"),
3208 }
3209
3210 // Test Pocket variant
3211 let pocket_spec = RepositorySpecrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#::Pocketrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#Pocket#("security".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
3212 match pocket_spec {
3213 RepositorySpecrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#::Pocketrust-analyzer cargo apt-sources 0.3.0 RepositorySpec#Pocket#(p) => assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(p, "security"),
3214 _ => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected Pocket variant"),
3215 }
3216 }
3217
3218 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
3219 fn test_create_http_clientrust-analyzer cargo apt-sources 0.3.0 tests/test_create_http_client().() {
3220 // Test without proxy env vars
3221 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::remove_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/remove_var().("HTTP_PROXY");
3222 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::remove_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/remove_var().("http_proxy");
3223 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::remove_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/remove_var().("HTTPS_PROXY");
3224 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::remove_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/remove_var().("https_proxy");
3225
3226 let client_result = create_http_clientrust-analyzer cargo apt-sources 0.3.0 create_http_client().();
3227 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(client_result.is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
3228
3229 // Test with invalid proxy
3230 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().("HTTP_PROXY", "not-a-valid-url");
3231 let client_result = create_http_clientrust-analyzer cargo apt-sources 0.3.0 create_http_client().();
3232 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(client_result.is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); // Should still succeed, just warn about invalid proxy
3233
3234 // Clean up
3235 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::remove_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/remove_var().("HTTP_PROXY");
3236 }
3237
3238 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
3239 fn test_validate_fingerprintrust-analyzer cargo apt-sources 0.3.0 tests/test_validate_fingerprint().() {
3240 // Valid fingerprints (40 hex chars)
3241 let valid = "1234567890ABCDEF1234567890ABCDEF12345678";
3242 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(valid.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() == 40);
3243 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(valid.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().().allrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#all().(|c| c.is_ascii_hexdigitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_ascii_hexdigit().()));
3244
3245 // Invalid fingerprints
3246 let invalid_short = "1234567890ABCDEF";
3247 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(invalid_short.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() <rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). 40);
3248
3249 let invalid_chars = "1234567890ABCDEF1234567890ABCDEF12345XYZ";
3250 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().invalid_chars.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().().allrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#all().(|c| c.is_ascii_hexdigitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_ascii_hexdigit().()));
3251 }
3252
3253 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
3254 fn test_parsed_repository_structrust-analyzer cargo apt-sources 0.3.0 tests/test_parsed_repository_struct().() {
3255 let repo = Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#::defaultrust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Default]default().();
3256 let parsed = ParsedRepositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository# {
3257 repositoryrust-analyzer cargo apt-sources 0.3.0 ParsedRepository#repository.: repo,
3258 filenamerust-analyzer cargo apt-sources 0.3.0 ParsedRepository#filename.: "test.sources".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
3259 ppa_inforust-analyzer cargo apt-sources 0.3.0 ParsedRepository#ppa_info.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(PpaInforust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo# {
3260 userrust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#user.: "test".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
3261 namerust-analyzer cargo apt-sources 0.3.0 launchpad/PpaInfo#name.: "ppa".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
3262 }),
3263 };
3264
3265 // Test Debug trait
3266 let debug_str = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:?}", parsed);
3267 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(debug_str.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("test.sources"));
3268 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(debug_str.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("ppa_info"));
3269 }
3270
3271 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
3272 fn test_empty_component_handlingrust-analyzer cargo apt-sources 0.3.0 tests/test_empty_component_handling().() {
3273 // Test that empty components are handled properly
3274 let empty_vec: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![];
3275 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validate_ppa_componentsrust-analyzer cargo apt-sources 0.3.0 launchpad/validate_ppa_components().(&empty_vec).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
3276
3277 // Test with empty string in components
3278 let vec_with_empty = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()];
3279 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validate_ppa_componentsrust-analyzer cargo apt-sources 0.3.0 launchpad/validate_ppa_components().(&vec_with_empty).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
3280 }
3281 }