<commit_before>use std::fs::{rename, set_permissions, Permissions};
use std::os::unix::fs::{PermissionsExt, symlink};
use std::fs::File;
use std::io::{BufRead, BufReader, Write};
use std::path::{Path, PathBuf};

use quire::validate as V;
use container::util::clean_dir;
use super::super::context::{Context};
use super::super::download::download_file;
use super::super::commands::tarcmd::unpack_file;
use super::super::packages;
use builder::commands::generic::{command, run};
use shaman::sha2::Sha256;
use shaman::digest::Digest as ShamanDigest;
use builder::distrib::{Distribution, Named, DistroBox};
use unshare::Stdio;
use file_util::copy;
use build_step::{BuildStep, VersionError, StepError, Digest, Config, Guard};

const DEFAULT_MIRROR: &'static str = "http://archive.ubuntu.com/ubuntu/";

// Build Steps
#[derive(Debug)]
pub struct Ubuntu(String);
tuple_struct_decode!(Ubuntu);

impl Ubuntu {
    pub fn config() -> V::Scalar {
        V::Scalar::new()
    }
}

#[derive(RustcDecodable, Debug)]
pub struct UbuntuRelease {
    pub version: String,
    pub arch: String,
    pub keep_chfn_command: bool,
}

impl UbuntuRelease {
    pub fn config() -> V::Structure<'static> {
        V::Structure::new()
        .member("version", V::Scalar::new())
        .member("arch", V::Scalar::new().default("amd64"))
        .member("keep_chfn_command", V::Scalar::new().default(false))
    }
}

#[derive(Debug, RustcDecodable)]
pub struct UbuntuUniverse;

impl UbuntuUniverse {
    pub fn config() -> V::Nothing {
        V::Nothing
    }
}

#[derive(Debug)]
pub struct UbuntuPPA(String);
tuple_struct_decode!(UbuntuPPA);

impl UbuntuPPA {
    pub fn config() -> V::Scalar {
        V::Scalar::new()
    }
}

#[derive(RustcDecodable, Debug)]
pub struct UbuntuRepo {
    pub url: String,
    pub suite: String,
    pub components: Vec<String>,
}

impl UbuntuRepo {
    pub fn config() -> V::Structure<'static> {
        V::Structure::new()
        .member("url", V::Scalar::new())
        .member("suite", V::Scalar::new())
        .member("components", V::Sequence::new(V::Scalar::new()))
    }
}

#[derive(RustcDecodable, Debug)]
pub struct AptTrust {
    pub server: Option<String>,
    pub keys: Vec<String>,
}

impl AptTrust {
    pub fn config() -> V::Structure<'static> {
        V::Structure::new()
        .member("server", V::Scalar::new().optional())
        .member("keys", V::Sequence::new(V::Scalar::new()))
    }
}

#[derive(Debug)]
pub enum Version {
    Daily { codename: String },
    Release { version: String },
}

#[derive(Debug)]
pub struct Distro {
    version: Version,
    codename: Option<String>,
    arch: String,
    apt_update: bool,
    has_universe: bool,
    clobber_chfn: bool,
}

impl Named for Distro {
    fn static_name() -> &'static str { "ubuntu" }
}

