Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions crates/rrg/src/action/get_file_contents_kmx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type Item = Result<OkItem, ErrorItem>;
/// Result of the `get_file_contents` action in case of success.
#[derive(Debug)]
pub struct OkItem {
/// Absolute path to the raw volume on which the file is located.
volume_path: std::path::PathBuf,
/// Path to the file this result corresponds to.
path: keramics_formats::ntfs::NtfsPath,
/// Byte offset of the file part sent to the blob sink.
Expand All @@ -44,6 +46,8 @@ pub struct OkItem {
/// Result of the `get_file_contents` action in case of an error.
#[derive(Debug)]
struct ErrorItem {
/// Absolute path to the raw volume on which the file is located.
volume_path: std::path::PathBuf,
/// Path to the file that cause the issue.
path: keramics_formats::ntfs::NtfsPath,
/// Error that occurred when working with the file.
Expand Down Expand Up @@ -111,6 +115,7 @@ where
Ok(file_entry) => file_entry,
Err(error) => {
session.reply(Err(ErrorItem {
volume_path: volume_path.clone(),
path,
error,
}))?;
Expand Down Expand Up @@ -143,6 +148,7 @@ where
Ok(file_data_stream) => file_data_stream,
Err(error) => {
session.reply(Err(ErrorItem {
volume_path: volume_path.clone(),
path: path.clone(),
error,
}))?;
Expand All @@ -167,6 +173,7 @@ where
Ok(_) => (),
Err(error) => {
session.reply(Err(ErrorItem {
volume_path: volume_path.clone(),
path: path.clone(),
error: FileError {
kind: FileErrorKind::Seek,
Expand All @@ -190,6 +197,7 @@ where
Ok(len_read) => len_read,
Err(error) => {
session.reply(Err(ErrorItem {
volume_path: volume_path.clone(),
path: path.clone(),
error: FileError {
kind: FileErrorKind::Read,
Expand All @@ -209,6 +217,7 @@ where

session.send(crate::Sink::Blob, blob)?;
session.reply(Ok(OkItem {
volume_path: volume_path.clone(),
path: path.clone(),
offset,
len: len_read,
Expand Down Expand Up @@ -287,6 +296,7 @@ impl crate::response::Item for Item {
.map(|comp| String::from_utf16_lossy(&comp.elements))
);

proto.set_volume_path(item.volume_path.into());
proto.set_path(path.into());
proto.set_offset(item.offset);
proto.set_length(item.len as u64);
Expand All @@ -299,6 +309,7 @@ impl crate::response::Item for Item {
.map(|comp| String::from_utf16_lossy(&comp.elements))
);

proto.set_volume_path(item.volume_path.into());
proto.set_path(path.into());
proto.set_error(item.error.to_string());
}
Expand Down Expand Up @@ -374,6 +385,7 @@ mod tests {

let error_item = session.reply::<Item>(0)
.as_ref().unwrap_err();
assert_eq!(error_item.volume_path, ntfs_file.path());
assert_eq!(error_item.path, "\\idonotexist".into());
assert_eq!(error_item.error.kind, FileErrorKind::OpenEntry);
}
Expand Down Expand Up @@ -403,6 +415,7 @@ mod tests {

let error_item = session.reply::<Item>(0)
.as_ref().unwrap_err();
assert_eq!(error_item.volume_path, ntfs_file.path());
assert_eq!(error_item.path, "\\dir".into());
assert_eq!(error_item.error.kind, FileErrorKind::OpenDataStream);
}
Expand Down Expand Up @@ -458,6 +471,8 @@ mod tests {

let item = session.reply::<Item>(0)
.as_ref().unwrap();
assert_eq!(item.volume_path, ntfs_file.path());
assert_eq!(item.path, keramics_formats::ntfs::NtfsPath::from("\\file"));
assert_eq!(item.offset, 0);
assert_eq!(item.len, b"0123456789".len());

Expand Down Expand Up @@ -494,6 +509,8 @@ mod tests {

let item = session.reply::<Item>(0)
.as_ref().unwrap();
assert_eq!(item.volume_path, ntfs_file.path());
assert_eq!(item.path, keramics_formats::ntfs::NtfsPath::from("\\file"));
assert_eq!(item.offset, 5);
assert_eq!(item.len, 5);

Expand Down Expand Up @@ -530,6 +547,8 @@ mod tests {

let item = session.reply::<Item>(0)
.as_ref().unwrap();
assert_eq!(item.volume_path, ntfs_file.path());
assert_eq!(item.path, keramics_formats::ntfs::NtfsPath::from("\\file"));
assert_eq!(item.offset, 0);
assert_eq!(item.len, 5);

Expand Down Expand Up @@ -566,6 +585,8 @@ mod tests {

let item = session.reply::<Item>(0)
.as_ref().unwrap();
assert_eq!(item.volume_path, ntfs_file.path());
assert_eq!(item.path, keramics_formats::ntfs::NtfsPath::from("\\file"));
assert_eq!(item.offset, 0xb33f);
assert_eq!(item.len, MAX_BLOB_LEN);

Expand Down Expand Up @@ -727,18 +748,21 @@ mod tests {

let item_34 = session.reply::<Item>(0)
.as_ref().unwrap();
assert_eq!(item_34.volume_path, ntfs_file.path());
assert_eq!(item_34.path, "\\foo".into());
assert_eq!(item_34.offset, 3);
assert_eq!(item_34.len, 2);

let item_78 = session.reply::<Item>(1)
.as_ref().unwrap();
assert_eq!(item_78.volume_path, ntfs_file.path());
assert_eq!(item_78.path, "\\foo".into());
assert_eq!(item_78.offset, 7);
assert_eq!(item_78.len, 2);

let item_9 = session.reply::<Item>(2)
.as_ref().unwrap();
assert_eq!(item_9.volume_path, ntfs_file.path());
assert_eq!(item_9.path, "\\foo".into());
assert_eq!(item_9.offset, 9);
assert_eq!(item_9.len, 1);
Expand Down
5 changes: 5 additions & 0 deletions crates/rrg/src/action/get_file_metadata_kmx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct Args {

/// Result of the `get_file_metadata_kmx` action.
pub struct Item {
volume_path: std::path::PathBuf,
path: keramics_formats::ntfs::NtfsPath,
file_type: FileType,
modified: Option<std::time::SystemTime>,
Expand Down Expand Up @@ -222,6 +223,7 @@ where
log::debug!("sending metadata for '{:?}'", cur.path);

session.reply(Item {
volume_path: volume_path.clone(),
path: cur.path.clone(),
file_type,
modified,
Expand Down Expand Up @@ -345,6 +347,7 @@ impl crate::response::Item for Item {
);

let mut proto = rrg_proto::get_file_metadata_kmx::Result::new();
proto.set_volume_path(self.volume_path.into());
proto.set_path(path.into());
proto.mut_metadata().set_type(self.file_type.into());
proto.mut_metadata().set_size(self.len);
Expand Down Expand Up @@ -520,6 +523,7 @@ mod tests {
assert_eq!(session.reply_count(), 1);

let item = session.reply::<Item>(0);
assert_eq!(item.volume_path, ntfs_file.path());
assert_eq!(item.path, keramics_formats::ntfs::NtfsPath::from("\\link"));
assert_eq!(item.file_type, FileType::Symlink);
}
Expand Down Expand Up @@ -551,6 +555,7 @@ mod tests {
assert_eq!(session.reply_count(), 1);

let item = session.reply::<Item>(0);
assert_eq!(item.volume_path, ntfs_file.path());
assert_eq!(item.path, keramics_formats::ntfs::NtfsPath::from("\\link"));
assert_eq!(item.file_type, FileType::Symlink);
}
Expand Down
10 changes: 10 additions & 0 deletions crates/rrg/src/action/get_file_sha256_kmx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub struct Args {

/// Result of the `get_file_sha256_kmx` action.
struct Item {
/// Absolute path to the raw volume on which the file is located.
volume_path: std::path::PathBuf,
/// Path of the file this result corresponds to.
path: keramics_formats::ntfs::NtfsPath,
/// Byte offset from which the file content was hashed.
Expand Down Expand Up @@ -119,6 +121,7 @@ where
let sha256 = <[u8; 32]>::from(sha256.finalize());

session.reply(Item {
volume_path: volume_path.clone(),
path: args.path.clone(),
offset,
len: len_read_total,
Expand Down Expand Up @@ -182,6 +185,7 @@ impl crate::response::Item for Item {
.map(|comp| String::from_utf16_lossy(&comp.elements))
);

proto.set_path(self.volume_path.into());
proto.set_path(path.into());
proto.set_offset(self.offset);
proto.set_length(self.len);
Expand Down Expand Up @@ -284,6 +288,7 @@ mod tests {
assert_eq!(session.reply_count(), 1);

let item = session.reply::<Item>(0);
assert_eq!(item.volume_path, ntfs_file.path());
assert_eq!(item.path, "\\foo".into());
assert_eq!(item.offset, 0);
assert_eq!(item.len, u64::try_from(b"hello\n".len()).unwrap());
Expand Down Expand Up @@ -321,6 +326,7 @@ mod tests {
assert_eq!(session.reply_count(), 1);

let item = session.reply::<Item>(0);
assert_eq!(item.volume_path, ntfs_file.path());
assert_eq!(item.path, "\\foo".into());
assert_eq!(item.offset, u64::try_from(b"<ignore me>".len()).unwrap());
assert_eq!(item.len, u64::try_from(b"hello\n".len()).unwrap());
Expand Down Expand Up @@ -361,6 +367,7 @@ mod tests {
assert_eq!(session.reply_count(), 2);

let item_foo = session.reply::<Item>(0);
assert_eq!(item_foo.volume_path, ntfs_file.path());
assert_eq!(item_foo.path, "\\foo".into());
assert_eq!(item_foo.offset, 9);
assert_eq!(item_foo.len, 3);
Expand All @@ -373,6 +380,7 @@ mod tests {
]);

let item_bar = session.reply::<Item>(1);
assert_eq!(item_bar.volume_path, ntfs_file.path());
assert_eq!(item_bar.path, "\\foo".into());
assert_eq!(item_bar.offset, 21);
assert_eq!(item_bar.len, 3);
Expand Down Expand Up @@ -410,6 +418,7 @@ mod tests {
assert_eq!(session.reply_count(), 1);

let item = session.reply::<Item>(0);
assert_eq!(item.volume_path, ntfs_file.path());
assert_eq!(item.path, "\\foo".into());
assert_eq!(item.offset, 0);
assert_eq!(item.len, u64::try_from(b"hello\n".len()).unwrap());
Expand Down Expand Up @@ -448,6 +457,7 @@ mod tests {
assert_eq!(session.reply_count(), 1);

let item = session.reply::<Item>(0);
assert_eq!(item.volume_path, ntfs_file.path());
assert_eq!(item.path, "\\foo".into());
assert_eq!(item.offset, 0);
assert_eq!(item.len, 13371337);
Expand Down
6 changes: 6 additions & 0 deletions proto/rrg/action/get_file_contents_kmx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ message Args {
}

message Result {
// Absolute path to the raw volume on which the file is located.
//
// This will be the original volume path specified in the arguments, if avail-
// lable or the inferred path if only volume mount path is given.
rrg.fs.Path volume_path = 6;

// Path to the file this result corresponds to.
rrg.fs.Path path = 4;

Expand Down
6 changes: 6 additions & 0 deletions proto/rrg/action/get_file_metadata_kmx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ message Args {
}

message Result {
// Absolute path to the raw volume on which the file is located.
//
// This will be the original volume path specified in the arguments, if avail-
// lable or the inferred path if only volume mount path is given.
rrg.fs.Path volume_path = 3;

// Path to the file.
//
// This is the original root path of the file as specified in the arguments,
Expand Down
6 changes: 6 additions & 0 deletions proto/rrg/action/get_file_sha256_kmx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ message Args {
}

message Result {
// Absolute path to the raw volume on which the file is located.
//
// This will be the original volume path specified in the arguments, if avail-
// lable or the inferred path if only volume mount path is given.
rrg.fs.Path volume_path = 5;

// Path (relative to the volume root) to the file this result corresponds to.
rrg.fs.Path path = 1;

Expand Down
Loading