|
|
@ -2,7 +2,8 @@ use regex::Regex; |
|
|
|
use std::error::Error;
|
|
|
|
use std::fmt;
|
|
|
|
use std::fs::File as FsFile;
|
|
|
|
use std::io::Read;
|
|
|
|
use std::io;
|
|
|
|
use std::io::{BufRead, BufReader};
|
|
|
|
use std::ops::Deref;
|
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
|
|
|
@ -36,19 +37,31 @@ impl<'a, C, R> Symbol for WordpressPlugin<'a, C, R> where C: Deref<Target=str> + |
|
|
|
return Ok(false);
|
|
|
|
}
|
|
|
|
let path = self.get_path().join(self.name.to_string() + ".php");
|
|
|
|
let mut file = try!(FsFile::open(path));
|
|
|
|
let mut file_content = String::new();
|
|
|
|
try!(file.read_to_string(&mut file_content));
|
|
|
|
let mut version = String::new();
|
|
|
|
let mut plugin_uri = String::new();
|
|
|
|
let regex = try!(Regex::new("(?m)^(Plugin URI|Version): (.+)$"));
|
|
|
|
for matches in regex.captures_iter(&file_content) {
|
|
|
|
match FsFile::open(path) {
|
|
|
|
Err(e) => {
|
|
|
|
// Check if file exists
|
|
|
|
return if e.kind() == io::ErrorKind::NotFound {
|
|
|
|
Ok(false)
|
|
|
|
} else {
|
|
|
|
Err(Box::new(e))
|
|
|
|
};
|
|
|
|
},
|
|
|
|
Ok(file) => {
|
|
|
|
let mut reader = BufReader::new(file);
|
|
|
|
let regex = Regex::new("(?m)^(Plugin URI|Version): (.+)$")?;
|
|
|
|
for content in reader.lines() {
|
|
|
|
for matches in regex.captures_iter(&(content?)) {
|
|
|
|
if &matches[1] == "Plugin URI" {
|
|
|
|
plugin_uri = matches[2].to_string();
|
|
|
|
} else {
|
|
|
|
version = matches[2].to_string();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let upstream = try!(self.command_runner.get_output("curl", &["--form", &format!(r###"plugins={{"plugins":{{"{0}/{0}.php":{{"Version":"{1}", "PluginURI":"{2}"}}}}}}"###, self.name, version, plugin_uri), "https://api.wordpress.org/plugins/update-check/1.1/"]));
|
|
|
|
Ok(try!(String::from_utf8(upstream)).contains(r###""plugins":[]"###))
|
|
|
|
}
|
|
|
|