Debian Codegraph @

src/sources_manager.rs

raw symbols SCIP
1 use craterust-analyzer cargo apt-sources 0.3.0 crate/::{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#};
2 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#;
3 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/;
4 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/;
5 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#;
6 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#};
7
8 /// Default path for APT sources files
9 pub const DEFAULT_SOURCES_PATHrust-analyzer cargo apt-sources 0.3.0 sources_manager/DEFAULT_SOURCES_PATH.: &str = "/etc/apt/sources.list.d";
10 /// Default path for APT keyring files
11 pub const DEFAULT_KEYRING_PATHrust-analyzer cargo apt-sources 0.3.0 sources_manager/DEFAULT_KEYRING_PATH.: &str = "/etc/apt/trusted.gpg.d";
12
13 /// Manager for APT sources and keyrings
14 #[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:)]
15 pub struct SourcesManagerrust-analyzer cargo apt-sources 0.3.0 sources_manager/SourcesManager# {
16 sources_dirrust-analyzer cargo apt-sources 0.3.0 sources_manager/SourcesManager#sources_dir.: PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#,
17 keyring_dirrust-analyzer cargo apt-sources 0.3.0 sources_manager/SourcesManager#keyring_dir.: PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#,
18 }
19
20 impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for SourcesManagerrust-analyzer cargo apt-sources 0.3.0 sources_manager/SourcesManager# {
21 fn defaultrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager][Default]default().() -> Selfrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager][Default] {
22 Selfrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager][Default] {
23 sources_dirrust-analyzer cargo apt-sources 0.3.0 sources_manager/SourcesManager#sources_dir.: 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().(DEFAULT_SOURCES_PATHrust-analyzer cargo apt-sources 0.3.0 sources_manager/DEFAULT_SOURCES_PATH.),
24 keyring_dirrust-analyzer cargo apt-sources 0.3.0 sources_manager/SourcesManager#keyring_dir.: 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().(DEFAULT_KEYRING_PATHrust-analyzer cargo apt-sources 0.3.0 sources_manager/DEFAULT_KEYRING_PATH.),
25 }
26 }
27 }
28
29 impl SourcesManagerrust-analyzer cargo apt-sources 0.3.0 sources_manager/SourcesManager# {
30 /// Create a new SourcesManager with custom directories
31 pub fn newrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]new().(sources_dir: impl Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#>, keyring_dir: impl Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#>) -> Selfrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager] {
32 Selfrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager] {
33 sources_dirrust-analyzer cargo apt-sources 0.3.0 sources_manager/SourcesManager#sources_dir.: sources_dir.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(),
34 keyring_dirrust-analyzer cargo apt-sources 0.3.0 sources_manager/SourcesManager#keyring_dir.: keyring_dir.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(),
35 }
36 }
37
38 /// Get the path to the sources directory
39 pub fn sources_dirrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]sources_dir().(&self) -> &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path# {
40 &self.sources_dirrust-analyzer cargo apt-sources 0.3.0 sources_manager/SourcesManager#sources_dir.
41 }
42
43 /// Get the path to the keyring directory
44 pub fn keyring_dirrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]keyring_dir().(&self) -> &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path# {
45 &self.keyring_dirrust-analyzer cargo apt-sources 0.3.0 sources_manager/SourcesManager#keyring_dir.
46 }
47
48 /// Generate a filename for a repository
49 pub fn generate_filenamerust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]generate_filename().(&self, name: &str, format: FileFormatrust-analyzer cargo apt-sources 0.3.0 sources_manager/FileFormat#) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
50 let sanitized = name.replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().(['/', ':', ' '], "-").to_lowercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_lowercase().();
51
52 match format {
53 FileFormatrust-analyzer cargo apt-sources 0.3.0 sources_manager/FileFormat#::Deb822rust-analyzer cargo apt-sources 0.3.0 sources_manager/FileFormat#Deb822# => formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{sanitized}.sources"),
54 FileFormatrust-analyzer cargo apt-sources 0.3.0 sources_manager/FileFormat#::Legacyrust-analyzer cargo apt-sources 0.3.0 sources_manager/FileFormat#Legacy# => formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{sanitized}.list"),
55 }
56 }
57
58 /// Get the full path for a repository file
59 pub fn get_repository_pathrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]get_repository_path().(&self, filename: &str) -> PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf# {
60 self.sources_dirrust-analyzer cargo apt-sources 0.3.0 sources_manager/SourcesManager#sources_dir..joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(filename)
61 }
62
63 /// Get the full path for a keyring file
64 pub fn get_keyring_pathrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]get_keyring_path().(&self, filename: &str) -> PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf# {
65 self.keyring_dirrust-analyzer cargo apt-sources 0.3.0 sources_manager/SourcesManager#keyring_dir..joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(filename)
66 }
67
68 /// Write repositories to a file
69 pub fn write_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]write_repositories().(&self, path: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, repositories: &Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
70 let mut file = fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::createrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]create().(path)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
71 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(file, "{repositories}")
72 }
73
74 /// Read repositories from a file
75 pub fn read_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]read_repositories().(&self, path: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
76 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)
77 .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}", path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().()))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
78
79 content
80 .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#>()
81 .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}"))
82 }
83
84 /// List all repository files in the sources directory
85 pub fn list_repository_filesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]list_repository_files().(&self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<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#>> {
86 let mut files = 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().();
87
88 if self.sources_dirrust-analyzer cargo apt-sources 0.3.0 sources_manager/SourcesManager#sources_dir..existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().() {
89 for entry in 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().(&self.sources_dirrust-analyzer cargo apt-sources 0.3.0 sources_manager/SourcesManager#sources_dir.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
90 let entry = entry?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
91 let path = entry.pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]path().();
92 if path.is_filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]is_file().() {
93 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ext) = path.extensionrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]extension().() {
94 if ext 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()."sources" || ext 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()."list" {
95 files.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(path);
96 }
97 }
98 }
99 }
100 }
101
102 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(files)
103 }
104
105 /// Scan all repository files and return their contents
106 pub fn scan_all_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]scan_all_repositories().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<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#, Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#)>, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
107 let mut results = 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().();
108
109 let files = self
110 .list_repository_filesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]list_repository_files().()
111 .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 list repository files: {}", e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
112
113 for file in files {
114 match self.read_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]read_repositories().(&file) {
115 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(repos) => results.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().((file, repos)),
116 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
117 // Log error but continue scanning
118 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("Warning: Failed to read {}: {}", file.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().(), e);
119 }
120 }
121 }
122
123 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(results)
124 }
125
126 /// Check if a repository already exists in any file
127 pub fn repository_existsrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]repository_exists().(&self, repository: &Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#) -> 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#> {
128 let all_repos = self.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().;
129
130 for (path, repos) in all_repos {
131 for repo in repos.iterrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]iter().() {
132 if repos_matchrust-analyzer cargo apt-sources 0.3.0 sources_manager/repos_match().(repo, repository) {
133 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#(path));
134 }
135 }
136 }
137
138 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#)
139 }
140
141 /// Ensure the sources and keyring directories exist
142 pub fn ensure_directoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]ensure_directories().(&self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
143 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().(&self.sources_dirrust-analyzer cargo apt-sources 0.3.0 sources_manager/SourcesManager#sources_dir.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
144 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().(&self.keyring_dirrust-analyzer cargo apt-sources 0.3.0 sources_manager/SourcesManager#keyring_dir.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
145 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
146 }
147
148 /// Add a repository to a file, creating the file if it doesn't exist
149 pub fn add_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]add_repository().(&self, repository: &Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#, filename: &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#> {
150 let path = self.get_repository_pathrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]get_repository_path().(filename);
151
152 // Check if repository already exists
153 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(existing_path) = self.repository_existsrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]repository_exists().(repository)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
154 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!!(
155 "Repository already exists in {}",
156 existing_path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().()
157 ));
158 }
159
160 // Read existing repositories if file exists
161 let mut repositories = if path.existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().() {
162 self.read_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]read_repositories().(&path)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
163 } else {
164 Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#::emptyrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]empty().()
165 };
166
167 // Add the new repository
168 repositories.pushrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]push().(repository.clonerust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Clone]clone().());
169
170 // Write back to file
171 self.write_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]write_repositories().(&path, &repositories)
172 .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 repository: {e}"))
173 }
174
175 /// Remove a repository from all files
176 pub fn remove_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]remove_repository().(&self, repository: &Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<bool, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
177 let mut removed = false;
178 let all_files = self.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().;
179
180 for (path, mut repos) in all_files {
181 let initial_count = repos.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().();
182 repos.retainrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]retain().(|r| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().repos_matchrust-analyzer cargo apt-sources 0.3.0 sources_manager/repos_match().(r, repository));
183
184 if 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][`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().initial_count {
185 removed = true;
186 if repos.is_emptyrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]is_empty().() {
187 // Remove empty file
188 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().(&path)
189 .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 {}: {e}", path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().()))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
190 } else {
191 // Write updated repositories
192 self.write_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]write_repositories().(&path, &repos)
193 .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 update {}: {e}", path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().()))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
194 }
195 }
196 }
197
198 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(removed)
199 }
200
201 /// Enable or disable a repository
202 pub fn set_repository_enabledrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]set_repository_enabled().(
203 &self,
204 repository: &Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#,
205 enabled: bool,
206 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<bool, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
207 let mut modified = false;
208 let all_files = self.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().;
209
210 for (path, mut repos) in all_files {
211 let mut changed = false;
212 for repo in repos.iter_mutrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]iter_mut().() {
213 if repos_matchrust-analyzer cargo apt-sources 0.3.0 sources_manager/repos_match().(repo, repository) && repo.enabledrust-analyzer cargo apt-sources 0.3.0 Repository#enabled. 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#(enabled) {
214 repo.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#(enabled);
215 changed = true;
216 modified = true;
217 }
218 }
219
220 if changed {
221 self.write_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]write_repositories().(&path, &repos)
222 .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 update {}: {}", 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().;
223 }
224 }
225
226 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(modified)
227 }
228
229 /// Add a component to all matching repositories
230 pub fn add_component_to_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]add_component_to_repositories().(
231 &self,
232 component: &str,
233 filter: impl Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#) -> bool,
234 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<u32, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
235 let mut modified_count = 0;
236 let all_files = self.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().;
237
238 for (path, mut repos) in all_files {
239 let mut changed = false;
240
241 for repo in repos.iter_mutrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]iter_mut().() {
242 if filter(repo) {
243 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(components) = &mut repo.componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components. {
244 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().components.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().()) {
245 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().());
246 changed = true;
247 modified_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;
248 }
249 } else {
250 repo.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!![component.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()]);
251 changed = true;
252 modified_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;
253 }
254 }
255 }
256
257 if changed {
258 self.write_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]write_repositories().(&path, &repos)
259 .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 update {}: {}", 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().;
260 }
261 }
262
263 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(modified_count)
264 }
265
266 /// Enable source repositories
267 pub fn enable_source_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]enable_source_repositories().(
268 &self,
269 create_if_missing: bool,
270 ) -> 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#> {
271 let mut enabled_count = 0;
272 let mut created_count = 0;
273 let all_files = self.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().;
274
275 for (path, mut repos) in all_files {
276 let mut changed = false;
277 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().();
278
279 for repo in repos.iter_mutrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]iter_mut().() {
280 // Check if this repo has binary type but not source
281 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#)
282 && !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#)
283 {
284 if repo.enabledrust-analyzer cargo apt-sources 0.3.0 Repository#enabled. 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#(false) {
285 // Just enable existing disabled source repo
286 repo.typesrust-analyzer cargo apt-sources 0.3.0 Repository#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#);
287 repo.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);
288 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;
289 changed = true;
290 } else if create_if_missing {
291 // Create a new source repository entry
292 let mut source_repo = repo.clonerust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Clone]clone().();
293 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#]);
294 new_repos.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(source_repo);
295 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;
296 changed = true;
297 }
298 }
299 }
300
301 // Add any new repositories
302 repos.extendrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]extend().(new_repos);
303
304 if changed {
305 self.write_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]write_repositories().(&path, &repos)
306 .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 update {}: {}", 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().;
307 }
308 }
309
310 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((enabled_count, created_count))
311 }
312
313 /// List all repositories with their file paths
314 pub fn list_all_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]list_all_repositories().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<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#, Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#)>, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
315 let files = self.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().;
316
317 // Pre-calculate capacity to avoid reallocations
318 let total_repos: usize = files.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().(|(_, repos)| repos.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()).sumrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#sum().();
319 let mut all_repos = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(total_repos);
320
321 for (path, repos) in files {
322 for repo in repos.iterrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]iter().() {
323 all_repos.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().((path.clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][Clone]clone().(), repo.clonerust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Clone]clone().()));
324 }
325 }
326
327 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(all_repos)
328 }
329
330 /// Generate a keyring filename for a repository
331 pub fn generate_keyring_filenamerust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]generate_keyring_filename().(&self, repository_name: &str) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
332 let sanitized = repository_name.replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().(['/', ':', ' '], "-").to_lowercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_lowercase().();
333 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{sanitized}.gpg")
334 }
335
336 /// Save a GPG key to the keyring directory
337 pub fn save_keyrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]save_key().(&self, key_data: &[u8], filename: &str) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#> {
338 let key_path = self.get_keyring_pathrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]get_keyring_path().(filename);
339 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().(&key_path, key_data)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
340 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(key_path)
341 }
342 }
343
344 /// File format for APT source list files
345 #[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:)]
346 pub enum FileFormatrust-analyzer cargo apt-sources 0.3.0 sources_manager/FileFormat# {
347 /// Deb822 format (new style)
348 Deb822rust-analyzer cargo apt-sources 0.3.0 sources_manager/FileFormat#Deb822#,
349 /// Legacy format (one-line style)
350 Legacyrust-analyzer cargo apt-sources 0.3.0 sources_manager/FileFormat#Legacy#,
351 }
352
353 /// Check if two repositories match (have the same URIs, suites, and components)
354 fn repos_matchrust-analyzer cargo apt-sources 0.3.0 sources_manager/repos_match().(repo1: &Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#, repo2: &Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#) -> bool {
355 // Compare types
356 if repo1.typesrust-analyzer cargo apt-sources 0.3.0 Repository#types. 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().repo2.typesrust-analyzer cargo apt-sources 0.3.0 Repository#types. {
357 return false;
358 }
359
360 // Compare URIs
361 let uris1: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<_> = repo1.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().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
362 let uris2: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<_> = repo2.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().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
363 if uris1 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().uris2 {
364 return false;
365 }
366
367 // Compare suites
368 let suites1: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<_> = repo1.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().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
369 let suites2: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<_> = repo2.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().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
370 if suites1 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().suites2 {
371 return false;
372 }
373
374 // Compare components
375 let components1: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<_> = repo1.componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
376 let components2: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<_> = repo2.componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
377 if components1 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().components2 {
378 return false;
379 }
380
381 true
382 }
383
384 #[cfg(test)]
385 mod testsrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/ {
386 use superrust-analyzer cargo apt-sources 0.3.0 sources_manager/::*;
387 use tempfilerust-analyzer cargo tempfile 3.27.0 crate/::TempDirrust-analyzer cargo tempfile 3.27.0 dir/TempDir#;
388 use urlrust-analyzer cargo url 2.5.8 crate/::Urlrust-analyzer cargo url 2.5.8 Url#;
389
390 fn create_test_managerrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_manager().() -> (SourcesManagerrust-analyzer cargo apt-sources 0.3.0 sources_manager/SourcesManager#, TempDirrust-analyzer cargo tempfile 3.27.0 dir/TempDir#) {
391 let temp_dir = TempDirrust-analyzer cargo tempfile 3.27.0 dir/TempDir#::newrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]new().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
392 let sources_dir = temp_dir.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("sources.list.d");
393 let keyring_dir = temp_dir.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("trusted.gpg.d");
394
395 let 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().(&sources_dir, &keyring_dir);
396 (manager, temp_dir)
397 }
398
399 fn create_test_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_repository().() -> Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository# {
400 Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository# {
401 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),
402 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#]),
403 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/ubuntu").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()],
404 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().()],
405 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().()]),
406 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().()]),
407 ..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().()
408 }
409 }
410
411 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
412 fn test_ensure_directoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/test_ensure_directories().() {
413 let (manager, _temp_dir) = create_test_managerrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_manager().();
414
415 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().manager.sources_dirrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]sources_dir().().existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().());
416 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().manager.keyring_dirrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]keyring_dir().().existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().());
417
418 manager.ensure_directoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]ensure_directories().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
419
420 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(manager.sources_dirrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]sources_dir().().existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().());
421 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(manager.keyring_dirrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]keyring_dir().().existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().());
422 }
423
424 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
425 fn test_generate_filenamerust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/test_generate_filename().() {
426 let (manager, _) = create_test_managerrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_manager().();
427
428 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
429 manager.generate_filenamerust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]generate_filename().("test-repo", FileFormatrust-analyzer cargo apt-sources 0.3.0 sources_manager/FileFormat#::Deb822rust-analyzer cargo apt-sources 0.3.0 sources_manager/FileFormat#Deb822#),
430 "test-repo.sources"
431 );
432
433 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
434 manager.generate_filenamerust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]generate_filename().("Test/Repo:Name", FileFormatrust-analyzer cargo apt-sources 0.3.0 sources_manager/FileFormat#::Legacyrust-analyzer cargo apt-sources 0.3.0 sources_manager/FileFormat#Legacy#),
435 "test-repo-name.list"
436 );
437 }
438
439 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
440 fn test_add_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/test_add_repository().() {
441 let (manager, _) = create_test_managerrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_manager().();
442 manager.ensure_directoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]ensure_directories().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
443
444 let repo = create_test_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_repository().();
445
446 // Add repository
447 manager.add_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]add_repository().(&repo, "test.sources").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
448
449 // Verify it was added
450 let path = manager.get_repository_pathrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]get_repository_path().("test.sources");
451 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(path.existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().());
452
453 let repos = manager.read_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]read_repositories().(&path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
454 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(repos.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1);
455 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(repos[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..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()..as_strrust-analyzer cargo url 2.5.8 impl#[Url]as_str().(), "http://example.com/ubuntu");
456
457 // Try to add duplicate - should fail
458 let result = manager.add_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]add_repository().(&repo, "test2.sources");
459 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().());
460 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(result.unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("already exists"));
461 }
462
463 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
464 fn test_remove_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/test_remove_repository().() {
465 let (manager, _) = create_test_managerrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_manager().();
466 manager.ensure_directoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]ensure_directories().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
467
468 let repo = create_test_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_repository().();
469
470 // Add repository
471 manager.add_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]add_repository().(&repo, "test.sources").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
472
473 // Remove it
474 let removed = manager.remove_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]remove_repository().(&repo).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
475 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(removed);
476
477 // Verify file was removed
478 let path = manager.get_repository_pathrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]get_repository_path().("test.sources");
479 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().path.existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().());
480
481 // Try to remove again - should return false
482 let removed = manager.remove_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]remove_repository().(&repo).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
483 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().removed);
484 }
485
486 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
487 fn test_set_repository_enabledrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/test_set_repository_enabled().() {
488 let (manager, _) = create_test_managerrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_manager().();
489 manager.ensure_directoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]ensure_directories().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
490
491 let mut repo = create_test_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_repository().();
492 repo.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);
493
494 // Add repository
495 manager.add_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]add_repository().(&repo, "test.sources").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
496
497 // Disable it
498 let modified = manager.set_repository_enabledrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]set_repository_enabled().(&repo, false).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
499 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(modified);
500
501 // Verify it was disabled
502 let path = manager.get_repository_pathrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]get_repository_path().("test.sources");
503 let repos = manager.read_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]read_repositories().(&path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
504 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(repos[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..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#(false));
505
506 // Enable it again
507 let modified = manager.set_repository_enabledrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]set_repository_enabled().(&repo, true).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
508 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(modified);
509
510 // Verify it was enabled
511 let repos = manager.read_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]read_repositories().(&path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
512 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(repos[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..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));
513 }
514
515 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
516 fn test_add_component_to_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/test_add_component_to_repositories().() {
517 let (manager, _) = create_test_managerrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_manager().();
518 manager.ensure_directoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]ensure_directories().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
519
520 let repo = create_test_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_repository().();
521
522 // Add repository
523 manager.add_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]add_repository().(&repo, "test.sources").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
524
525 // Add component to repositories from example.com
526 let count = manager
527 .add_component_to_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]add_component_to_repositories().("universe", |r| {
528 r.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().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]any().(|u| u.host_strrust-analyzer cargo url 2.5.8 impl#[Url]host_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#("example.com"))
529 })
530 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
531 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(count, 1);
532
533 // Verify component was added
534 let path = manager.get_repository_pathrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]get_repository_path().("test.sources");
535 let repos = manager.read_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]read_repositories().(&path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
536 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(repos[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().
537 .componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components.
538 .as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().()
539 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()
540 .containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&"universe".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
541
542 // Try to add same component again - should not modify
543 let count = manager
544 .add_component_to_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]add_component_to_repositories().("universe", |r| {
545 r.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().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]any().(|u| u.host_strrust-analyzer cargo url 2.5.8 impl#[Url]host_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#("example.com"))
546 })
547 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
548 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(count, 0);
549 }
550
551 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
552 fn test_enable_source_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/test_enable_source_repositories().() {
553 let (manager, _) = create_test_managerrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_manager().();
554 manager.ensure_directoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]ensure_directories().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
555
556 let repo = create_test_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_repository().();
557
558 // Add repository
559 manager.add_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]add_repository().(&repo, "test.sources").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
560
561 // Enable source repositories (create if missing)
562 let (enabled, created) = manager.enable_source_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]enable_source_repositories().(true).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
563 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(enabled, 0);
564 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(created, 1);
565
566 // Verify source repo was created
567 let path = manager.get_repository_pathrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]get_repository_path().("test.sources");
568 let repos = manager.read_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]read_repositories().(&path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
569 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(repos.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2);
570
571 // Find the source repo
572 let source_repo = repos
573 .iterrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]iter().()
574 .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]find().(|r| r.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#))
575 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
576 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(source_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#));
577 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().source_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#));
578 }
579
580 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
581 fn test_list_repository_filesrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/test_list_repository_files().() {
582 let (manager, _) = create_test_managerrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_manager().();
583 manager.ensure_directoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]ensure_directories().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
584
585 // Initially empty
586 let files = manager.list_repository_filesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]list_repository_files().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
587 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(files.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 0);
588
589 // Add some files
590 let repo1 = create_test_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_repository().();
591 let mut repo2 = create_test_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_repository().();
592 repo2.suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites. = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["jammy".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()]; // Make it different
593 manager.add_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]add_repository().(&repo1, "test1.sources").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
594 manager.add_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]add_repository().(&repo2, "test2.list").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
595
596 // Should find both files
597 let files = manager.list_repository_filesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]list_repository_files().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
598 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(files.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2);
599
600 // Create a non-repository file
601 let non_repo = manager.get_repository_pathrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]get_repository_path().("test.txt");
602 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().(&non_repo, "not a repo").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
603
604 // Should still only find 2 repository files
605 let files = manager.list_repository_filesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]list_repository_files().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
606 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(files.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2);
607 }
608
609 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
610 fn test_scan_all_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/test_scan_all_repositories().() {
611 let (manager, _) = create_test_managerrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_manager().();
612 manager.ensure_directoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]ensure_directories().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
613
614 let repo1 = create_test_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_repository().();
615 let mut repo2 = create_test_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_repository().();
616 repo2.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://example2.com/ubuntu").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()];
617
618 // Add repositories to different files
619 manager.add_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]add_repository().(&repo1, "test1.sources").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
620 manager.add_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]add_repository().(&repo2, "test2.sources").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
621
622 // Scan all
623 let all_repos = manager.scan_all_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]scan_all_repositories().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
624 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(all_repos.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2);
625
626 // Each file should have one repository
627 for (_, repos) in all_repos {
628 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(repos.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1);
629 }
630 }
631
632 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
633 fn test_repository_existsrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/test_repository_exists().() {
634 let (manager, _) = create_test_managerrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_manager().();
635 manager.ensure_directoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]ensure_directories().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
636
637 let repo = create_test_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_repository().();
638
639 // Should not exist initially
640 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(manager.repository_existsrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]repository_exists().(&repo).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().());
641
642 // Add repository
643 manager.add_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]add_repository().(&repo, "test.sources").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
644
645 // Should exist now
646 let existing_path = manager.repository_existsrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]repository_exists().(&repo).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
647 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(existing_path.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().());
648 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(existing_path.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().ends_withrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]ends_with().("test.sources"));
649 }
650
651 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
652 fn test_save_keyrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/test_save_key().() {
653 let (manager, _) = create_test_managerrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_manager().();
654 manager.ensure_directoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]ensure_directories().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
655
656 let key_data =
657 b"-----BEGIN PGP PUBLIC KEY BLOCK-----\ntest key\n-----END PGP PUBLIC KEY BLOCK-----";
658
659 let key_path = manager.save_keyrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]save_key().(key_data, "test.gpg").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
660 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(key_path.existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().());
661 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(key_path.file_namerust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]file_name().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), "test.gpg");
662
663 let saved_data = fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read().(&key_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
664 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(saved_data, key_data);
665 }
666
667 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
668 fn test_repos_matchrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/test_repos_match().() {
669 let repo1 = create_test_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_repository().();
670 let mut repo2 = repo1.clonerust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Clone]clone().();
671
672 // Should match identical repos
673 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(repos_matchrust-analyzer cargo apt-sources 0.3.0 sources_manager/repos_match().(&repo1, &repo2));
674
675 // Different types
676 repo2.typesrust-analyzer cargo apt-sources 0.3.0 Repository#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#);
677 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().repos_matchrust-analyzer cargo apt-sources 0.3.0 sources_manager/repos_match().(&repo1, &repo2));
678 repo2.typesrust-analyzer cargo apt-sources 0.3.0 Repository#types. = repo1.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().();
679
680 // Different URIs
681 repo2.urisrust-analyzer cargo apt-sources 0.3.0 Repository#uris..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().("http://extra.com").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().());
682 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().repos_matchrust-analyzer cargo apt-sources 0.3.0 sources_manager/repos_match().(&repo1, &repo2));
683 repo2.urisrust-analyzer cargo apt-sources 0.3.0 Repository#uris. = repo1.urisrust-analyzer cargo apt-sources 0.3.0 Repository#uris..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Clone]clone().();
684
685 // Different suites
686 repo2.suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().("bionic".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
687 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().repos_matchrust-analyzer cargo apt-sources 0.3.0 sources_manager/repos_match().(&repo1, &repo2));
688 repo2.suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites. = repo1.suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Clone]clone().();
689
690 // Different components
691 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref mut components) = repo2.componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components. {
692 components.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().("universe".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
693 }
694 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().repos_matchrust-analyzer cargo apt-sources 0.3.0 sources_manager/repos_match().(&repo1, &repo2));
695 }
696
697 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
698 fn test_generate_keyring_filenamerust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/test_generate_keyring_filename().() {
699 let (manager, _) = create_test_managerrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_manager().();
700
701 // Test basic filename
702 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
703 manager.generate_keyring_filenamerust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]generate_keyring_filename().("test-repo"),
704 "test-repo.gpg"
705 );
706
707 // Test with special characters that should be sanitized
708 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
709 manager.generate_keyring_filenamerust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]generate_keyring_filename().("Test/Repo:Name With Spaces"),
710 "test-repo-name-with-spaces.gpg"
711 );
712
713 // Test empty string
714 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(manager.generate_keyring_filenamerust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]generate_keyring_filename().(""), ".gpg");
715 }
716
717 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
718 fn test_list_all_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/test_list_all_repositories().() {
719 let (manager, _) = create_test_managerrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_manager().();
720 manager.ensure_directoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]ensure_directories().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
721
722 // Initially empty
723 let all_repos = manager.list_all_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]list_all_repositories().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
724 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(all_repos.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().());
725
726 // Add some repositories
727 let repo1 = create_test_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_repository().();
728 let mut repo2 = create_test_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_repository().();
729 repo2.suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites. = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["jammy".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()];
730
731 manager.add_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]add_repository().(&repo1, "test1.sources").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
732 manager.add_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]add_repository().(&repo2, "test2.sources").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
733
734 // Should list all repositories with their paths
735 let all_repos = manager.list_all_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]list_all_repositories().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
736 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(all_repos.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2);
737
738 // Check that paths are included
739 let paths: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = all_repos
740 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
741 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(p, _)| p.file_namerust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]file_name().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().())
742 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
743 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(paths.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]new().("test1.sources")));
744 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(paths.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]new().("test2.sources")));
745 }
746
747 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
748 fn test_enable_source_repositories_counter_edge_casesrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/test_enable_source_repositories_counter_edge_cases().() {
749 let (manager, _) = create_test_managerrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_manager().();
750 manager.ensure_directoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]ensure_directories().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
751
752 // Add a binary repository
753 let mut repo = create_test_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_repository().();
754 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#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary#]);
755 manager.add_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]add_repository().(&repo, "test.sources").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
756
757 // Enable source repositories with creation
758 let (enabled, created) = manager.enable_source_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]enable_source_repositories().(true).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
759 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(enabled, 0);
760 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(created, 1);
761
762 // Check that source repo was actually created
763 let all_repos = manager.list_all_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]list_all_repositories().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
764 let source_repos: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = all_repos
765 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
766 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|(_, r)| {
767 r.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#)
768 && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().r.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#)
769 })
770 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
771 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(source_repos.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1);
772
773 // Add a disabled binary repository
774 let mut disabled_repo = create_test_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_repository().();
775 disabled_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#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary#]);
776 disabled_repo.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#(false);
777 disabled_repo.suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites. = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["jammy".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()]; // Make it different
778 manager
779 .add_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]add_repository().(&disabled_repo, "test2.sources")
780 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
781
782 // Enable source repositories again
783 // The first binary repo will create another source repo
784 // The disabled binary repo will have source type added and be enabled
785 let (enabled2, created2) = manager.enable_source_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]enable_source_repositories().(true).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
786 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(enabled2, 1); // Should enable the disabled binary repo
787 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(created2, 1); // Will create a source repo for the new binary repo
788 }
789
790 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
791 fn test_set_repository_enabled_edge_casesrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/test_set_repository_enabled_edge_cases().() {
792 let (manager, _) = create_test_managerrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_manager().();
793 manager.ensure_directoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]ensure_directories().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
794
795 let mut repo = create_test_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_repository().();
796 repo.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);
797
798 // Add repository
799 manager.add_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]add_repository().(&repo, "test.sources").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
800
801 // Try to enable already enabled repo - should return false
802 let modified = manager.set_repository_enabledrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]set_repository_enabled().(&repo, true).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
803 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().modified);
804
805 // Disable it
806 let modified = manager.set_repository_enabledrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]set_repository_enabled().(&repo, false).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
807 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(modified);
808
809 // Try to disable already disabled repo - should return false
810 let modified = manager.set_repository_enabledrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]set_repository_enabled().(&repo, false).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
811 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().modified);
812 }
813
814 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
815 fn test_add_component_edge_casesrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/test_add_component_edge_cases().() {
816 let (manager, _) = create_test_managerrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_manager().();
817 manager.ensure_directoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]ensure_directories().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
818
819 let mut repo = create_test_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_repository().();
820 repo.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().()]);
821
822 manager.add_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]add_repository().(&repo, "test.sources").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
823
824 // Add component that already exists - should not increment counter
825 let count = manager
826 .add_component_to_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]add_component_to_repositories().("main", |_| true)
827 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
828 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(count, 0);
829
830 // Add new component
831 let count = manager
832 .add_component_to_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]add_component_to_repositories().("universe", |_| true)
833 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
834 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(count, 1);
835
836 // Add to repo with no components initially
837 let mut repo2 = create_test_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/tests/create_test_repository().();
838 repo2.componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components. = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
839 manager.add_repositoryrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]add_repository().(&repo2, "test2.sources").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
840
841 let count = manager
842 .add_component_to_repositoriesrust-analyzer cargo apt-sources 0.3.0 sources_manager/impl#[SourcesManager]add_component_to_repositories().("restricted", |r| r.componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().())
843 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
844 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(count, 1);
845 }
846 }