src/api2/config/datastore.rs - create: pass uid and gid instead of User

This commit is contained in:
Dietmar Maurer 2019-12-20 09:23:58 +01:00
parent e67770d496
commit 645995634a
2 changed files with 7 additions and 6 deletions

View File

@ -60,7 +60,7 @@ fn create_datastore(
let path: PathBuf = param["path"].as_str().unwrap().into(); let path: PathBuf = param["path"].as_str().unwrap().into();
let backup_user = crate::backup::backup_user()?; let backup_user = crate::backup::backup_user()?;
let _store = ChunkStore::create(name, path, backup_user)?; let _store = ChunkStore::create(name, path, backup_user.uid, backup_user.gid)?;
let datastore = json!({ let datastore = json!({
"path": param["path"], "path": param["path"],

View File

@ -85,7 +85,7 @@ impl ChunkStore {
chunk_dir chunk_dir
} }
pub fn create<P>(name: &str, path: P, user: nix::unistd::User) -> Result<Self, Error> pub fn create<P>(name: &str, path: P, uid: nix::unistd::Uid, gid: nix::unistd::Gid) -> Result<Self, Error>
where where
P: Into<PathBuf>, P: Into<PathBuf>,
{ {
@ -99,8 +99,8 @@ impl ChunkStore {
let chunk_dir = Self::chunk_dir(&base); let chunk_dir = Self::chunk_dir(&base);
let options = CreateOptions::new() let options = CreateOptions::new()
.owner(user.uid) .owner(uid)
.group(user.gid); .group(gid);
let default_options = CreateOptions::new(); let default_options = CreateOptions::new();
@ -465,7 +465,8 @@ fn test_chunk_store1() {
let chunk_store = ChunkStore::open("test", &path); let chunk_store = ChunkStore::open("test", &path);
assert!(chunk_store.is_err()); assert!(chunk_store.is_err());
let chunk_store = ChunkStore::create("test", &path, CreateOptions::new()).unwrap(); let user = nix::unistd::User::from_uid(nix::unistd::Uid::current()).unwrap().unwrap();
let chunk_store = ChunkStore::create("test", &path, user.uid, user.gid).unwrap();
let (chunk, digest) = super::DataChunkBuilder::new(&[0u8, 1u8]).build().unwrap(); let (chunk, digest) = super::DataChunkBuilder::new(&[0u8, 1u8]).build().unwrap();
@ -476,7 +477,7 @@ fn test_chunk_store1() {
assert!(exists); assert!(exists);
let chunk_store = ChunkStore::create("test", &path, CreateOptions::new()); let chunk_store = ChunkStore::create("test", &path, user.uid, user.gid);
assert!(chunk_store.is_err()); assert!(chunk_store.is_err());
if let Err(_e) = std::fs::remove_dir_all(".testdir") { /* ignore */ } if let Err(_e) = std::fs::remove_dir_all(".testdir") { /* ignore */ }