File src/backend/check.rs changed (mode: 100644) (index 6885a45..08d2bca) |
1 |
1 |
extern crate serde_json; |
extern crate serde_json; |
2 |
2 |
|
|
3 |
|
use std::io::{Result, Error, ErrorKind, Write}; |
|
|
3 |
|
use std::io::{Result, Error, ErrorKind}; |
4 |
4 |
|
|
5 |
5 |
pub fn dep(config: String) -> Result<String> { |
pub fn dep(config: String) -> Result<String> { |
6 |
6 |
let config_json: serde_json::Value; |
let config_json: serde_json::Value; |
|
... |
... |
pub fn dep(config: String) -> Result<String> { |
37 |
37 |
} |
} |
38 |
38 |
} |
} |
39 |
39 |
|
|
40 |
|
pkg_check(config_json) |
|
|
40 |
|
config_check(config_json) |
41 |
41 |
} |
} |
42 |
42 |
|
|
43 |
43 |
#[cfg(target_os="linux")] |
#[cfg(target_os="linux")] |
44 |
|
fn pkg_check(config: serde_json::Value) -> Result<String> { |
|
|
44 |
|
fn config_check(config: serde_json::Value) -> Result<String> { |
45 |
45 |
match config["deps"]["linux"] { |
match config["deps"]["linux"] { |
46 |
46 |
json!(null) => return Ok(String::from("No dependencies found!")), |
json!(null) => return Ok(String::from("No dependencies found!")), |
47 |
47 |
ref deps => { |
ref deps => { |
48 |
48 |
if !deps.is_object() { |
if !deps.is_object() { |
49 |
49 |
return Err(Error::new(ErrorKind::InvalidData, "beheer.json: 'deps->linux' should be an object.")); |
return Err(Error::new(ErrorKind::InvalidData, "beheer.json: 'deps->linux' should be an object.")); |
50 |
50 |
} |
} |
|
51 |
|
|
51 |
52 |
for dep in deps.as_object().unwrap().iter() { |
for dep in deps.as_object().unwrap().iter() { |
|
53 |
|
|
52 |
54 |
if !dep.1.is_string() { |
if !dep.1.is_string() { |
53 |
55 |
return Err(Error::new(ErrorKind::InvalidData, "beheer.json: all deps should be strings!")); |
return Err(Error::new(ErrorKind::InvalidData, "beheer.json: all deps should be strings!")); |
54 |
56 |
} |
} |
|
57 |
|
|
55 |
58 |
println!("Checking for {}..\n\t{}", dep.0, dep.1); |
println!("Checking for {}..\n\t{}", dep.0, dep.1); |
56 |
|
super::fetch::fetch(dep.0.to_string(), String::from(dep.1.as_str().unwrap())); |
|
|
59 |
|
|
|
60 |
|
match dir_check(dep.0.to_string(), String::from(dep.1.as_str().unwrap())) { |
|
61 |
|
Ok(_) => {}, |
|
62 |
|
Err(e) => return Err(e) |
|
63 |
|
} |
57 |
64 |
} |
} |
58 |
65 |
} |
} |
59 |
66 |
} |
} |
|
... |
... |
fn pkg_check(config: serde_json::Value) -> Result<String> { |
61 |
68 |
} |
} |
62 |
69 |
|
|
63 |
70 |
#[cfg(target_os="macos")] |
#[cfg(target_os="macos")] |
64 |
|
fn pkg_check(config: serde_json::Value) -> Result<String> { |
|
|
71 |
|
fn config_check(config: serde_json::Value) -> Result<String> { |
65 |
72 |
match config["deps"]["os-x"] { |
match config["deps"]["os-x"] { |
66 |
73 |
json!(null) => return Ok(String::from("No dependencies found!")), |
json!(null) => return Ok(String::from("No dependencies found!")), |
67 |
74 |
ref sys_deps => { |
ref sys_deps => { |
68 |
75 |
if !sys_deps.is_object() { |
if !sys_deps.is_object() { |
69 |
76 |
return Err(Error::new(ErrorKind::InvalidData, "beheer.json: 'deps->os-x' should be an object.")); |
return Err(Error::new(ErrorKind::InvalidData, "beheer.json: 'deps->os-x' should be an object.")); |
70 |
77 |
} |
} |
71 |
|
for dep in sys_deps.as_object().unwrap().iter() { |
|
|
78 |
|
|
|
79 |
|
for dep in deps.as_object().unwrap().iter() { |
|
80 |
|
|
72 |
81 |
if !dep.1.is_string() { |
if !dep.1.is_string() { |
73 |
82 |
return Err(Error::new(ErrorKind::InvalidData, "beheer.json: all deps should be strings!")); |
return Err(Error::new(ErrorKind::InvalidData, "beheer.json: all deps should be strings!")); |
74 |
83 |
} |
} |
75 |
|
println!("Checking for {} version {}..", dep.0, dep.1); |
|
|
84 |
|
|
|
85 |
|
println!("Checking for {}..\n\t{}", dep.0, dep.1); |
|
86 |
|
|
|
87 |
|
if dir_check(dep.0.to_string(), String::from(dep.1.as_str().unwrap())) == Err(e) { |
|
88 |
|
return Err(e); |
|
89 |
|
} |
76 |
90 |
} |
} |
77 |
91 |
} |
} |
78 |
92 |
} |
} |
|
... |
... |
fn pkg_check(config: serde_json::Value) -> Result<String> { |
80 |
94 |
} |
} |
81 |
95 |
|
|
82 |
96 |
#[cfg(target_os="windows")] |
#[cfg(target_os="windows")] |
83 |
|
fn pkg_check(config: serde_json::Value) -> Result<String> { |
|
|
97 |
|
fn config_check(config: serde_json::Value) -> Result<String> { |
84 |
98 |
match config["deps"]["windows"] { |
match config["deps"]["windows"] { |
85 |
99 |
json!(null) => return Ok(String::from("No dependencies found!")), |
json!(null) => return Ok(String::from("No dependencies found!")), |
86 |
100 |
ref sys_deps => { |
ref sys_deps => { |
87 |
101 |
if !sys_deps.is_object() { |
if !sys_deps.is_object() { |
88 |
102 |
return Err(Error::new(ErrorKind::InvalidData, "beheer.json: 'deps->windows' should be an object.")); |
return Err(Error::new(ErrorKind::InvalidData, "beheer.json: 'deps->windows' should be an object.")); |
89 |
103 |
} |
} |
90 |
|
for dep in sys_deps.as_object().unwrap().iter() { |
|
|
104 |
|
|
|
105 |
|
for dep in deps.as_object().unwrap().iter() { |
91 |
106 |
if !dep.1.is_string() { |
if !dep.1.is_string() { |
92 |
107 |
return Err(Error::new(ErrorKind::InvalidData, "beheer.json: all deps should be strings!")); |
return Err(Error::new(ErrorKind::InvalidData, "beheer.json: all deps should be strings!")); |
93 |
108 |
} |
} |
94 |
|
println!("Checking for {} version {}..", dep.0, dep.1); |
|
|
109 |
|
|
|
110 |
|
println!("Checking for {}..\n\t{}", dep.0, dep.1); |
|
111 |
|
|
|
112 |
|
if dir_check(dep.0.to_string(), String::from(dep.1.as_str().unwrap())) == Err(e) { |
|
113 |
|
return Err(e); |
|
114 |
|
} |
95 |
115 |
} |
} |
96 |
116 |
} |
} |
97 |
117 |
} |
} |
98 |
118 |
Ok(String::from("Dependencies OK!")) |
Ok(String::from("Dependencies OK!")) |
99 |
119 |
} |
} |
|
120 |
|
|
|
121 |
|
fn dir_check(dependency: String, command: String) -> Result<()> { |
|
122 |
|
let dir = super::filesystem::get_dep_dir(); |
|
123 |
|
|
|
124 |
|
match dir { |
|
125 |
|
Ok(mut dep_dir) => { |
|
126 |
|
dep_dir.push(dependency); |
|
127 |
|
if !dep_dir.is_dir() { |
|
128 |
|
dep_dir.pop(); |
|
129 |
|
super::fetch::fetch(dep_dir, command); |
|
130 |
|
} |
|
131 |
|
Ok(()) |
|
132 |
|
}, |
|
133 |
|
Err(e) => Err(e) |
|
134 |
|
} |
|
135 |
|
} |