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;
|
|
|
|
|
2016-07-16 22:45:51 +00:00
|
|
|
use libimagrt::runtime::Runtime;
|
2016-09-05 17:34:12 +00:00
|
|
|
use libimagutil::warn_exit::warn_exit;
|
2018-05-01 15:49:41 +00:00
|
|
|
use libimagerror::trace::MapErrTrace;
|
2019-02-05 00:37:32 +00:00
|
|
|
use libimagerror::exit::ExitUnwrap;
|
2018-05-01 15:49:41 +00:00
|
|
|
use libimagerror::iter::TraceIterator;
|
2016-07-16 22:45:51 +00:00
|
|
|
|
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`.
|
2016-07-16 22:45:51 +00:00
|
|
|
pub fn verify(rt: &Runtime) {
|
2017-10-31 12:11:34 +00:00
|
|
|
info!("Header | Content length | Path");
|
|
|
|
info!("-------+----------------+-----");
|
|
|
|
let result = rt
|
|
|
|
.store()
|
2018-05-01 15:49:41 +00:00
|
|
|
.entries()
|
2019-02-05 00:37:32 +00:00
|
|
|
.map_err_trace_exit_unwrap()
|
2018-05-01 15:49:41 +00:00
|
|
|
.into_get_iter()
|
2019-02-05 00:37:32 +00:00
|
|
|
.trace_unwrap_exit()
|
2018-05-01 15:49:41 +00:00
|
|
|
.filter_map(|x| x)
|
|
|
|
.all(|fle| {
|
|
|
|
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-08-27 08:41:35 +00:00
|
|
|
rt.report_touched(fle.get_location()).unwrap_or_exit();
|
2018-05-01 15:49:41 +00:00
|
|
|
status
|
2017-10-31 12:11:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
if result {
|
2016-07-16 22:45:51 +00:00
|
|
|
info!("Store seems to be fine");
|
|
|
|
} else {
|
2016-09-05 17:34:12 +00:00
|
|
|
warn_exit("Store seems to be broken somehow", 1);
|
2016-07-16 22:45:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|