2013-07-11 18:20:31 -07:00
|
|
|
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
// Listing installed packages
|
|
|
|
|
|
|
|
use path_util::*;
|
|
|
|
use std::os;
|
|
|
|
|
|
|
|
pub fn list_installed_packages(f: &fn(&PkgId) -> bool) -> bool {
|
|
|
|
let workspaces = rust_path();
|
2013-08-03 12:45:23 -04:00
|
|
|
for p in workspaces.iter() {
|
2013-07-11 18:20:31 -07:00
|
|
|
let binfiles = os::list_dir(&p.push("bin"));
|
2013-08-03 12:45:23 -04:00
|
|
|
for exec in binfiles.iter() {
|
2013-06-26 17:42:24 -07:00
|
|
|
let exec_path = Path(*exec).filestem();
|
|
|
|
do exec_path.iter().advance |s| {
|
|
|
|
f(&PkgId::new(*s, p))
|
|
|
|
};
|
2013-07-11 18:20:31 -07:00
|
|
|
}
|
|
|
|
let libfiles = os::list_dir(&p.push("lib"));
|
2013-08-03 12:45:23 -04:00
|
|
|
for lib in libfiles.iter() {
|
2013-06-26 17:42:24 -07:00
|
|
|
debug!("Full name: %s", *lib);
|
|
|
|
let lib_path = Path(*lib).filestem();
|
|
|
|
do lib_path.iter().advance |s| {
|
|
|
|
f(&PkgId::new(*s, p))
|
|
|
|
};
|
2013-07-11 18:20:31 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn package_is_installed(p: &PkgId) -> bool {
|
|
|
|
let mut is_installed = false;
|
2013-07-13 13:38:07 -07:00
|
|
|
do list_installed_packages() |installed| {
|
2013-07-11 18:20:31 -07:00
|
|
|
if installed == p {
|
|
|
|
is_installed = true;
|
|
|
|
}
|
|
|
|
false
|
|
|
|
};
|
|
|
|
is_installed
|
|
|
|
}
|