Browse Source

Code style

master
Adrian Heine 6 years ago
parent
commit
2230a702a4
  1. 3
      src/lib.rs
  2. 2
      src/schema.rs
  3. 2
      src/symbols/acme/account_key.rs
  4. 1
      src/symbols/acme/user.rs
  5. 1
      src/symbols/user.rs
  6. 25
      src/symbols/wordpress/plugin.rs
  7. 20
      src/symbols/wordpress/translation.rs

3
src/lib.rs

@ -1,7 +1,6 @@
// rustfmt // rustfmt
#![deny(fat_ptr_transmutes,
trivial_numeric_casts, unsafe_code,
#![deny(trivial_numeric_casts, unsafe_code,
unstable_features, unused_extern_crates, unstable_features, unused_extern_crates,
unused_import_braces, unused_qualifications, unused_import_braces, unused_qualifications,
variant_size_differences variant_size_differences

2
src/schema.rs

@ -139,7 +139,7 @@ impl<R: SymbolRunner> SymbolRunner for NonRepeatingSymbolRunner<R> {
for resource in resources { for resource in resources {
if !done.contains(&resource) { if !done.contains(&resource) {
has_to_run = true; has_to_run = true;
done.insert(resource.clone());
assert!(done.insert(resource.clone()));
} }
} }
if !has_to_run { if !has_to_run {

2
src/symbols/acme/account_key.rs

@ -1,4 +1,4 @@
use std::borrow::{Borrow, Cow};
use std::borrow::Cow;
use std::error::Error; use std::error::Error;
use std::fmt; use std::fmt;
use std::path::Path; use std::path::Path;

1
src/symbols/acme/user.rs

@ -10,7 +10,6 @@ use symbols::{Action, OwnedSymbolAction, SymbolAction, SymbolRunner, Symbol};
use symbols::acme::AcmeAccountKey; use symbols::acme::AcmeAccountKey;
use symbols::dir::Dir; use symbols::dir::Dir;
use symbols::file::File; use symbols::file::File;
use symbols::hook::Hook;
use symbols::list::List; use symbols::list::List;
use symbols::owner::Owner; use symbols::owner::Owner;

1
src/symbols/user.rs

@ -1,7 +1,6 @@
use std::borrow::Cow; use std::borrow::Cow;
use std::error::Error; use std::error::Error;
use std::fmt; use std::fmt;
use std::io::Error as IoError;
use command_runner::CommandRunner; use command_runner::CommandRunner;
use resources::Resource; use resources::Resource;

25
src/symbols/wordpress/plugin.rs

@ -2,7 +2,8 @@ use regex::Regex;
use std::error::Error; use std::error::Error;
use std::fmt; use std::fmt;
use std::fs::File as FsFile; use std::fs::File as FsFile;
use std::io::Read;
use std::io;
use std::io::{BufRead, BufReader};
use std::ops::Deref; use std::ops::Deref;
use std::path::{Path, PathBuf}; 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); return Ok(false);
} }
let path = self.get_path().join(self.name.to_string() + ".php"); 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 version = String::new();
let mut plugin_uri = 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" { if &matches[1] == "Plugin URI" {
plugin_uri = matches[2].to_string(); plugin_uri = matches[2].to_string();
} else { } else {
version = matches[2].to_string(); 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/"])); 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":[]"###)) Ok(try!(String::from_utf8(upstream)).contains(r###""plugins":[]"###))
} }

20
src/symbols/wordpress/translation.rs

@ -4,7 +4,7 @@ use std::error::Error;
use std::fmt; use std::fmt;
use std::fs::File as FsFile; use std::fs::File as FsFile;
use std::io; use std::io;
use std::io::Read;
use std::io::{BufRead, BufReader};
use std::path::Path; use std::path::Path;
use command_runner::CommandRunner; use command_runner::CommandRunner;
@ -52,20 +52,24 @@ impl<'a, C, D, R> Symbol for WordpressTranslation<'a, C, D, R> where C: AsRef<st
let mut newest = String::new(); let mut newest = String::new();
let match_date = Regex::new("(?m)^\"PO-Revision-Date: (.+)\\+0000\\\\n\"$").unwrap(); let match_date = Regex::new("(?m)^\"PO-Revision-Date: (.+)\\+0000\\\\n\"$").unwrap();
for (_, target) in self.get_pairs() { for (_, target) in self.get_pairs() {
let file = FsFile::open(target.clone());
match FsFile::open(target.clone()) {
Err(e) => {
// Check if file exists // Check if file exists
if let Err(e) = file {
return if e.kind() == io::ErrorKind::NotFound { return if e.kind() == io::ErrorKind::NotFound {
Ok(false) Ok(false)
} else { } else {
Err(Box::new(e)) Err(Box::new(e))
}; };
},
Ok(mut file) => if target.ends_with(".po") {
let mut reader = BufReader::new(file);
for content in reader.lines() {
if let Some(match_result) = match_date.captures(&try!(content)) {
newest = max(newest, match_result[1].to_string());
break;
}
}
} }
if target.ends_with(".po") {
let mut content = String::new();
try!(file.unwrap().read_to_string(&mut content));
let file_date = &match_date.captures(&content).unwrap()[1];
newest = max(newest, file_date.to_string());
} }
} }
let upstream = try!(self.command_runner.get_output("curl", &[&format!("https://api.wordpress.org/core/version-check/1.7/?version={}&locale={}", self.version, self.locale)])); let upstream = try!(self.command_runner.get_output("curl", &[&format!("https://api.wordpress.org/core/version-check/1.7/?version={}&locale={}", self.version, self.locale)]));

Loading…
Cancel
Save