|
1 | 1 | use crate::background_jobs::{Environment, Job, NormalizeIndexJob};
|
2 | 2 | use crate::models;
|
3 |
| -use crate::schema; |
4 | 3 | use crate::swirl::PerformError;
|
5 | 4 | use anyhow::Context;
|
6 | 5 | use cargo_registry_index::{Crate, Repository};
|
@@ -157,66 +156,6 @@ pub fn get_index_data(name: &str, conn: &mut PgConnection) -> anyhow::Result<Opt
|
157 | 156 | Ok(Some(str))
|
158 | 157 | }
|
159 | 158 |
|
160 |
| -/// Yanks or unyanks a crate version. This requires finding the index |
161 |
| -/// file, deserlialise the crate from JSON, change the yank boolean to |
162 |
| -/// `true` or `false`, write all the lines back out, and commit and |
163 |
| -/// push the changes. |
164 |
| -#[instrument(skip(env, conn))] |
165 |
| -pub fn perform_index_update_yanked( |
166 |
| - env: &Environment, |
167 |
| - conn: &mut PgConnection, |
168 |
| - krate: &str, |
169 |
| - version_num: &str, |
170 |
| -) -> Result<(), PerformError> { |
171 |
| - info!("Syncing yanked status from database into the index"); |
172 |
| - |
173 |
| - debug!("Loading yanked status from database"); |
174 |
| - |
175 |
| - let yanked: bool = schema::versions::table |
176 |
| - .inner_join(schema::crates::table) |
177 |
| - .filter(schema::crates::name.eq(&krate)) |
178 |
| - .filter(schema::versions::num.eq(&version_num)) |
179 |
| - .select(schema::versions::yanked) |
180 |
| - .get_result(conn) |
181 |
| - .context("Failed to load yanked status from database")?; |
182 |
| - |
183 |
| - debug!(yanked); |
184 |
| - |
185 |
| - let repo = env.lock_index()?; |
186 |
| - let dst = repo.index_file(krate); |
187 |
| - |
188 |
| - let prev = fs::read_to_string(&dst)?; |
189 |
| - let new = prev |
190 |
| - .lines() |
191 |
| - .map(|line| { |
192 |
| - let mut git_crate = serde_json::from_str::<Crate>(line) |
193 |
| - .map_err(|_| format!("couldn't decode: `{line}`"))?; |
194 |
| - if git_crate.name != krate || git_crate.vers != version_num { |
195 |
| - return Ok(line.to_string()); |
196 |
| - } |
197 |
| - git_crate.yanked = Some(yanked); |
198 |
| - Ok(serde_json::to_string(&git_crate)?) |
199 |
| - }) |
200 |
| - .collect::<Result<Vec<_>, PerformError>>(); |
201 |
| - let new = new?.join("\n") + "\n"; |
202 |
| - |
203 |
| - if new != prev { |
204 |
| - fs::write(&dst, new.as_bytes())?; |
205 |
| - |
206 |
| - let action = if yanked { "Yank" } else { "Unyank" }; |
207 |
| - let message = format!("{action} crate `{krate}#{version_num}`"); |
208 |
| - |
209 |
| - repo.commit_and_push(&message, &dst)?; |
210 |
| - } else { |
211 |
| - debug!("Skipping `yanked` update because index is up-to-date"); |
212 |
| - } |
213 |
| - |
214 |
| - // Queue another background job to update the http-based index as well. |
215 |
| - Job::update_crate_index(krate.to_string()).enqueue(conn)?; |
216 |
| - |
217 |
| - Ok(()) |
218 |
| -} |
219 |
| - |
220 | 159 | /// Collapse the index into a single commit, archiving the current history in a snapshot branch.
|
221 | 160 | #[instrument(skip(env))]
|
222 | 161 | pub fn perform_index_squash(env: &Environment) -> Result<(), PerformError> {
|
|
0 commit comments