Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ rusoto_core = "0.40"
rusoto_credential = "0.40"
futures = "0.1"
tokio = "0.1"
systemstat = "0.1.4"

# iron dependencies
iron = "0.5"
Expand Down
2 changes: 1 addition & 1 deletion src/db/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub fn get_path(conn: &Connection, path: &str) -> Option<Blob> {

let res = match res {
Ok(r) => r,
Err(err) => {
Err(_) => {
return None;
}
};
Expand Down
38 changes: 36 additions & 2 deletions src/docbuilder/chroot_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ use db::{connect_db, add_package_into_database, add_build_into_database, add_pat
use cargo::core::Package;
use cargo::util::CargoResultExt;
use std::process::Command;
use std::path::PathBuf;
use std::fs::remove_dir_all;
use std::path::{Path, PathBuf};
use std::fs::{self, remove_dir_all};
use postgres::Connection;
use rustc_serialize::json::{Json, ToJson};
use error::Result;
use systemstat::{Platform, Filesystem, System};

const MAX_DISK_USAGE: f32 = 80.0;

/// List of targets supported by docs.rs
const TARGETS: [&'static str; 6] = [
Expand Down Expand Up @@ -237,6 +239,20 @@ impl DocBuilder {
.join("doc");
let _ = remove_dir_all(crate_doc_path);
}

let crate_build_path = PathBuf::from(&self.options.chroot_path)
.join("home")
.join(&self.options.chroot_user)
.join("cratesfyi");
let fs = mount_for_path(&crate_build_path);
let disk_usage = 100.0 - 100.0 * (fs.free.as_usize() as f32 / fs.total.as_usize() as f32);
if disk_usage >= MAX_DISK_USAGE {
info!("Cleaning target directory, disk usage {:.2} exceeded {:.2}",
disk_usage, MAX_DISK_USAGE);
let _ = remove_dir_all(&crate_build_path);
let _ = fs::create_dir_all(&crate_build_path);
}

Ok(())
}

Expand Down Expand Up @@ -466,6 +482,24 @@ fn crates<F>(path: PathBuf, mut func: F) -> Result<()>
crates_from_path(&path, &mut func)
}

fn mount_for_path(path: &Path) -> Filesystem {
let system = System::new();

let mut found = None;
let mut found_pos = std::usize::MAX;
for mount in system.mounts().expect("get all mounts").into_iter() {
let mount_path = Path::new(&mount.fs_mounted_on);
for (i, ancestor) in path.ancestors().enumerate() {
if ancestor == mount_path && i < found_pos {
found_pos = i;
found = Some(mount);
break;
}
}
}
found.expect("on a disk mount")
}


#[cfg(test)]
mod test {
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ extern crate rusoto_core;
extern crate rusoto_credential;
extern crate futures;
extern crate tokio;
extern crate systemstat;

pub use self::docbuilder::DocBuilder;
pub use self::docbuilder::ChrootBuilderResult;
Expand Down