diff --git a/.gitignore b/.gitignore index 072503d71cc75fc0b7999844dcaf741f3affecfc..6b20e9f07016526024bb5a53257785edc45ec418 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ native/artifacts.json *.wot build/ + +\.vscode/ diff --git a/lib/index.ts b/lib/index.ts index ba7465d973949e11d01965002acb0d3575fe4664..a59971e83cb54b3a75ee5fe88ece71a097e99a62 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -114,7 +114,7 @@ export class MemoryWebOfTrust implements WebOfTrust { } resetWoT(): void { - + this.wot = new NativeWebOfTrust(this.wot.getMaxCert()) } } @@ -123,8 +123,10 @@ export class AtomicFileWebOfTrust implements WebOfTrust { filePath: String; constructor (path: String) { + console.log("before") this.wot = new NativeWebOfTrust(path); this.filePath = path; + console.log("after") } toFile(path: String): Boolean { @@ -217,6 +219,8 @@ export class AtomicFileWebOfTrust implements WebOfTrust { } resetWoT(): void { - + this.wot = new NativeWebOfTrust(this.wot.getMaxCert()) } -} \ No newline at end of file +} + +var test = new AtomicFileWebOfTrust("test.wot"); \ No newline at end of file diff --git a/native/src/lib.rs b/native/src/lib.rs index 9403a50aed9fba53c23e2b3b1a56ddad836fb574..61476e3b1235f43bb0406629b1430e8097ff21d0 100644 --- a/native/src/lib.rs +++ b/native/src/lib.rs @@ -4,7 +4,10 @@ extern crate neon; extern crate duniter_rs_wotb; -use neon::js::{Value, JsInteger, JsString, JsBoolean, JsFunction, JsArray, JsNumber, JsObject, Object}; +use std::path::Path; + +use neon::js::{Value, JsInteger, JsString, JsBoolean, JsFunction, JsArray, JsNumber, JsObject, + Object}; use neon::js::class::{Class, JsClass}; use neon::mem::Handle; use neon::vm::{Throw, Lock}; @@ -29,10 +32,16 @@ declare_types! { } else if let Some(path) = arg0.downcast::<JsString>() { let path = path.value(); - match WebOfTrust::from_file(path.as_str()) { - Some(wot) => Ok(wot), - None => Err(Throw), - } + if !Path::new(&path).exists() { + let wot = WebOfTrust::new(0); + wot.to_file(&path); + Ok(wot) + } else { + match WebOfTrust::from_file(path.as_str()) { + Some(wot) => Ok(wot), + None => Err(Throw), + } + } } else { Err(Throw) } diff --git a/tests/test.js b/tests/test.js index 1e99c7349659b1fd2f061568c38796c551ffadc2..165c4b7e8f18d0afebd6f6acf0c1641713294b55 100644 --- a/tests/test.js +++ b/tests/test.js @@ -6,7 +6,7 @@ var assert = require('assert'); var path = require('path'); var fs = require('fs'); -const FILE = path.join(__dirname, 'wot.bin'); +const FILE = path.join(__dirname, 'wot.wot'); const X_PERCENT = 1.0; const _100_PERCENT = 1.0; const MAX_DISTANCE_1 = 1;