mirror of https://github.com/dswd/zvault
Correct ids on mount (re #2)
This commit is contained in:
parent
a1f269be8f
commit
3da0a1d4ed
|
@ -6,7 +6,7 @@ This project follows [semantic versioning](http://semver.org).
|
||||||
### UNRELEASED
|
### UNRELEASED
|
||||||
- [added] Added CHANGELOG
|
- [added] Added CHANGELOG
|
||||||
- [added] Locking local repository to avoid index corruption
|
- [added] Locking local repository to avoid index corruption
|
||||||
- [added] Storing user/group names in backup
|
- [added] Storing user/group names in backups
|
||||||
- [modified] No longer trying to upload by rename
|
- [modified] No longer trying to upload by rename
|
||||||
- [modified] No longer failing restore if setting file attributes fails
|
- [modified] No longer failing restore if setting file attributes fails
|
||||||
- [fixed] Creating empty bundle cache on init to avoid warnings
|
- [fixed] Creating empty bundle cache on init to avoid warnings
|
||||||
|
|
|
@ -490,9 +490,9 @@ pub fn run() -> Result<(), ErrorCode> {
|
||||||
let backup = try!(get_backup(&repo, &backup_name));
|
let backup = try!(get_backup(&repo, &backup_name));
|
||||||
if let Some(inode) = inode {
|
if let Some(inode) = inode {
|
||||||
let inode = checked!(repo.get_backup_inode(&backup, inode), "load subpath inode", ErrorCode::LoadInode);
|
let inode = checked!(repo.get_backup_inode(&backup, inode), "load subpath inode", ErrorCode::LoadInode);
|
||||||
checked!(FuseFilesystem::from_inode(&mut repo, inode), "create fuse filesystem", ErrorCode::FuseMount)
|
checked!(FuseFilesystem::from_inode(&mut repo, backup, inode), "create fuse filesystem", ErrorCode::FuseMount)
|
||||||
} else {
|
} else {
|
||||||
checked!(FuseFilesystem::from_backup(&mut repo, &backup), "create fuse filesystem", ErrorCode::FuseMount)
|
checked!(FuseFilesystem::from_backup(&mut repo, backup), "create fuse filesystem", ErrorCode::FuseMount)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
checked!(FuseFilesystem::from_repository(&mut repo), "create fuse filesystem", ErrorCode::FuseMount)
|
checked!(FuseFilesystem::from_repository(&mut repo), "create fuse filesystem", ErrorCode::FuseMount)
|
||||||
|
|
49
src/mount.rs
49
src/mount.rs
|
@ -9,6 +9,7 @@ use std::mem;
|
||||||
use std::cmp::min;
|
use std::cmp::min;
|
||||||
|
|
||||||
use fuse;
|
use fuse;
|
||||||
|
use users::{self, Users, Groups};
|
||||||
use time::Timespec;
|
use time::Timespec;
|
||||||
use libc;
|
use libc;
|
||||||
|
|
||||||
|
@ -78,11 +79,26 @@ pub struct FuseInode {
|
||||||
inode: Inode,
|
inode: Inode,
|
||||||
parent: Option<FuseInodeRef>,
|
parent: Option<FuseInodeRef>,
|
||||||
children: HashMap<String, FuseInodeRef>,
|
children: HashMap<String, FuseInodeRef>,
|
||||||
chunks: Option<ChunkList>
|
chunks: Option<ChunkList>,
|
||||||
|
name_cache: Rc<users::UsersCache>,
|
||||||
|
user_names: Rc<HashMap<u32, String>>,
|
||||||
|
group_names: Rc<HashMap<u32, String>>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FuseInode {
|
impl FuseInode {
|
||||||
pub fn to_attrs(&self) -> fuse::FileAttr {
|
pub fn to_attrs(&self) -> fuse::FileAttr {
|
||||||
|
let mut uid = self.inode.user;
|
||||||
|
if let Some(name) = self.user_names.get(&self.inode.user) {
|
||||||
|
if let Some(user) = self.name_cache.get_user_by_name(name) {
|
||||||
|
uid = user.uid();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let mut gid = self.inode.group;
|
||||||
|
if let Some(name) = self.group_names.get(&self.inode.group) {
|
||||||
|
if let Some(group) = self.name_cache.get_group_by_name(name) {
|
||||||
|
gid = group.gid();
|
||||||
|
}
|
||||||
|
}
|
||||||
fuse::FileAttr {
|
fuse::FileAttr {
|
||||||
ino: self.num,
|
ino: self.num,
|
||||||
size: self.inode.size,
|
size: self.inode.size,
|
||||||
|
@ -94,8 +110,8 @@ impl FuseInode {
|
||||||
kind: convert_file_type(self.inode.file_type),
|
kind: convert_file_type(self.inode.file_type),
|
||||||
perm: self.inode.mode as u16,
|
perm: self.inode.mode as u16,
|
||||||
nlink: 1,
|
nlink: 1,
|
||||||
uid: self.inode.user,
|
uid: uid,
|
||||||
gid: self.inode.group,
|
gid: gid,
|
||||||
rdev: 0,
|
rdev: 0,
|
||||||
flags: 0
|
flags: 0
|
||||||
}
|
}
|
||||||
|
@ -160,16 +176,16 @@ impl<'a> FuseFilesystem<'a> {
|
||||||
Ok(fs)
|
Ok(fs)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_backup(repository: &'a mut Repository, backup: &Backup) -> Result<Self, RepositoryError> {
|
pub fn from_backup(repository: &'a mut Repository, backup: Backup) -> Result<Self, RepositoryError> {
|
||||||
let inode = try!(repository.get_inode(&backup.root));
|
let inode = try!(repository.get_inode(&backup.root));
|
||||||
let mut fs = try!(FuseFilesystem::new(repository));
|
let mut fs = try!(FuseFilesystem::new(repository));
|
||||||
fs.add_inode(inode, None);
|
fs.add_inode(inode, None, backup.user_names, backup.group_names);
|
||||||
Ok(fs)
|
Ok(fs)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_inode(repository: &'a mut Repository, inode: Inode) -> Result<Self, RepositoryError> {
|
pub fn from_inode(repository: &'a mut Repository, backup: Backup, inode: Inode) -> Result<Self, RepositoryError> {
|
||||||
let mut fs = try!(FuseFilesystem::new(repository));
|
let mut fs = try!(FuseFilesystem::new(repository));
|
||||||
fs.add_inode(inode, None);
|
fs.add_inode(inode, None, backup.user_names, backup.group_names);
|
||||||
Ok(fs)
|
Ok(fs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,16 +194,19 @@ impl<'a> FuseFilesystem<'a> {
|
||||||
name: name,
|
name: name,
|
||||||
file_type: FileType::Directory,
|
file_type: FileType::Directory,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}, parent)
|
}, parent, HashMap::default(), HashMap::default())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_inode(&mut self, inode: Inode, parent: Option<FuseInodeRef>) -> FuseInodeRef {
|
pub fn add_inode(&mut self, inode: Inode, parent: Option<FuseInodeRef>, user_names: HashMap<u32, String>, group_names: HashMap<u32, String>) -> FuseInodeRef {
|
||||||
let inode = FuseInode {
|
let inode = FuseInode {
|
||||||
inode: inode,
|
inode: inode,
|
||||||
num: self.next_id,
|
num: self.next_id,
|
||||||
parent: parent.clone(),
|
parent: parent.clone(),
|
||||||
chunks: None,
|
chunks: None,
|
||||||
children: HashMap::new()
|
children: HashMap::new(),
|
||||||
|
user_names: Rc::new(user_names),
|
||||||
|
group_names: Rc::new(group_names),
|
||||||
|
name_cache: Rc::new(users::UsersCache::new())
|
||||||
};
|
};
|
||||||
let name = inode.inode.name.clone();
|
let name = inode.inode.name.clone();
|
||||||
let inode = Rc::new(RefCell::new(inode));
|
let inode = Rc::new(RefCell::new(inode));
|
||||||
|
@ -224,7 +243,10 @@ impl<'a> FuseFilesystem<'a> {
|
||||||
inode: try!(self.repository.get_inode(chunks)),
|
inode: try!(self.repository.get_inode(chunks)),
|
||||||
parent: Some(parent.clone()),
|
parent: Some(parent.clone()),
|
||||||
children: HashMap::new(),
|
children: HashMap::new(),
|
||||||
chunks: None
|
chunks: None,
|
||||||
|
user_names: parent_mut.user_names.clone(),
|
||||||
|
group_names: parent_mut.group_names.clone(),
|
||||||
|
name_cache: parent_mut.name_cache.clone()
|
||||||
}));
|
}));
|
||||||
self.inodes.insert(self.next_id, child.clone());
|
self.inodes.insert(self.next_id, child.clone());
|
||||||
self.next_id +=1;
|
self.next_id +=1;
|
||||||
|
@ -247,7 +269,10 @@ impl<'a> FuseFilesystem<'a> {
|
||||||
inode: try!(self.repository.get_inode(chunks)),
|
inode: try!(self.repository.get_inode(chunks)),
|
||||||
parent: Some(parent.clone()),
|
parent: Some(parent.clone()),
|
||||||
children: HashMap::new(),
|
children: HashMap::new(),
|
||||||
chunks: None
|
chunks: None,
|
||||||
|
user_names: parent_mut.user_names.clone(),
|
||||||
|
group_names: parent_mut.group_names.clone(),
|
||||||
|
name_cache: parent_mut.name_cache.clone()
|
||||||
}));
|
}));
|
||||||
self.inodes.insert(self.next_id, child.clone());
|
self.inodes.insert(self.next_id, child.clone());
|
||||||
self.next_id +=1;
|
self.next_id +=1;
|
||||||
|
|
Loading…
Reference in New Issue