Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/windirstat/ntfs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Finck <colin@reactos.org>2021-09-17 20:29:44 +0300
committerColin Finck <colin@reactos.org>2021-09-17 20:29:44 +0300
commit270127a5b852e27d88ace5be0c49ab04368a1f1b (patch)
treef0d5238d4227d29122dd020446f16ccd8c20426b
parentc45b7cc2af981f77d9f043bd92e1017c1fe3bb2e (diff)
Remove an `Option` around the return value of `NtfsAttribute::name`.
There is no difference between an empty attribute name and no attribute name at all.
-rw-r--r--src/attribute.rs8
-rw-r--r--src/file.rs35
2 files changed, 12 insertions, 31 deletions
diff --git a/src/attribute.rs b/src/attribute.rs
index 55cd8e6..17eb855 100644
--- a/src/attribute.rs
+++ b/src/attribute.rs
@@ -157,18 +157,18 @@ impl<'n, 'f> NtfsAttribute<'n, 'f> {
///
/// Note that most NTFS attributes have no name and are distinguished by their types.
/// Use [`NtfsAttribute::ty`] to get the attribute type.
- pub fn name(&self) -> Option<Result<NtfsString<'f>>> {
+ pub fn name(&self) -> Result<NtfsString<'f>> {
if self.name_offset() == 0 || self.name_length() == 0 {
- return None;
+ return Ok(NtfsString(&[]));
}
- iter_try!(self.validate_name_sizes());
+ self.validate_name_sizes()?;
let start = self.offset + self.name_offset() as usize;
let end = start + self.name_length();
let string = NtfsString(&self.file.record_data()[start..end]);
- Some(Ok(string))
+ Ok(string)
}
fn name_offset(&self) -> u16 {
diff --git a/src/file.rs b/src/file.rs
index f2dff53..097eff0 100644
--- a/src/file.rs
+++ b/src/file.rs
@@ -113,17 +113,13 @@ impl<'n> NtfsFile<'n> {
/// Convenience function to get a $DATA attribute of this file.
///
- /// As NTFS supports multiple data streams per file, you can optionally specify a data stream
- /// name and NTFS will look up the corresponding $DATA attribute.
- /// If you specify `None` for `data_stream_name`, the default unnamed $DATA attribute will be looked
- /// up (commonly known as the "file data").
+ /// As NTFS supports multiple data streams per file, you can specify the name of the $DATA attribute
+ /// to look up.
+ /// Passing an empty string here looks up the default unnamed $DATA attribute (commonly known as the "file data").
///
/// If you need more control over which $DATA attribute is available and picked up,
/// you can use [`NtfsFile::attributes`] to iterate over all attributes of this file.
- pub fn data<'f>(
- &'f self,
- data_stream_name: Option<&str>,
- ) -> Option<Result<NtfsAttribute<'n, 'f>>> {
+ pub fn data<'f>(&'f self, data_stream_name: &str) -> Option<Result<NtfsAttribute<'n, 'f>>> {
// Create an iterator that emits all $DATA attributes.
let iter = self.attributes().filter(|attribute| {
// TODO: Replace by attribute.ty().contains() once https://github.com/rust-lang/rust/issues/62358 has landed.
@@ -134,25 +130,10 @@ impl<'n> NtfsFile<'n> {
});
for attribute in iter {
- match (attribute.name(), data_stream_name) {
- (None, None) => {
- // We found the unnamed $DATA attribute and are looking for the unnamed $DATA attribute.
- return Some(Ok(attribute));
- }
- (Some(Ok(name)), Some(data_stream_name)) => {
- // We found a named $DATA attribute and are looking for a named $DATA attribute.
- if data_stream_name == name {
- return Some(Ok(attribute));
- }
- }
- (Some(Err(e)), _) => {
- // We hit an error while fetching the $DATA attribute name.
- return Some(Err(e));
- }
- _ => {
- // In any other case, we didn't find what we are looking for.
- continue;
- }
+ let name = iter_try!(attribute.name());
+
+ if data_stream_name == name {
+ return Some(Ok(attribute));
}
}