commit 8228310f282d85b72bc5df0201c4d4737cb7b038
parent 7b1e7e5feaaf2b63e5bff5d015a7c0ae4d0d506c
Author: lash <dev@holbrook.no>
Date:   Tue, 26 Jul 2022 07:28:02 +0000
Add recursive import, rehabilitate scan
Diffstat:
4 files changed, 57 insertions(+), 31 deletions(-)
diff --git a/src/main.rs b/src/main.rs
@@ -135,7 +135,6 @@ fn exec_import_xattr(f: &Path, index_path: &Path) -> bool {
     let m = MetaData::from_xattr(f);
     match m.typ() {
         EntryType::Unknown(v) => {
-            debug!("vvv {}", v);
             return false;
         },
         _ => {},
@@ -189,7 +188,7 @@ fn exec_import_biblatex(f: &Path, index_path: &Path) -> bool {
     true
 }
 
-fn exec_scan(p: &Path, index_path: &Path) {
+fn exec_scan(p: &Path, index_path: &Path) -> bool {
     for entry in WalkDir::new(&p)
         .into_iter()
         .filter_map(Result::ok)
@@ -209,7 +208,28 @@ fn exec_scan(p: &Path, index_path: &Path) {
                 Err(e) => {
                     debug!("metadata not found for {:?} -> {:?}", entry, z_hex);
                 },
-            }
+            };
+    }
+    true
+}
+
+fn exec_import(p: &Path, index_path: &Path) {
+    for entry in WalkDir::new(&p)
+        .into_iter()
+        .filter_map(Result::ok)
+        .filter(|e| !e.file_type().is_dir()) {
+
+        let fp = entry.path();
+        debug!("processing {:?}", fp);
+        if exec_import_xattr(fp, index_path) {
+            continue;
+        }
+        if exec_import_rdf(fp, index_path) {
+            continue;
+        } 
+        if exec_import_biblatex(fp, index_path) {
+            continue;
+        }
     }
 }
 
@@ -224,25 +244,20 @@ fn main() {
     match args.subcommand_matches("import") {
         Some(v) => {
             let p = str_to_path(v);
-            info!("have path {:?}", &p);
-            if exec_import_xattr(p.as_path(), index_dir.as_path()) {
-                return;
-            }
-            if exec_import_rdf(p.as_path(), index_dir.as_path()) {
-                return;
-            }
-            if exec_import_biblatex(p.as_path(), index_dir.as_path()) {
-                return;
-            }
+            info!("import from path {:?}", &p);
+            return exec_import(&p, index_dir.as_path());
         },
         _ => {},
     }
 
+    let mut r = true;
     match args.subcommand_matches("scan") {
         Some(v) => {
             let p = str_to_path(v);
-            info!("have path {:?}", &p);
-            return exec_scan(p.as_path(), index_dir.as_path());
+            info!("scan from path {:?}", &p);
+            if !exec_scan(p.as_path(), index_dir.as_path()) {
+                r = false; 
+            }
         },
         _ => {},
     }
diff --git a/src/rdf.rs b/src/rdf.rs
@@ -121,7 +121,7 @@ fn handle_parse_match(metadata: &mut MetaData, triple: Triple) -> Result<(), Rdf
     let l = subject_iri.len()-1;
     //let subject = &subject_iri[1..l];
     let subject = &subject_iri[1..l];
-    match &subject[0..4] {
+    match subject[0..4].to_lowercase().as_str() {
         "urn:"  => {},
         _ => {
             return Err(RdfError::UrnError(UrnError::InvalidNid));
@@ -226,7 +226,12 @@ pub fn read(r: impl Read) -> MetaData {
     let r: Result<_, TurtleError> = tp.parse_all(&mut |r| {
         match r {
             Triple{subject, predicate, object } => {
-                handle_parse_match(&mut metadata, r);
+                match handle_parse_match(&mut metadata, r) {
+                    Err(e) => {
+                        error!("error parsing rdf source: {:?}", e);
+                    },
+                    _ => {},
+                };
             },
             _ => {},
         }
diff --git a/testdata/meta.biblatex b/testdata/meta.biblatex
@@ -6,12 +6,18 @@
 	language = "en",
 	note = "sha512:2ac531ee521cf93f8419c2018f770fbb42c65396178e079a416e7038d3f9ab9fc2c35c4d838bc8b5dd68f4c13759fe9cdf90a46528412fefe1294cb26beabf4e",
 }
-@inproceedings{
-	decentralizedmarketplace_smartcities,
-	author = "Gowri Sankar Ramachandran, Rahul Radhakrishnan and Bhaskar Krishnamachari",
-	title = "Towards a Decentralized Data Marketplace for Smart Cities",
-	booktitle = "IEEE International Smart Cities Conference",
-	month = sep,
-	year = 2018,
-	note = "sha512:f450b0b35ed8bd1c00b45b4f6ebd645079ae8bf3b8abd28aea62fc2ab3bab2878e021e0b6c182f776e24e5ed956c204d647b4c5b0f64a73e3753f736ffe2818c",
+
+@techreport{
+	kenya_dataprotectionact,
+	title = "The Data Protection Act, 2019",
+	author = "Government of Kenya",
+	year = 2019,
+	month = nov,
+	booktitle = "Kenya Gazette Supplement, ACTS 2019",
+	publisher = "The Government Printer, Nairobi",
+	note = "sha256:7d76e977bbc0b5ca652c058e62be2baf04d2b2106424ff76c7a2b71bff803301",
+	url = "http://kenyalaw.org/kl/fileadmin/pdfdownloads/Acts/2019/TheDataProtectionAct__No24of2019.pdf",
+	urldate = "2022-02-17",
+	pages = "901--948",
+	note = "sha512:9136bb8c656f0ac208b1802ee23980c3b761ef4153c09f723c4724c841c048c159ee61be8222d202b698b718768b3d4931046e977f4e858dc46ae9d2d8ac4afa",
 }
diff --git a/testdata/meta.ttl b/testdata/meta.ttl
@@ -1,13 +1,13 @@
 @prefix dcterms: <https://purl.org/dc/terms/> .
 @prefix dcmi: <https://purl.org/dc/dcmi/> .
 
-<urn:sha512:2ac531ee521cf93f8419c2018f770fbb42c65396178e079a416e7038d3f9ab9fc2c35c4d838bc8b5dd68f4c13759fe9cdf90a46528412fefe1294cb26beabf4e>
-	dcterms:title "Bitcoin: A Peer-to-Peer Electronic Cash System" ;
-	dcterms:subject "bitcoin,cryptocurrency,cryptography" ;
-	dcterms:creator "Satoshi Nakamoto" ;
-	dcterms:type "article" ;
+<urn:sha256:9d57da39b0c06dd9cbc9244fa0b948ee4841a9520ccc5e21aaf318242cc4de07>
+	dcterms:title "Blockchain and the General Data Protection Regulation" ;
+	dcterms:subject "blockchain,regulation,government" ;
+	dcterms:creator "European Parliamentary Research Service, Scientific Foresight Unit (STOA)" ;
+	dcterms:type "techreport" ;
 	dcterms:MediaType "application/pdf" ;
-	dcterms:language "en-US" .
+	dcterms:language "en" .
 
 <urn:sha512:f450b0b35ed8bd1c00b45b4f6ebd645079ae8bf3b8abd28aea62fc2ab3bab2878e021e0b6c182f776e24e5ed956c204d647b4c5b0f64a73e3753f736ffe2818c>
 	dcterms:title "Towards a Decentralized Data Marketplace for Smart Cities";