Make tags unique before writing
This commit is contained in:
parent
9f8a648600
commit
2e2c6e19fa
3 changed files with 6 additions and 2 deletions
|
@ -8,6 +8,7 @@ clap = "2.1.1"
|
||||||
log = "0.3.5"
|
log = "0.3.5"
|
||||||
regex = "0.1.47"
|
regex = "0.1.47"
|
||||||
toml = "0.1.25"
|
toml = "0.1.25"
|
||||||
|
itertools = "0.4.7"
|
||||||
|
|
||||||
[dependencies.libimagstore]
|
[dependencies.libimagstore]
|
||||||
path = "../libimagstore"
|
path = "../libimagstore"
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
extern crate clap;
|
extern crate clap;
|
||||||
|
extern crate itertools;
|
||||||
#[macro_use] extern crate log;
|
#[macro_use] extern crate log;
|
||||||
extern crate regex;
|
extern crate regex;
|
||||||
extern crate toml;
|
extern crate toml;
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::ops::DerefMut;
|
use std::ops::DerefMut;
|
||||||
|
|
||||||
|
use itertools::Itertools;
|
||||||
|
|
||||||
use libimagstore::store::{Entry, EntryHeader, FileLockEntry};
|
use libimagstore::store::{Entry, EntryHeader, FileLockEntry};
|
||||||
|
|
||||||
use error::{TagError, TagErrorKind};
|
use error::{TagError, TagErrorKind};
|
||||||
|
@ -66,7 +68,7 @@ impl Tagable for EntryHeader {
|
||||||
return Err(TagError::new(TagErrorKind::NotATag, None));
|
return Err(TagError::new(TagErrorKind::NotATag, None));
|
||||||
}
|
}
|
||||||
|
|
||||||
let a = ts.iter().map(|t| Value::String(t.clone())).collect();
|
let a = ts.iter().unique().map(|t| Value::String(t.clone())).collect();
|
||||||
self.set("imag.tags", Value::Array(a))
|
self.set("imag.tags", Value::Array(a))
|
||||||
.map(|_| ())
|
.map(|_| ())
|
||||||
.map_err(|e| TagError::new(TagErrorKind::HeaderWriteError, Some(Box::new(e))))
|
.map_err(|e| TagError::new(TagErrorKind::HeaderWriteError, Some(Box::new(e))))
|
||||||
|
@ -81,7 +83,7 @@ impl Tagable for EntryHeader {
|
||||||
self.get_tags()
|
self.get_tags()
|
||||||
.map(|mut tags| {
|
.map(|mut tags| {
|
||||||
tags.push(t);
|
tags.push(t);
|
||||||
self.set_tags(tags)
|
self.set_tags(tags.into_iter().unique().collect())
|
||||||
})
|
})
|
||||||
.map(|_| ())
|
.map(|_| ())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue