1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
use std::path::Path;

const MIRROR: &'static str = "http://archlinux.polymorf.fr/$repo/os/$arch";

/// The options that can be set in the pacman conf file.
pub struct Options {
    /// The root directory of the instance. Packages are installed relative to here.
    pub root_dir: String,
    /// The location of the synced databases.
    pub db_path: String,
    /// The location of the cache directory.
    pub cache_dir: String,
    /// The location of the log file.
    pub log_file: String,
    /// The location of the gpg directory.
    pub gpg_dir: String,
    pub hook_dir: String,
    pub hold_pkg: Vec<String>,
    //pub XferCommand
    //pub clean_method: TODO,
    //pub use_delta: TODO,
    //pub architecture: TODO,
    pub ignore_pkg: Vec<String>,
    pub ignore_group: Vec<String>,
    pub no_upgrade: Vec<String>,
    pub no_extract: Vec<String>,
    pub use_syslog: bool,
    pub color: bool,
    pub total_download: bool,
    pub check_space: bool,
    pub verbose_pkg_lists: bool,
    //pub sig_level: TODO,
    //pub local_files_sig_level: TODO,
    //pub remote_files_sig_level: TODO,
    pub repositories: Vec<RepoOptions>,
}

impl Options {
    /// Reads a pacman-style ini file and returns an Options instance to match
    ///
    /// TODO will only be implemented after I've finished the rest of the lib
    pub fn from_ini(loc: &Path) -> Option<Options> {
        unimplemented!()
    }
}


impl Default for Options {
    fn default() -> Options {
        Options {
            root_dir: "/".into(),
            db_path: "/var/lib/pacman/".into(),
            cache_dir: "/var/cache/pacman/pkg/".into(),
            log_file: "/var/log/pacman.log".into(),
            gpg_dir: "/etc/pacman.d/gnupg/".into(),
            hook_dir: "/etc/pacman.d/hooks/".into(),
            hold_pkg: vec!["pacman".into(), "glibc".into()],
            // xfer_command
            //clean_method
            //use_delta: TODO,
            //architecture: TODO,
            ignore_pkg: vec![],
            ignore_group: vec![],
            no_upgrade: vec![],
            no_extract: vec![],
            use_syslog: false,
            color: false,
            total_download: false,
            check_space: true,
            verbose_pkg_lists: false,
            //sig_level: TODO,
            //local_files_sig_level: TODO,
            //remote_files_sig_level: TODO,
            repositories: vec![
                RepoOptions::new("core", vec![MIRROR.into()]),
                RepoOptions::new("extra", vec![MIRROR.into()]),
                RepoOptions::new("community", vec![MIRROR.into()]),
                RepoOptions::new("multilib", vec![MIRROR.into()]),
            ],
        }
    }

}

/// Options for a repository.
pub struct RepoOptions {
    /// The name of the repository.
    pub name: String,
    /// A vector containing urls for the repository's mirrors.
    pub servers: Vec<String>
}

impl RepoOptions {
    fn new<Name: Into<String>>(name: Name, servers: Vec<String>) -> RepoOptions {
        RepoOptions { name: name.into(), servers: servers }
    }
}