-
Notifications
You must be signed in to change notification settings - Fork 599
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
2,838 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use crate::admin::dialoguer; | ||
use cargo_registry_index::{Repository, RepositoryConfig}; | ||
use reqwest::blocking::Client; | ||
|
||
use crate::config; | ||
|
||
#[derive(clap::Parser, Debug)] | ||
#[clap( | ||
name = "upload-index", | ||
about = "Upload index from git to S3 (http-based index)" | ||
)] | ||
pub struct Opts { | ||
/// Incremental commit. Any changed files made after this commit will be uploaded. | ||
incremental_commit: Option<String>, | ||
} | ||
|
||
pub fn run(opts: Opts) -> anyhow::Result<()> { | ||
let config = config::Base::from_environment(); | ||
let uploader = config.uploader(); | ||
let client = Client::new(); | ||
|
||
println!("fetching git repo"); | ||
let config = RepositoryConfig::from_environment(); | ||
let repo = Repository::open(&config)?; | ||
repo.reset_head()?; | ||
println!("HEAD is at {}", repo.head_oid()?); | ||
|
||
let files = repo.get_files_modified_since(opts.incremental_commit.as_deref())?; | ||
println!("found {} files to upload", files.len()); | ||
if !dialoguer::confirm("continue with upload?") { | ||
return Ok(()); | ||
} | ||
|
||
for file in files { | ||
let crate_name = file.file_name().unwrap().to_str().unwrap(); | ||
let path = repo.index_file(crate_name); | ||
if !path.exists() { | ||
println!("skipping file `{}`", crate_name); | ||
continue; | ||
} | ||
let contents = std::fs::read_to_string(&path)?; | ||
uploader.upload_index(&client, crate_name, contents)?; | ||
} | ||
|
||
println!( | ||
"uploading completed; use `upload-index {}` for an incremental run", | ||
repo.head_oid()? | ||
); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.