use std::io::{Read, Write}; use std::path::Path; use protobuf::Message; use protobuf::parse_from_bytes; use errors::*; use sleep_register::*; use metadata_msgs::{Index, Stat, Node}; /// "Sort of" follows rust std::fs API for file system access. pub struct DatDrive { metadata: SleepDirRegister, content: SleepDirRegister, } impl DatDrive { /// Instantiates a drive in the given directory. Path should be the complete path (eg, ending /// in '/.dat/'), not an enclosing directory containing files. pub fn create>(path: P) -> Result { unimplemented!() } /// Path should be the complete path (eg, ending in '/.dat/'), not an enclosing directory /// containing files. pub fn open>(path: P) -> Result { unimplemented!() } } impl<'a> DatDrive { pub fn history(start: u64) -> DriveHistory<'a> { unimplemented!() } pub fn read_dir_recursive>(path: P) -> ReadDriveDir<'a> { unimplemented!() } pub fn read_dir>(path: P) -> ReadDriveDir<'a> { unimplemented!() } pub fn file_metadata>(path: P) -> Result { unimplemented!() } pub fn create_file_bytes>(path: P, stat: &Stat, data: &[u8]) -> Result<()> { unimplemented!() } pub fn create_file, R: Read>(path: P, stat: &Stat, source: R) -> Result<()> { unimplemented!() } /// Copies Stat metadata and all content from a file in the "real" filesystem into the /// DatDrive. pub fn import_file, Q: AsRef>(source: P, dest: Q) -> Result<()> { unimplemented!() } /* Possible future helper functions to be even more like std::fs pub fn rename, Q: AsRef>(from: P, to: Q) -> Result<()> pub fn copy, Q: AsRef>(from: P, to: Q) -> Result<()> pub fn remove_file>(path: P) -> Result<()> pub fn remove_dir_all>(path: P) -> Result<()> */ } #[test] fn test_dd_open() { let mut dd = DatDrive::open(Path::new("test-data/dat/simple/.dat/")).unwrap(); // verified from dat log assert_eq!(dd.history().collect().len(), 2); assert_eq!(dd.read_dir().collect().len(), 1); assert_eq!(dd.read_dir_recurisve().collect().len(), 1); } #[test] fn test_dd_create() { use tempdir::TempDir; let tmp_dir = TempDir::new("geniza-test").unwrap(); let mut dd = DatDrive::create(tmp_dir.path()).unwrap(); assert_eq!(dd.history().collect().len(), 0); assert_eq!(dd.read_dir().collect().len(), 0); assert_eq!(dd.read_dir_recurisve().collect().len(), 0); } pub struct DriveEntry { node: Node, index: u64, } pub struct DriveHistory<'a> { drive: &'a mut DatDrive, } /// Iterator pub struct ReadDriveDir<'a> { drive: &'a mut DatDrive, recursive: bool, // Entries to recurse over entries: Vec, } impl<'a> ReadDriveDir<'a> { fn init>(drive: &mut DatDrive, path: P, recursive: bool) { unimplemented!(); // TODO: starting from the last data entry, recurse up to nearest directory, then recurse // down to base path //ReadDriveDir { // drive, // recursive, // entries: vec![], //} } } impl<'a> Iterator for DriveHistory<'a> { type Item = DriveEntry; fn next(&mut self) -> Option { unimplemented!(); } } impl<'a> Iterator for ReadDriveDir<'a> { type Item = DriveEntry; fn next(&mut self) -> Option { unimplemented!(); } }