This commit is contained in:
Dennis Schwerdel 2017-03-22 21:42:43 +01:00 committed by Dennis Schwerdel
parent bdcab7e308
commit 519ac6bade
2 changed files with 19 additions and 22 deletions

View File

@ -3,7 +3,7 @@ use ::prelude::*;
use std::io::{self, BufReader, BufWriter, Read, Write}; use std::io::{self, BufReader, BufWriter, Read, Write};
use std::fs::{self, File}; use std::fs::{self, File};
use std::path::{self, Path, PathBuf}; use std::path::{self, Path, PathBuf};
use std::collections::{HashMap, VecDeque}; use std::collections::{HashMap, BTreeMap, VecDeque};
use chrono::prelude::*; use chrono::prelude::*;
@ -327,20 +327,21 @@ impl Repository {
}, },
Err(err) => return Err(err) Err(err) => return Err(err)
}; };
backup.total_data_size += inode.size; let meta_size = 1000; // add 1000 for encoded metadata
backup.total_data_size += inode.size + meta_size;
if let Some(ref ref_inode) = reference_inode { if let Some(ref ref_inode) = reference_inode {
if !ref_inode.is_unchanged(&inode) { if !ref_inode.is_unchanged(&inode) {
backup.changed_data_size += inode.size; backup.changed_data_size += inode.size + meta_size;
} }
} else { } else {
backup.changed_data_size += inode.size; backup.changed_data_size += inode.size + meta_size;
} }
if inode.file_type == FileType::Directory { if inode.file_type == FileType::Directory {
backup.dir_count +=1; backup.dir_count +=1;
// For directories we need to put all children on the stack too, so there will be inodes created for them // For directories we need to put all children on the stack too, so there will be inodes created for them
// Also we put directories on the save stack to save them in order // Also we put directories on the save stack to save them in order
save_stack.push(path.clone()); save_stack.push(path.clone());
inode.children = Some(HashMap::new()); inode.children = Some(BTreeMap::new());
directories.insert(path.clone(), inode); directories.insert(path.clone(), inode);
let dirlist = match fs::read_dir(&path) { let dirlist = match fs::read_dir(&path) {
Ok(dirlist) => dirlist, Ok(dirlist) => dirlist,

View File

@ -2,9 +2,9 @@ use ::prelude::*;
use filetime::{self, FileTime}; use filetime::{self, FileTime};
use std::collections::HashMap; use std::collections::BTreeMap;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::fs::{self, Metadata, File, Permissions}; use std::fs::{self, File, Permissions};
use std::os::linux::fs::MetadataExt; use std::os::linux::fs::MetadataExt;
use std::os::unix::fs::{PermissionsExt, symlink}; use std::os::unix::fs::{PermissionsExt, symlink};
use std::io::{self, Read, Write}; use std::io::{self, Read, Write};
@ -106,7 +106,7 @@ pub struct Inode {
pub create_time: i64, pub create_time: i64,
pub symlink_target: Option<String>, pub symlink_target: Option<String>,
pub contents: Option<FileContents>, pub contents: Option<FileContents>,
pub children: Option<HashMap<String, ChunkList>> pub children: Option<BTreeMap<String, ChunkList>>
} }
impl Default for Inode { impl Default for Inode {
fn default() -> Self { fn default() -> Self {
@ -138,22 +138,11 @@ serde_impl!(Inode(u8) {
create_time: i64 => 8, create_time: i64 => 8,
symlink_target: Option<String> => 9, symlink_target: Option<String> => 9,
contents: Option<FileContents> => 10, contents: Option<FileContents> => 10,
children: HashMap<String, ChunkList> => 11 children: BTreeMap<String, ChunkList> => 11
}); });
impl Inode { impl Inode {
#[inline]
fn get_extended_attrs_from(&mut self, meta: &Metadata) -> Result<(), InodeError> {
self.mode = meta.st_mode();
self.user = meta.st_uid();
self.group = meta.st_gid();
self.access_time = meta.st_atime();
self.modify_time = meta.st_mtime();
self.create_time = meta.st_ctime();
Ok(())
}
pub fn get_from<P: AsRef<Path>>(path: P) -> Result<Self, InodeError> { pub fn get_from<P: AsRef<Path>>(path: P) -> Result<Self, InodeError> {
let path = path.as_ref(); let path = path.as_ref();
let name = try!(path.file_name() let name = try!(path.file_name()
@ -162,7 +151,9 @@ impl Inode {
let meta = try!(fs::symlink_metadata(path).map_err(|e| InodeError::ReadMetadata(e, path.to_owned()))); let meta = try!(fs::symlink_metadata(path).map_err(|e| InodeError::ReadMetadata(e, path.to_owned())));
let mut inode = Inode::default(); let mut inode = Inode::default();
inode.name = name; inode.name = name;
if meta.is_file() {
inode.size = meta.len(); inode.size = meta.len();
}
inode.file_type = if meta.is_file() { inode.file_type = if meta.is_file() {
FileType::File FileType::File
} else if meta.is_dir() { } else if meta.is_dir() {
@ -175,7 +166,12 @@ impl Inode {
if meta.file_type().is_symlink() { if meta.file_type().is_symlink() {
inode.symlink_target = Some(try!(fs::read_link(path).map_err(|e| InodeError::ReadLinkTarget(e, path.to_owned()))).to_string_lossy().to_string()); inode.symlink_target = Some(try!(fs::read_link(path).map_err(|e| InodeError::ReadLinkTarget(e, path.to_owned()))).to_string_lossy().to_string());
} }
try!(inode.get_extended_attrs_from(&meta)); inode.mode = meta.st_mode();
inode.user = meta.st_uid();
inode.group = meta.st_gid();
inode.access_time = meta.st_atime();
inode.modify_time = meta.st_mtime();
inode.create_time = meta.st_ctime();
Ok(inode) Ok(inode)
} }