Skip to content

Commit

Permalink
Update repository and find the latest index
Browse files Browse the repository at this point in the history
Ref: #6
  • Loading branch information
nabijaczleweli committed Nov 3, 2016
1 parent 63934d1 commit aa090b4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cargo-install-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Only updates packages from the main repository.

Exit values and possible errors:

-1 - cargo install process was terminated by a signal (Linux-only)
-1 - cargo subprocess was terminated by a signal (Linux-only)
1 - option parsing error
X - bubbled-up cargo install exit value

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
//! Exit values and possible errors:
//!
//! ```text
//! -1 - cargo install process was terminated by a signal (Linux-only)
//! -1 - cargo subprocess was terminated by a signal (Linux-only)
//! 1 - option parsing error
//! X - bubbled-up cargo install exit value
//! ```
Expand Down
10 changes: 10 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ fn actual_main() -> Result<(), i32> {
packages = cargo_update::ops::intersect_packages(packages, &opts.to_update);
}

{
// Searching for "" will just update the registry
let search_res = Command::new("cargo").arg("search").arg("").status().unwrap();
if !search_res.success() {
try!(Err(search_res.code().unwrap_or(-1)));
}
}

println!("Latest registry: {:?}", cargo_update::ops::get_index_path(&opts.cargo_dir.1));

for package in &mut packages {
package.pull_version();
}
Expand Down
14 changes: 12 additions & 2 deletions src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@


use hyper::Client as HttpClient;
use std::path::{PathBuf, Path};
use semver::Version as Semver;
use std::path::Path;
use std::fs::File;
use std::fs::{self, File};
use std::io::Read;
use regex::Regex;
use toml;
Expand Down Expand Up @@ -229,3 +229,13 @@ pub fn crate_versions_raw(crate_name: &str) -> String {
pub fn crate_versions(raw: &str) -> Vec<Semver> {
json::parse(raw).unwrap()["versions"].members().map(|v| Semver::parse(v["num"].as_str().unwrap()).unwrap()).collect()
}

pub fn get_index_path(cargo_dir: &Path) -> PathBuf {
fs::read_dir(cargo_dir.join("registry").join("index"))
.unwrap()
.map(Result::unwrap)
.filter(|i| i.file_type().unwrap().is_dir())
.max_by_key(|i| i.metadata().unwrap().modified().unwrap())
.unwrap()
.path()
}

0 comments on commit aa090b4

Please sign in to comment.