impl Distribution for Distro {
    fn name(&self) -> &'static str { "Ubuntu" }
    fn bootstrap(&mut self, ctx: &mut Context) -> Result<(), StepError> {
        try!(fetch_ubuntu_core(ctx, &self.version, self.arch.clone()));
        let codename = try!(read_ubuntu_codename());
        if self.codename.is_some() && self.codename.as_ref() != Some(&codename) {
            return Err(From::from("Codename mismatch. \
                This is either bug of vagga or may be damaged archive"));
        }
        ctx.binary_ident = format!("{}-ubuntu-{}",
            ctx.binary_ident, codename);
        try!(init_ubuntu_core(ctx));
        if self.clobber_chfn {
            try!(clobber_chfn());
        }
        Ok(())
    }
    fn install(&mut self, ctx: &mut Context, pkgs: &[String])
        -> Result<(), StepError>
    {
        if self.apt_update {
            self.apt_update = false;
            let mut cmd = try!(command(ctx, "apt-get"));
            cmd.arg("update");
            try!(run(cmd)
                .map_err(|error| {
                    debug!("The apt-get update failed. \
                        Cleaning apt-lists so that apt can proceed next time");
                    clean_dir(&Path::new("/vagga/cache/apt-lists"), false)
                        .map_err(|e| error!(
                            "Cleaning apt-lists cache failed: {}", e)).ok();
                    error
                }));
        }
        let mut cmd = try!(command(ctx, "apt-get"));
        cmd.arg("install");<commit_msg>Add a warning on failed apt-get update (fixes #242)<commit_after>use std::fs::{rename, set_permissions, Permissions};
use std::os::unix::fs::{PermissionsExt, symlink};
use std::fs::File;
use std::io::{BufRead, BufReader, Write};
use std::path::{Path, PathBuf};

use quire::validate as V;
use container::util::clean_dir;
use super::super::context::{Context};
use super::super::download::download_file;
use super::super::commands::tarcmd::unpack_file;
use super::super::packages;
use builder::commands::generic::{command, run};
use shaman::sha2::Sha256;
use shaman::digest::Digest as ShamanDigest;
use builder::distrib::{Distribution, Named, DistroBox};
use unshare::Stdio;
use file_util::copy;
use build_step::{BuildStep, VersionError, StepError, Digest, Config, Guard};

const DEFAULT_MIRROR: &'static str = "http://archive.ubuntu.com/ubuntu/";

// Build Steps
#[derive(Debug)]
pub struct Ubuntu(String);
tuple_struct_decode!(Ubuntu);

impl Ubuntu {
    pub fn config() -> V::Scalar {
        V::Scalar::new()
    }
}

#[derive(RustcDecodable, Debug)]
pub struct UbuntuRelease {
    pub version: String,
    pub arch: String,
    pub keep_chfn_command: bool,
}

impl UbuntuRelease {
    pub fn config() -> V::Structure<'static> {
        V::Structure::new()
        .member("version", V::Scalar::new())
        .member("arch", V::Scalar::new().default("amd64"))
        .member("keep_chfn_command", V::Scalar::new().default(false))
    }
}

#[derive(Debug, RustcDecodable)]
pub struct UbuntuUniverse;

impl UbuntuUniverse {
    pub fn config() -> V::Nothing {
        V::Nothing
    }
}

#[derive(Debug)]
pub struct UbuntuPPA(String);
tuple_struct_decode!(UbuntuPPA);

impl UbuntuPPA {
    pub fn config() -> V::Scalar {
        V::Scalar::new()
    }
}

#[derive(RustcDecodable, Debug)]
pub struct UbuntuRepo {
    pub url: String,
    pub suite: String,
    pub components: Vec<String>,
}

impl UbuntuRepo {
    pub fn config() -> V::Structure<'static> {
        V::Structure::new()
        .member("url", V::Scalar::new())
        .member("suite", V::Scalar::new())
        .member("components", V::Sequence::new(V::Scalar::new()))
    }
}

#[derive(RustcDecodable, Debug)]
pub struct AptTrust {
    pub server: Option<String>,
    pub keys: Vec<String>,
}

impl AptTrust {
    pub fn config() -> V::Structure<'static> {
        V::Structure::new()
        .member("server", V::Scalar::new().optional())
        .member("keys", V::Sequence::new(V::Scalar::new()))
    }
}

#[derive(Debug)]
pub enum Version {
    Daily { codename: String },
    Release { version: String },
}

#[derive(Debug)]
pub struct Distro {
    version: Version,
    codename: Option<String>,
    arch: String,
    apt_update: bool,
    has_universe: bool,
    clobber_chfn: bool,
}

impl Named for Distro {
    fn static_name() -> &'static str { "ubuntu" }
}

impl Distribution for Distro {
    fn name(&self) -> &'static str { "Ubuntu" }
    fn bootstrap(&mut self, ctx: &mut Context) -> Result<(), StepError> {
        try!(fetch_ubuntu_core(ctx, &self.version, self.arch.clone()));
        let codename = try!(read_ubuntu_codename());
        if self.codename.is_some() && self.codename.as_ref() != Some(&codename) {
            return Err(From::from("Codename mismatch. \
                This is either bug of vagga or may be damaged archive"));
        }
        ctx.binary_ident = format!("{}-ubuntu-{}",
            ctx.binary_ident, codename);
        try!(init_ubuntu_core(ctx));
        if self.clobber_chfn {
            try!(clobber_chfn());
        }
        Ok(())
    }
    fn install(&mut self, ctx: &mut Context, pkgs: &[String])
        -> Result<(), StepError>
    {
        if self.apt_update {
            self.apt_update = false;
            let mut cmd = try!(command(ctx, "apt-get"));
            cmd.arg("update");
            try!(run(cmd)
                .map_err(|error| {
                    debug!("The apt-get update failed. \
                        Cleaning apt-lists so that apt can proceed next time");
                    clean_dir(&Path::new("/vagga/cache/apt-lists"), false)
                        .map_err(|e| error!(
                            "Cleaning apt-lists cache failed: {}", e)).ok();
                    if ctx.settings.ubuntu_mirror.is_none() {
                        warn!("The `apt-get update` failed. You have no mirror\
                           setup, and default one is not always perfect.\n\
                           Add the following to your ~/.vagga.yaml:\
                           \n  ubuntu-mirror: http://CC.archive.ubuntu.com/ubuntu\n\
                           Where CC is a two-letter country code where you currently are.\
                           ");
                    } else {
                        warn!("The `apt-get update` failed. \
                            If this happens too often, consider changing \
                            the `ubuntu-mirror` in settings");
                    }
                    error
                }));
        }
        let mut cmd = try!(command(ctx, "apt-get"));
        cmd.arg("install");
{'fraction_non_alphanumeric': 0.1593833067517278, 'fraction_numerical': 0.001594896331738437, 'mean_word_length': 2.634466769706337, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5807110', 'n_tokens_mistral': 3011, 'n_tokens_neox': 2920, 'n_words': 679}