From 7fbe51db68a91110a2e255946601331fda0c7790 Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Mon, 7 Feb 2022 19:06:50 +0000 Subject: [PATCH] Support filesystems (e.g. ZFS) that don't expose a creation time --- olivefs_common/src/messages.rs | 4 ++-- olivefs_common/src/messages/messages_fuser.rs | 5 +++-- olivefsd/src/server/file_access.rs | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/olivefs_common/src/messages.rs b/olivefs_common/src/messages.rs index 508fc4b..410728f 100644 --- a/olivefs_common/src/messages.rs +++ b/olivefs_common/src/messages.rs @@ -162,8 +162,8 @@ pub struct FileMetadata { pub atime: SystemTime, /// Time of last modification pub mtime: SystemTime, - /// Time of last change - pub ctime: SystemTime, + /// Time of last change. Not all filesystems have this. + pub ctime: Option, // /// Time of creation (macOS only) // pub crtime: SystemTime, /// Kind of file (directory, file, pipe, etc) diff --git a/olivefs_common/src/messages/messages_fuser.rs b/olivefs_common/src/messages/messages_fuser.rs index a6361d3..9a4ef05 100644 --- a/olivefs_common/src/messages/messages_fuser.rs +++ b/olivefs_common/src/messages/messages_fuser.rs @@ -1,5 +1,6 @@ use crate::messages::{FileKind, FileMetadata}; use fuser::{FileAttr, FileType}; +use std::time::SystemTime; impl From for FileKind { fn from(filetype: FileType) -> Self { @@ -37,8 +38,8 @@ impl Into for FileMetadata { blocks: self.blocks, atime: self.atime, mtime: self.mtime, - ctime: self.ctime, - crtime: self.ctime, + ctime: self.ctime.unwrap_or(SystemTime::UNIX_EPOCH), + crtime: self.ctime.unwrap_or(SystemTime::UNIX_EPOCH), kind: self.kind.into(), perm: self.perm, nlink: self.nlink, diff --git a/olivefsd/src/server/file_access.rs b/olivefsd/src/server/file_access.rs index 07622f6..619cdb1 100644 --- a/olivefsd/src/server/file_access.rs +++ b/olivefsd/src/server/file_access.rs @@ -240,7 +240,7 @@ impl FileAccess { blocks: metadata.blocks(), atime: metadata.accessed().unwrap(), mtime: metadata.modified().unwrap(), - ctime: metadata.created().unwrap(), + ctime: metadata.created().ok(), kind: metadata.file_type().into(), perm: metadata.permissions().mode() as u16, nlink: metadata.nlink() as u32,