summaryrefslogtreecommitdiff
path: root/src/fsentry.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2022-05-03 10:44:26 +0300
committerLars Wirzenius <liw@liw.fi>2022-05-03 11:23:38 +0300
commit3d50e1497dd07929655636cfea0c48ccadd3ab8e (patch)
tree69770791ebb26ebbce6137ea481e85f19ec35041 /src/fsentry.rs
parent856d32c448a87245234315462d2190c5a9aab549 (diff)
downloadobnam2-3d50e1497dd07929655636cfea0c48ccadd3ab8e.tar.gz
test: add test for storing, retrieving u64::MAX values in JSON
The test passes. We create a FilesystemEntry with a length field containing u64::MAX, store that into a generation, and read it back. This works. The entry is serialised into JSON for storing in SQLite, and this proves we can handle any u64 value in an entry. serde_json deals with it fine, and we don't need to worry about it. Sponsored-by: author
Diffstat (limited to 'src/fsentry.rs')
-rw-r--r--src/fsentry.rs51
1 files changed, 39 insertions, 12 deletions
diff --git a/src/fsentry.rs b/src/fsentry.rs
index 90afd70..a04a3de 100644
--- a/src/fsentry.rs
+++ b/src/fsentry.rs
@@ -70,12 +70,19 @@ pub enum FsEntryError {
#[allow(clippy::len_without_is_empty)]
impl FilesystemEntry {
/// Create an `FsEntry` from a file's metadata.
- pub fn from_metadata(
+ pub(crate) fn new(
path: &Path,
- meta: &Metadata,
+ kind: FilesystemKind,
+ uid: u32,
+ gid: u32,
+ len: u64,
+ mode: u32,
+ mtime: i64,
+ mtime_ns: i64,
+ atime: i64,
+ atime_ns: i64,
cache: &mut UsersCache,
) -> Result<Self, FsEntryError> {
- let kind = FilesystemKind::from_file_type(meta.file_type());
let symlink_target = if kind == FilesystemKind::Symlink {
debug!("reading symlink target for {:?}", path);
let target =
@@ -85,8 +92,6 @@ impl FilesystemEntry {
None
};
- let uid = meta.st_uid();
- let gid = meta.st_gid();
let user: String = if let Some(user) = cache.get_user_by_uid(uid) {
user.name().to_string_lossy().to_string()
} else {
@@ -100,13 +105,13 @@ impl FilesystemEntry {
Ok(Self {
path: path.to_path_buf().into_os_string().into_vec(),
- kind: FilesystemKind::from_file_type(meta.file_type()),
- len: meta.len(),
- mode: meta.st_mode(),
- mtime: meta.st_mtime(),
- mtime_ns: meta.st_mtime_nsec(),
- atime: meta.st_atime(),
- atime_ns: meta.st_atime_nsec(),
+ kind,
+ len,
+ mode,
+ mtime,
+ mtime_ns,
+ atime,
+ atime_ns,
symlink_target,
uid,
gid,
@@ -115,6 +120,28 @@ impl FilesystemEntry {
})
}
+ /// Create an `FsEntry` from a file's metadata.
+ pub fn from_metadata(
+ path: &Path,
+ meta: &Metadata,
+ cache: &mut UsersCache,
+ ) -> Result<Self, FsEntryError> {
+ let kind = FilesystemKind::from_file_type(meta.file_type());
+ Self::new(
+ path,
+ kind,
+ meta.st_uid(),
+ meta.st_gid(),
+ meta.len(),
+ meta.st_mode(),
+ meta.st_mtime(),
+ meta.st_mtime_nsec(),
+ meta.st_atime(),
+ meta.st_atime_nsec(),
+ cache,
+ )
+ }
+
/// Return the kind of file the entry refers to.
pub fn kind(&self) -> FilesystemKind {
self.kind