2016-10-01 15:35:06 +00:00
|
|
|
//
|
|
|
|
// imag - the personal information management suite for the commandline
|
2019-01-03 01:32:07 +00:00
|
|
|
// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> and contributors
|
2016-10-01 15:35:06 +00:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; version
|
|
|
|
// 2.1 of the License.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
//
|
|
|
|
|
2017-10-31 12:11:34 +00:00
|
|
|
use std::ops::Deref;
|
|
|
|
|
2019-10-19 06:54:57 +00:00
|
|
|
use failure::Fallible as Result;
|
|
|
|
use failure::err_msg;
|
|
|
|
use resiter::AndThen;
|
2019-10-26 14:32:33 +00:00
|
|
|
use resiter::IterInnerOkOrElse;
|
2019-10-19 06:54:57 +00:00
|
|
|
|
2016-07-16 22:45:51 +00:00
|
|
|
use libimagrt::runtime::Runtime;
|
|
|
|
|
2017-10-31 12:11:34 +00:00
|
|
|
/// Verify the store.
|
|
|
|
///
|
|
|
|
/// This function is not intended to be called by normal programs but only by `imag-store`.
|
2019-10-19 06:54:57 +00:00
|
|
|
pub fn verify(rt: &Runtime) -> Result<()> {
|
2017-10-31 12:11:34 +00:00
|
|
|
info!("Header | Content length | Path");
|
|
|
|
info!("-------+----------------+-----");
|
|
|
|
let result = rt
|
|
|
|
.store()
|
2019-10-19 06:54:57 +00:00
|
|
|
.entries()?
|
2018-05-01 15:49:41 +00:00
|
|
|
.into_get_iter()
|
2019-10-19 06:54:57 +00:00
|
|
|
.map_inner_ok_or_else(|| err_msg("Did not find one entry"))
|
|
|
|
.and_then_ok(|fle| {
|
2018-05-01 15:49:41 +00:00
|
|
|
let p = fle.get_location();
|
|
|
|
let content_len = fle.get_content().len();
|
2018-06-07 23:59:19 +00:00
|
|
|
let (verify, status) = if fle.verify().is_ok() {
|
2018-05-01 15:49:41 +00:00
|
|
|
("ok", true)
|
|
|
|
} else {
|
|
|
|
("broken", false)
|
|
|
|
};
|
|
|
|
|
2018-06-07 23:59:19 +00:00
|
|
|
info!("{: >6} | {: >14} | {:?}", verify, content_len, p.deref());
|
2019-10-19 06:54:57 +00:00
|
|
|
rt.report_touched(fle.get_location())?;
|
|
|
|
Ok(status)
|
|
|
|
})
|
|
|
|
.collect::<Result<Vec<_>>>()?
|
|
|
|
.iter()
|
|
|
|
.all(|x| *x);
|
2017-10-31 12:11:34 +00:00
|
|
|
|
|
|
|
if result {
|
2016-07-16 22:45:51 +00:00
|
|
|
info!("Store seems to be fine");
|
2019-10-19 06:54:57 +00:00
|
|
|
Ok(())
|
2016-07-16 22:45:51 +00:00
|
|
|
} else {
|
2019-10-19 06:54:57 +00:00
|
|
|
Err(err_msg("Store seems to be broken somehow"))
|
2016-07-16 22:45:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|