Flat representation of localsource
This commit is contained in:
+80
-28
@@ -6,7 +6,7 @@ use std::{
|
|||||||
time::{Duration, SystemTime},
|
time::{Duration, SystemTime},
|
||||||
};
|
};
|
||||||
|
|
||||||
use fuser::{Errno, FileAttr, Filesystem, INodeNo};
|
use fuser::{Errno, FileAttr, Filesystem, Generation, INodeNo, Request};
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
|
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
|
||||||
enum FileType {
|
enum FileType {
|
||||||
@@ -82,7 +82,7 @@ impl LocalOrigin {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mut local_path: PathBuf = PathBuf::new();
|
let mut local_path: PathBuf = PathBuf::new();
|
||||||
local_path.push(destination);
|
// local_path.push(destination);
|
||||||
local_path.push(name.clone());
|
local_path.push(name.clone());
|
||||||
|
|
||||||
let local_item = LocalItem {
|
let local_item = LocalItem {
|
||||||
@@ -118,32 +118,10 @@ impl LocalOrigin {
|
|||||||
fn local_file_to_file_attr(local_file: &LocalItem) -> FileAttr {
|
fn local_file_to_file_attr(local_file: &LocalItem) -> FileAttr {
|
||||||
let metadata = &local_file.metadata;
|
let metadata = &local_file.metadata;
|
||||||
let ctime = std::time::UNIX_EPOCH + Duration::from_secs(metadata.ctime() as u64);
|
let ctime = std::time::UNIX_EPOCH + Duration::from_secs(metadata.ctime() as u64);
|
||||||
let atime = metadata
|
let atime = metadata.accessed().unwrap_or(SystemTime::UNIX_EPOCH);
|
||||||
.accessed()
|
let mtime = metadata.modified().unwrap_or(SystemTime::UNIX_EPOCH);
|
||||||
.map_err(|err| {
|
let crtime = metadata.created().unwrap_or(SystemTime::UNIX_EPOCH);
|
||||||
println!("Failed to get atime for: {}", &local_file.name);
|
let kind = LocalOrigin::file_type(local_file.file_type);
|
||||||
err
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
let mtime = metadata
|
|
||||||
.modified()
|
|
||||||
.map_err(|err| {
|
|
||||||
println!("Failed to get atime for: {}", &local_file.name);
|
|
||||||
err
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let crtime = metadata
|
|
||||||
.created()
|
|
||||||
.map_err(|err| {
|
|
||||||
println!("Failed to get atime for: {}", &local_file.name);
|
|
||||||
err
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
let kind = match local_file.file_type {
|
|
||||||
FileType::Directory => fuser::FileType::Directory,
|
|
||||||
FileType::File => fuser::FileType::RegularFile,
|
|
||||||
};
|
|
||||||
|
|
||||||
return FileAttr {
|
return FileAttr {
|
||||||
ino: local_file.inode,
|
ino: local_file.inode,
|
||||||
@@ -163,6 +141,13 @@ impl LocalOrigin {
|
|||||||
flags: 0, // TODO this is for macos only but perhaps we could get it from metadata still?
|
flags: 0, // TODO this is for macos only but perhaps we could get it from metadata still?
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn file_type(file_type: FileType) -> fuser::FileType {
|
||||||
|
return match file_type {
|
||||||
|
FileType::Directory => fuser::FileType::Directory,
|
||||||
|
FileType::File => fuser::FileType::RegularFile,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Filesystem for LocalOrigin {
|
impl Filesystem for LocalOrigin {
|
||||||
@@ -183,4 +168,71 @@ impl Filesystem for LocalOrigin {
|
|||||||
None => reply.error(Errno::ENOENT),
|
None => reply.error(Errno::ENOENT),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn readdir(
|
||||||
|
&self,
|
||||||
|
_req: &fuser::Request,
|
||||||
|
ino: INodeNo,
|
||||||
|
fh: fuser::FileHandle,
|
||||||
|
offset: u64,
|
||||||
|
mut reply: fuser::ReplyDirectory,
|
||||||
|
) {
|
||||||
|
println!("readdir(ino={}, fh={}, offset={})", ino, fh, offset);
|
||||||
|
|
||||||
|
if ino == INodeNo::ROOT {
|
||||||
|
if offset == 0 {
|
||||||
|
let _ = reply.add(
|
||||||
|
INodeNo::ROOT,
|
||||||
|
0,
|
||||||
|
fuser::FileType::Directory,
|
||||||
|
&Path::new("."),
|
||||||
|
);
|
||||||
|
let _ = reply.add(
|
||||||
|
INodeNo::ROOT,
|
||||||
|
1,
|
||||||
|
fuser::FileType::Directory,
|
||||||
|
&Path::new(".."),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i, (key, value)) in self.files.iter().skip(offset as usize).enumerate() {
|
||||||
|
let offset: u64 = 2 + i as u64;
|
||||||
|
let file_type: fuser::FileType = LocalOrigin::file_type(value.file_type);
|
||||||
|
let path = &value.local_path;
|
||||||
|
|
||||||
|
let buffer_full: bool = reply.add(*key, offset, file_type, path);
|
||||||
|
|
||||||
|
if buffer_full {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reply.ok();
|
||||||
|
} else {
|
||||||
|
reply.error(Errno::ENOSYS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn lookup(
|
||||||
|
&self,
|
||||||
|
_req: &Request,
|
||||||
|
parent: INodeNo,
|
||||||
|
name: &std::ffi::OsStr,
|
||||||
|
reply: fuser::ReplyEntry,
|
||||||
|
) {
|
||||||
|
println!("lookup(parent={}, name={})", parent, name.display());
|
||||||
|
|
||||||
|
return match self
|
||||||
|
.files
|
||||||
|
.iter()
|
||||||
|
.find(|item| item.1.name == name.to_str().unwrap())
|
||||||
|
{
|
||||||
|
Some(item) => {
|
||||||
|
let ttl = Duration::new(1, 0);
|
||||||
|
let attr = LocalOrigin::local_file_to_file_attr(item.1);
|
||||||
|
|
||||||
|
reply.entry(&ttl, &attr, Generation(0));
|
||||||
|
}
|
||||||
|
None => reply.error(Errno::ENOENT),
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user