diff --git a/src/internal/directory.rs b/src/internal/directory.rs index cba4939..3a3739b 100644 --- a/src/internal/directory.rs +++ b/src/internal/directory.rs @@ -251,8 +251,12 @@ impl Directory { ); // Create a new directory entry. let stream_id = self.allocate_dir_entry()?; - let now = Timestamp::now(); - *self.dir_entry_mut(stream_id) = DirEntry::new(name, obj_type, now); + // 2.6.1 streams must have creation and modified time of 0 + let mut ts = Timestamp::zero(); + if obj_type == ObjType::Storage { + ts = Timestamp::now(); + } + *self.dir_entry_mut(stream_id) = DirEntry::new(name, obj_type, ts); // Insert the new entry into the tree. let mut sibling_id = self.dir_entry(parent_id).child; diff --git a/src/internal/header.rs b/src/internal/header.rs index 67509b9..ce46a1b 100644 --- a/src/internal/header.rs +++ b/src/internal/header.rs @@ -162,7 +162,7 @@ mod tests { fn make_valid_header() -> Header { let mut header = Header { version: Version::V3, - num_dir_sectors: 2, + num_dir_sectors: 0, num_fat_sectors: 1, first_dir_sector: 1, first_minifat_sector: 2, diff --git a/src/internal/path.rs b/src/internal/path.rs index d1e1b65..c1b9ae6 100644 --- a/src/internal/path.rs +++ b/src/internal/path.rs @@ -123,7 +123,7 @@ mod tests { #[test] fn absolute_path_is_valid() { assert_eq!( - name_chain_from_path(&Path::new("/foo/bar/baz/")).unwrap(), + name_chain_from_path(Path::new("/foo/bar/baz/")).unwrap(), vec!["foo", "bar", "baz"] ); } @@ -131,7 +131,7 @@ mod tests { #[test] fn relative_path_is_valid() { assert_eq!( - name_chain_from_path(&Path::new("foo/bar/baz")).unwrap(), + name_chain_from_path(Path::new("foo/bar/baz")).unwrap(), vec!["foo", "bar", "baz"] ); } @@ -139,7 +139,7 @@ mod tests { #[test] fn path_with_parents_is_valid() { assert_eq!( - name_chain_from_path(&Path::new("foo/bar/../baz")).unwrap(), + name_chain_from_path(Path::new("foo/bar/../baz")).unwrap(), vec!["foo", "baz"] ); } @@ -147,13 +147,13 @@ mod tests { #[test] #[should_panic(expected = "Invalid path (must be within root)")] fn parent_of_root_is_invalid() { - name_chain_from_path(&Path::new("foo/../../baz")).unwrap(); + name_chain_from_path(Path::new("foo/../../baz")).unwrap(); } #[test] fn canonical_path_is_absolute() { let path = Path::new("foo/bar/../baz"); - let names = name_chain_from_path(&path).unwrap(); + let names = name_chain_from_path(path).unwrap(); assert_eq!(path_from_name_chain(&names), PathBuf::from("/foo/baz")); } } diff --git a/src/internal/stream.rs b/src/internal/stream.rs index c139e2a..bf2bdde 100644 --- a/src/internal/stream.rs +++ b/src/internal/stream.rs @@ -1,4 +1,4 @@ -use crate::internal::{consts, MiniAllocator, ObjType, SectorInit, Timestamp}; +use crate::internal::{consts, MiniAllocator, ObjType, SectorInit}; use std::cell::RefCell; use std::io::{self, BufRead, Read, Seek, SeekFrom, Write}; use std::rc::{Rc, Weak}; @@ -385,7 +385,6 @@ fn write_data_to_stream( minialloc.with_dir_entry_mut(stream_id, |dir_entry| { dir_entry.start_sector = new_start_sector; dir_entry.stream_len = new_stream_len; - dir_entry.modified_time = Timestamp::now(); }) } @@ -481,7 +480,6 @@ fn resize_stream( minialloc.with_dir_entry_mut(stream_id, |dir_entry| { dir_entry.start_sector = new_start_sector; dir_entry.stream_len = new_stream_len; - dir_entry.modified_time = Timestamp::now(); }) } diff --git a/src/lib.rs b/src/lib.rs index 9929c05..a0e9ec1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -571,7 +571,8 @@ impl CompoundFile { ) -> io::Result> { let mut header = Header { version, - num_dir_sectors: 1, + // 2.2 requires this to be zero in V3 + num_dir_sectors: if version == Version::V3 { 0 } else { 1 }, num_fat_sectors: 1, first_dir_sector: 1, first_minifat_sector: consts::END_OF_CHAIN, @@ -972,7 +973,7 @@ mod tests { let mut data = Vec::::new(); let mut header = Header { version, - num_dir_sectors: 1, + num_dir_sectors: 0, num_fat_sectors: 1, first_dir_sector: 1, first_minifat_sector: consts::END_OF_CHAIN, diff --git a/tests/basic.rs b/tests/basic.rs index e506009..75434bf 100644 --- a/tests/basic.rs +++ b/tests/basic.rs @@ -643,7 +643,7 @@ fn truncate_stream() { assert_eq!(stream.seek(SeekFrom::Start(6000)).unwrap(), 6000); stream.set_len(7000).unwrap(); assert_eq!(stream.len(), 7000); - assert_eq!(stream.seek(SeekFrom::Current(0)).unwrap(), 6000); + assert_eq!(stream.stream_position().unwrap(), 6000); stream.set_len(5000).unwrap(); assert_eq!(stream.len(), 5000); stream.write_all(&vec![b'x'; 1000]).unwrap(); @@ -672,13 +672,13 @@ fn extend_stream() { assert_eq!(stream.seek(SeekFrom::Start(1000)).unwrap(), 1000); stream.write_all(&vec![b'y'; 500]).unwrap(); assert_eq!(stream.len(), 2000); - assert_eq!(stream.seek(SeekFrom::Current(0)).unwrap(), 1500); + assert_eq!(stream.stream_position().unwrap(), 1500); stream.set_len(5000).unwrap(); assert_eq!(stream.len(), 5000); - assert_eq!(stream.seek(SeekFrom::Current(0)).unwrap(), 1500); + assert_eq!(stream.stream_position().unwrap(), 1500); stream.write_all(&vec![b'z'; 500]).unwrap(); assert_eq!(stream.len(), 5000); - assert_eq!(stream.seek(SeekFrom::Current(0)).unwrap(), 2000); + assert_eq!(stream.stream_position().unwrap(), 2000); } let cursor = comp.into_inner(); diff --git a/tests/malformed.rs b/tests/malformed.rs index b1ef561..db9f645 100644 --- a/tests/malformed.rs +++ b/tests/malformed.rs @@ -31,7 +31,7 @@ where // Checks to see if a file can be walked over and read properly, or fail if it can not be read fn can_read(path: &Path) { - let data = std::fs::read(&path).unwrap(); + let data = std::fs::read(path).unwrap(); let cursor = Cursor::new(data); let mut cfb = match CompoundFile::open(cursor) {