Browse Source

Fix a few sync and logging bugs.

Thomas Kerber 6 months ago
parent
commit
ad7a28c3e8
Signed by: Thomas Kerber <t.kerber@ed.ac.uk> GPG Key ID: 8489B911F9ED617B
10 changed files with 976 additions and 997 deletions
  1. 161
    160
      Cargo.lock
  2. 783
    804
      Cargo.nix
  3. 4
    4
      Cargo.toml
  4. 4
    2
      default.nix
  5. 1
    1
      goblin-core/Cargo.toml
  6. 1
    1
      goblin-core/src/state.rs
  7. 5
    0
      hydra.nix
  8. 6
    4
      src/cfg.rs
  9. 11
    20
      src/log.rs
  10. 0
    1
      src/main.rs

+ 161
- 160
Cargo.lock
File diff suppressed because it is too large
View File


+ 783
- 804
Cargo.nix
File diff suppressed because it is too large
View File


+ 4
- 4
Cargo.toml View File

@@ -1,6 +1,6 @@
1 1
 [package]
2 2
 name = "goblin"
3
-version = "0.3.3"
3
+version = "0.3.4"
4 4
 authors = ["Thomas Kerber <tk@drwx.org>"]
5 5
 description = "Version controlled password management."
6 6
 publish = false
@@ -13,8 +13,8 @@ weak-scrypt = ["goblin-core/weak-scrypt"]
13 13
 clap = "2.26"
14 14
 clipboard = "0.4.4"
15 15
 getch = "0.2"
16
-goblin-core = {path="goblin-core"}
17
-log = "0.3"
16
+goblin-core = { path = "goblin-core" }
17
+log = { version = "0.4", features = ["release_max_level_info"] }
18 18
 rand = "0.3"
19 19
 rpassword = "1.0"
20 20
 term = "0.4"
@@ -22,4 +22,4 @@ atty = "0.2"
22 22
 serde = "1.0"
23 23
 serde_json = "1.0"
24 24
 chrono = "0.4"
25
-ssh2 = {version="0.3", optional=true}
25
+ssh2 = { version = "0.3", optional = true }

+ 4
- 2
default.nix View File

@@ -1,6 +1,8 @@
1
-with import <nixpkgs> { };
1
+{ nixpkgs ? import <nixpkgs> }:
2
+
3
+with nixpkgs { };
4
+
2 5
 ((callPackage ./Cargo.nix { }).goblin { }).override {
3
-  release = false;
4 6
   crateOverrides = defaultCrateOverrides // {
5 7
     libgpg-error-sys = attrs: {
6 8
       postFixup = ''

+ 1
- 1
goblin-core/Cargo.toml View File

@@ -1,6 +1,6 @@
1 1
 [package]
2 2
 name = "goblin-core"
3
-version = "0.3.3"
3
+version = "0.3.4"
4 4
 authors = ["Thomas Kerber <tk@drwx.org>"]
5 5
 publish = false
6 6
 

+ 1
- 1
goblin-core/src/state.rs View File

@@ -790,7 +790,7 @@ impl Merge {
790 790
         'outer: for (i, h) in hashes.iter().enumerate() {
791 791
             for h2 in hashes.iter() {
792 792
                 if h == h2 {
793
-                    continue 'outer;
793
+                    continue;
794 794
                 }
795 795
                 let mut seen = HashSet::new();
796 796
                 seen.insert(*h2);

+ 5
- 0
hydra.nix View File

@@ -0,0 +1,5 @@
1
+{ nixpkgs ? import <nixpkgs> }:
2
+
3
+{
4
+  goblin = import ./. { inherit nixpkgs; };
5
+}

+ 6
- 4
src/cfg.rs View File

@@ -2,7 +2,8 @@ use atty;
2 2
 use clap::ArgMatches;
3 3
 use err::{Error, Result};
4 4
 use goblin_core::{VaultLocation, ZeroBox};
5
-use log;
5
+use log::Logger;
6
+use log_crate;
6 7
 use rpassword::prompt_password_stdout;
7 8
 use std::env::var_os;
8 9
 use std::ffi::{OsStr, OsString};
@@ -35,8 +36,9 @@ impl Config {
35 36
                 None
36 37
             },
37 38
         };
38
-        log::Builder({
39
-            use LogLevelFilter::*;
39
+        log_crate::set_logger(&Logger).expect("Logger initialization failed!");
40
+        log_crate::set_max_level({
41
+            use log_crate::LevelFilter::*;
40 42
             match cfg.verbosity {
41 43
                 i if i <= -2 => Off,
42 44
                 -1 => Error,
@@ -45,7 +47,7 @@ impl Config {
45 47
                 2 => Debug,
46 48
                 _ => Trace,
47 49
             }
48
-        }).init();
50
+        });
49 51
         Ok(cfg)
50 52
     }
51 53
 

+ 11
- 20
src/log.rs View File

@@ -1,23 +1,11 @@
1
-use log_crate::{Log, LogLevel, LogLevelFilter, LogMetadata, LogRecord,
2
-                MaxLogLevelFilter, set_logger};
3
-use log_crate::LogLevel::*;
1
+use log_crate::{Log, Level, Metadata, Record};
2
+use log_crate::Level::*;
4 3
 use std::io::Write;
5 4
 use term::{BRIGHT_BLACK, BRIGHT_RED, Bold, RED, Term, WHITE};
6 5
 
7
-pub struct Builder(pub LogLevelFilter);
6
+pub struct Logger;
8 7
 
9
-impl Builder {
10
-    pub fn init(self) {
11
-        set_logger(|f| {
12
-            f.set(self.0);
13
-            Box::new(Logger(f))
14
-        }).expect("failed to initialize logging");
15
-    }
16
-}
17
-
18
-struct Logger(MaxLogLevelFilter);
19
-
20
-fn level_color<O: Write>(term: &mut Term<O>, level: LogLevel) {
8
+fn level_color<O: Write>(term: &mut Term<O>, level: Level) {
21 9
     match level {
22 10
         Error => {
23 11
             term.fg(BRIGHT_RED);
@@ -38,12 +26,11 @@ fn level_color<O: Write>(term: &mut Term<O>, level: LogLevel) {
38 26
 }
39 27
 
40 28
 impl Log for Logger {
41
-    fn enabled(&self, metadata: &LogMetadata) -> bool {
42
-        return metadata.level() <= self.0.get() &&
43
-            metadata.target().starts_with("goblin");
29
+    fn enabled(&self, metadata: &Metadata) -> bool {
30
+        return metadata.target().starts_with("goblin");
44 31
     }
45 32
 
46
-    fn log(&self, record: &LogRecord) {
33
+    fn log(&self, record: &Record) {
47 34
         if !self.enabled(record.metadata()) {
48 35
             return;
49 36
         }
@@ -67,4 +54,8 @@ impl Log for Logger {
67 54
             eprintln!(" {}", record.args());
68 55
         }
69 56
     }
57
+
58
+    fn flush(&self) {
59
+        Term::stderr().flush();
60
+    }
70 61
 }

+ 0
- 1
src/main.rs View File

@@ -23,7 +23,6 @@ mod args;
23 23
 
24 24
 use clap::ArgMatches;
25 25
 use err::Result;
26
-use log_crate::LogLevelFilter;
27 26
 use std::collections::HashMap;
28 27
 use std::process::exit;
29 28
 

Loading…
Cancel
Save