mirror of
https://github.com/rustic-rs/rustic.git
synced 2025-10-26 11:18:51 +00:00
Fix clippy::cast_lossless
This commit is contained in:
parent
a6d6815568
commit
bfe73779e2
@ -211,7 +211,7 @@ impl Cache {
|
||||
&offset
|
||||
);
|
||||
let mut file = File::open(self.path(tpe, id))?;
|
||||
file.seek(SeekFrom::Start(offset as u64))?;
|
||||
file.seek(SeekFrom::Start(u64::from(offset)))?;
|
||||
let mut vec = vec![0; length as usize];
|
||||
file.read_exact(&mut vec)?;
|
||||
trace!("cache hit!");
|
||||
|
||||
@ -57,12 +57,14 @@ impl PackSizer {
|
||||
pub fn size_ok(&self, size: u32) -> bool {
|
||||
let target_size = self.pack_size();
|
||||
// Note: we cast to u64 so that no overflow can occur in the multiplications
|
||||
size as u64 * 100 >= target_size as u64 * self.min_packsize_tolerate_percent as u64
|
||||
&& size as u64 * 100 <= target_size as u64 * self.max_packsize_tolerate_percent as u64
|
||||
u64::from(size) * 100
|
||||
>= u64::from(target_size) * u64::from(self.min_packsize_tolerate_percent)
|
||||
&& u64::from(size) * 100
|
||||
<= u64::from(target_size) * u64::from(self.max_packsize_tolerate_percent)
|
||||
}
|
||||
|
||||
fn add_size(&mut self, added: u32) {
|
||||
self.current_size += added as u64;
|
||||
self.current_size += u64::from(added);
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,7 +137,13 @@ impl<BE: DecryptWriteBackend> Packer<BE> {
|
||||
NonZeroU32::new(data_len),
|
||||
),
|
||||
};
|
||||
self.add_raw(&data, id, data_len as u64, uncompressed_length, size_limit)
|
||||
self.add_raw(
|
||||
&data,
|
||||
id,
|
||||
u64::from(data_len),
|
||||
uncompressed_length,
|
||||
size_limit,
|
||||
)
|
||||
}
|
||||
|
||||
/// adds the already encrypted (and maybe compressed) blob to the packfile
|
||||
|
||||
@ -143,7 +143,7 @@ fn check_cache_files(
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let total_size = files.values().map(|size| *size as u64).sum();
|
||||
let total_size = files.values().map(|size| u64::from(*size)).sum();
|
||||
p.set_length(total_size);
|
||||
|
||||
files
|
||||
@ -168,7 +168,7 @@ fn check_cache_files(
|
||||
(Ok(_), Ok(_)) => {} // everything ok
|
||||
}
|
||||
|
||||
p.inc(size as u64);
|
||||
p.inc(u64::from(size));
|
||||
});
|
||||
|
||||
p.finish();
|
||||
|
||||
@ -311,41 +311,41 @@ impl PrunePack {
|
||||
match todo {
|
||||
PackToDo::Undecided => panic!("not possible"),
|
||||
PackToDo::Keep => {
|
||||
stats.blobs[tpe].used += pi.used_blobs as u64;
|
||||
stats.blobs[tpe].unused += pi.unused_blobs as u64;
|
||||
stats.size[tpe].used += pi.used_size as u64;
|
||||
stats.size[tpe].unused += pi.unused_size as u64;
|
||||
stats.blobs[tpe].used += u64::from(pi.used_blobs);
|
||||
stats.blobs[tpe].unused += u64::from(pi.unused_blobs);
|
||||
stats.size[tpe].used += u64::from(pi.used_size);
|
||||
stats.size[tpe].unused += u64::from(pi.unused_size);
|
||||
stats.packs.keep += 1;
|
||||
}
|
||||
PackToDo::Repack => {
|
||||
stats.blobs[tpe].used += pi.used_blobs as u64;
|
||||
stats.blobs[tpe].unused += pi.unused_blobs as u64;
|
||||
stats.size[tpe].used += pi.used_size as u64;
|
||||
stats.size[tpe].unused += pi.unused_size as u64;
|
||||
stats.blobs[tpe].used += u64::from(pi.used_blobs);
|
||||
stats.blobs[tpe].unused += u64::from(pi.unused_blobs);
|
||||
stats.size[tpe].used += u64::from(pi.used_size);
|
||||
stats.size[tpe].unused += u64::from(pi.unused_size);
|
||||
stats.packs.repack += 1;
|
||||
stats.blobs[tpe].repack += (pi.unused_blobs + pi.used_blobs) as u64;
|
||||
stats.blobs[tpe].repackrm += pi.unused_blobs as u64;
|
||||
stats.size[tpe].repack += (pi.unused_size + pi.used_size) as u64;
|
||||
stats.size[tpe].repackrm += pi.unused_size as u64;
|
||||
stats.blobs[tpe].repack += u64::from(pi.unused_blobs + pi.used_blobs);
|
||||
stats.blobs[tpe].repackrm += u64::from(pi.unused_blobs);
|
||||
stats.size[tpe].repack += u64::from(pi.unused_size + pi.used_size);
|
||||
stats.size[tpe].repackrm += u64::from(pi.unused_size);
|
||||
}
|
||||
|
||||
PackToDo::MarkDelete => {
|
||||
stats.blobs[tpe].unused += pi.unused_blobs as u64;
|
||||
stats.size[tpe].unused += pi.unused_size as u64;
|
||||
stats.blobs[tpe].remove += pi.unused_blobs as u64;
|
||||
stats.size[tpe].remove += pi.unused_size as u64;
|
||||
stats.blobs[tpe].unused += u64::from(pi.unused_blobs);
|
||||
stats.size[tpe].unused += u64::from(pi.unused_size);
|
||||
stats.blobs[tpe].remove += u64::from(pi.unused_blobs);
|
||||
stats.size[tpe].remove += u64::from(pi.unused_size);
|
||||
}
|
||||
PackToDo::Recover => {
|
||||
stats.packs_to_delete.recover += 1;
|
||||
stats.size_to_delete.recover += self.size as u64;
|
||||
stats.size_to_delete.recover += u64::from(self.size);
|
||||
}
|
||||
PackToDo::Delete => {
|
||||
stats.packs_to_delete.remove += 1;
|
||||
stats.size_to_delete.remove += self.size as u64;
|
||||
stats.size_to_delete.remove += u64::from(self.size);
|
||||
}
|
||||
PackToDo::KeepMarked => {
|
||||
stats.packs_to_delete.keep += 1;
|
||||
stats.size_to_delete.keep += self.size as u64;
|
||||
stats.size_to_delete.keep += u64::from(self.size);
|
||||
}
|
||||
}
|
||||
self.to_do = todo;
|
||||
@ -599,7 +599,7 @@ impl Pruner {
|
||||
let blob_type = pi.blob_type;
|
||||
|
||||
let total_repack_size: u64 = repack_size.into_values().sum();
|
||||
if total_repack_size + pi.used_size as u64 >= max_repack
|
||||
if total_repack_size + u64::from(pi.used_size) >= max_repack
|
||||
|| (self.stats.size.sum().unused_after_prune() < max_unused
|
||||
&& repack_reason == PartlyUsed
|
||||
&& blob_type == BlobType::Data)
|
||||
@ -608,10 +608,10 @@ impl Pruner {
|
||||
pack.set_todo(PackToDo::Keep, &pi, &mut self.stats);
|
||||
} else if repack_reason == SizeMismatch {
|
||||
resize_packs[blob_type].push((pi, index_num, pack_num));
|
||||
repack_size[blob_type] += pi.used_size as u64;
|
||||
repack_size[blob_type] += u64::from(pi.used_size);
|
||||
} else {
|
||||
pack.set_todo(PackToDo::Repack, &pi, &mut self.stats);
|
||||
repack_size[blob_type] += pi.used_size as u64;
|
||||
repack_size[blob_type] += u64::from(pi.used_size);
|
||||
do_repack[blob_type] = true;
|
||||
}
|
||||
}
|
||||
@ -619,7 +619,7 @@ impl Pruner {
|
||||
// packs in resize_packs are only repacked if we anyway repack this blob type or
|
||||
// if the target pack size is reached for the blob type.
|
||||
let todo = if do_repack[blob_type]
|
||||
|| repack_size[blob_type] > pack_sizer[blob_type].pack_size() as u64
|
||||
|| repack_size[blob_type] > u64::from(pack_sizer[blob_type].pack_size())
|
||||
{
|
||||
PackToDo::Repack
|
||||
} else {
|
||||
@ -672,7 +672,7 @@ impl Pruner {
|
||||
|
||||
// all remaining packs in existing_packs are unreferenced packs
|
||||
for size in self.existing_packs.values() {
|
||||
self.stats.size_unref += *size as u64;
|
||||
self.stats.size_unref += u64::from(*size);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@ -827,7 +827,7 @@ impl Pruner {
|
||||
let size_after_prune = BlobTypeMap::init(|blob_type| {
|
||||
self.stats.size[blob_type].total_after_prune()
|
||||
+ self.stats.blobs[blob_type].total_after_prune()
|
||||
* HeaderEntry::ENTRY_LEN_COMPRESSED as u64
|
||||
* u64::from(HeaderEntry::ENTRY_LEN_COMPRESSED)
|
||||
});
|
||||
|
||||
let tree_repacker = Repacker::new(
|
||||
@ -928,7 +928,7 @@ impl Pruner {
|
||||
} else {
|
||||
repacker.add(&pack.id, blob)?;
|
||||
}
|
||||
p.inc(blob.length as u64);
|
||||
p.inc(u64::from(blob.length));
|
||||
}
|
||||
if opts.instant_delete {
|
||||
delete_pack(pack);
|
||||
@ -1016,8 +1016,8 @@ impl Ord for PackInfo {
|
||||
// then order such that packs with highest
|
||||
// ratio unused/used space are picked first.
|
||||
// This is equivalent to ordering by unused / total space.
|
||||
(other.unused_size as u64 * self.used_size as u64)
|
||||
.cmp(&(self.unused_size as u64 * other.used_size as u64)),
|
||||
(u64::from(other.unused_size) * u64::from(self.used_size))
|
||||
.cmp(&(u64::from(self.unused_size) * u64::from(other.used_size))),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -334,7 +334,7 @@ fn repair_tree<BE: DecryptWriteBackend>(
|
||||
match be.get_data(&blob) {
|
||||
Some(ie) => {
|
||||
new_content.push(blob);
|
||||
new_size += ie.data_length() as u64;
|
||||
new_size += u64::from(ie.data_length());
|
||||
}
|
||||
None => {
|
||||
file_changed = true;
|
||||
|
||||
@ -33,13 +33,13 @@ pub(super) fn execute(repo: OpenRepository, _opts: Opts) -> Result<()> {
|
||||
impl Info {
|
||||
fn add(&mut self, ie: IndexEntry) {
|
||||
self.count += 1;
|
||||
self.size += *ie.length() as u64;
|
||||
self.data_size += ie.data_length() as u64;
|
||||
self.size += u64::from(*ie.length());
|
||||
self.data_size += u64::from(ie.data_length());
|
||||
}
|
||||
|
||||
fn add_pack(&mut self, ip: &IndexPack) {
|
||||
self.pack_count += 1;
|
||||
let size = ip.pack_size() as u64;
|
||||
let size = u64::from(ip.pack_size());
|
||||
self.total_pack_size += size;
|
||||
self.min_pack_size = self.min_pack_size.min(size);
|
||||
self.max_pack_size = self.max_pack_size.max(size);
|
||||
@ -135,7 +135,7 @@ fn fileinfo(text: &str, be: &impl ReadBackend) -> Result<()> {
|
||||
for tpe in ALL_FILE_TYPES {
|
||||
let list = be.list_with_size(tpe)?;
|
||||
let count = list.len();
|
||||
let size = list.iter().map(|f| f.1 as u64).sum();
|
||||
let size = list.iter().map(|f| u64::from(f.1)).sum();
|
||||
table.add_row([format!("{:?}", tpe), count.to_string(), bytes(size)]);
|
||||
total_count += count;
|
||||
total_size += size;
|
||||
|
||||
@ -110,7 +110,7 @@ impl Extend<IndexPack> for IndexCollector {
|
||||
let idx = self.0[blob_type].packs.len();
|
||||
self.0[blob_type].packs.push((p.id, size));
|
||||
|
||||
self.0[blob_type].total_size += size as u64;
|
||||
self.0[blob_type].total_size += u64::from(size);
|
||||
|
||||
match &mut self.0[blob_type].entries {
|
||||
EntriesVariants::None => {}
|
||||
|
||||
@ -74,7 +74,7 @@ impl KeyFile {
|
||||
hostname,
|
||||
username,
|
||||
kdf: "scrypt".to_string(),
|
||||
n: 2_u32.pow(params.log_n() as u32),
|
||||
n: 2_u32.pow(u32::from(params.log_n())),
|
||||
r: params.r(),
|
||||
p: params.p(),
|
||||
created: with_created.then(Local::now),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user