Skip to content

Commit 14078b7

Browse files
Remove user attributes
The motivation for this change is to avoid increasing the interchange size with the larger data for files. The justification for removing it are the following: - They are not used anywhere - They were actually never written, so even if someone used them they did nothing when writing - Their usage was not documented at all
1 parent ebc798f commit 14078b7

7 files changed

Lines changed: 9 additions & 69 deletions

File tree

src/api.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ pub mod request {
227227
ReadDirFilesFirst:
228228
- location: Location
229229
- dir: PathBuf
230-
- user_attribute: Option<UserAttribute>
231230

232231
ReadDirFilesNext:
233232

@@ -279,7 +278,6 @@ pub mod request {
279278
WriteFile:
280279
- location: Location
281280
- path: PathBuf
282-
- user_attribute: Option<UserAttribute>
283281
- data: LargeMessage
284282

285283
UnsafeInjectKey:

src/client.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -577,13 +577,8 @@ pub trait FilesystemClient: PollClient {
577577
&mut self,
578578
location: Location,
579579
dir: PathBuf,
580-
user_attribute: Option<UserAttribute>,
581580
) -> ClientResult<'_, reply::ReadDirFilesFirst, Self> {
582-
self.request(request::ReadDirFilesFirst {
583-
dir,
584-
location,
585-
user_attribute,
586-
})
581+
self.request(request::ReadDirFilesFirst { dir, location })
587582
}
588583

589584
fn read_dir_files_next(&mut self) -> ClientResult<'_, reply::ReadDirFilesNext, Self> {
@@ -651,13 +646,11 @@ pub trait FilesystemClient: PollClient {
651646
location: Location,
652647
path: PathBuf,
653648
data: LargeMessage,
654-
user_attribute: Option<UserAttribute>,
655649
) -> ClientResult<'_, reply::WriteFile, Self> {
656650
self.request(request::WriteFile {
657651
location,
658652
path,
659653
data,
660-
user_attribute,
661654
})
662655
}
663656
}

src/service.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ impl<P: Platform> ServiceResources<P> {
378378
}
379379

380380
Request::ReadDirFilesFirst(request) => {
381-
let maybe_data = match filestore.read_dir_files_first(&request.dir, request.location, request.user_attribute.clone())? {
381+
let maybe_data = match filestore.read_dir_files_first(&request.dir, request.location)? {
382382
Some((data, state)) => {
383383
ctx.read_dir_files_state = Some(state);
384384
data

src/store/filestore.rs

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{
22
error::{Error, Result},
33
// service::ReadDirState,
44
store::{self, Store},
5-
types::{Location, Message, UserAttribute},
5+
types::{Location, Message},
66
Bytes,
77
};
88

@@ -17,7 +17,6 @@ pub struct ReadDirFilesState {
1717
real_dir: PathBuf,
1818
last: usize,
1919
location: Location,
20-
user_attribute: Option<UserAttribute>,
2120
}
2221

2322
use littlefs2::{
@@ -119,7 +118,6 @@ pub trait Filestore {
119118
&mut self,
120119
clients_dir: &PathBuf,
121120
location: Location,
122-
user_attribute: Option<UserAttribute>,
123121
) -> Result<Option<(Option<Message>, ReadDirFilesState)>>;
124122

125123
/// Continuation of `read_dir_files_first`.
@@ -271,7 +269,6 @@ impl<S: Store> Filestore for ClientFilestore<S> {
271269
&mut self,
272270
clients_dir: &PathBuf,
273271
location: Location,
274-
user_attribute: Option<UserAttribute>,
275272
) -> Result<Option<(Option<Message>, ReadDirFilesState)>> {
276273
if location != Location::Internal {
277274
return Err(Error::RequestNotAvailable);
@@ -289,35 +286,13 @@ impl<S: Store> Filestore for ClientFilestore<S> {
289286
//
290287
// Option<usize, Result<DirEntry>> -> ??
291288
.map(|(i, entry)| (i, entry.unwrap()))
292-
// skip over directories (including `.` and `..`)
293-
.filter(|(_, entry)| entry.file_type().is_file())
294-
// take first entry that meets requirements
295-
.find(|(_, entry)| {
296-
if let Some(user_attribute) = user_attribute.as_ref() {
297-
let mut path = dir.clone();
298-
path.push(entry.file_name());
299-
let attribute = fs
300-
.attribute(&path, crate::config::USER_ATTRIBUTE_NUMBER)
301-
.unwrap();
302-
303-
if let Some(attribute) = attribute {
304-
user_attribute == attribute.data()
305-
} else {
306-
false
307-
}
308-
} else {
309-
true
310-
}
311-
})
312-
// if there is an entry, construct the state that needs storing out of it,
313-
// and return the file's contents.
314-
// the client, and return both the entry and the state
289+
// skip over directories (including `.` and `..`) and take first file
290+
.find(|(_, entry)| entry.file_type().is_file())
315291
.map(|(i, entry)| {
316292
let read_dir_files_state = ReadDirFilesState {
317293
real_dir: dir.clone(),
318294
last: i,
319295
location,
320-
user_attribute,
321296
};
322297
// The semantics is that for a non-existent file, we return None (not an error)
323298
let data = store::read(self.store, location, entry.path()).ok();
@@ -340,7 +315,6 @@ impl<S: Store> Filestore for ClientFilestore<S> {
340315
real_dir,
341316
last,
342317
location,
343-
user_attribute,
344318
} = state;
345319
let fs = self.store.ifs();
346320

@@ -353,31 +327,13 @@ impl<S: Store> Filestore for ClientFilestore<S> {
353327
.skip(last + 1)
354328
// entry is still a Result :/ (see question in `read_dir_first`)
355329
.map(|(i, entry)| (i, entry.unwrap()))
356-
// skip over directories (including `.` and `..`)
357-
.filter(|(_, entry)| entry.file_type().is_file())
358-
// take first entry that meets requirements
359-
.find(|(_, entry)| {
360-
if let Some(user_attribute) = user_attribute.as_ref() {
361-
let mut path = real_dir.clone();
362-
path.push(entry.file_name());
363-
let attribute = fs
364-
.attribute(&path, crate::config::USER_ATTRIBUTE_NUMBER)
365-
.unwrap();
366-
if let Some(attribute) = attribute {
367-
user_attribute == attribute.data()
368-
} else {
369-
false
370-
}
371-
} else {
372-
true
373-
}
374-
})
330+
// skip over directories (including `.` and `..`) and take first file
331+
.find(|(_, entry)| entry.file_type().is_file())
375332
.map(|(i, entry)| {
376333
let read_dir_files_state = ReadDirFilesState {
377334
real_dir: real_dir.clone(),
378335
last: i,
379336
location,
380-
user_attribute,
381337
};
382338
// The semantics is that for a non-existent file, we return None (not an error)
383339
let data = store::read(self.store, location, entry.path()).ok();

src/tests.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -528,12 +528,7 @@ fn filesystem() {
528528

529529
let data = Bytes::from_slice(&[0; 20]).unwrap();
530530
block!(client
531-
.write_file(
532-
Location::Internal,
533-
PathBuf::from("test_file"),
534-
data.clone(),
535-
None
536-
)
531+
.write_file(Location::Internal, PathBuf::from("test_file"), data.clone())
537532
.expect("no client error"))
538533
.expect("no errors");
539534

src/types.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,5 +616,3 @@ pub enum SignatureSerialization {
616616
Raw,
617617
// Sec1,
618618
}
619-
620-
pub type UserAttribute = Bytes<MAX_USER_ATTRIBUTE_LENGTH>;

tests/virt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn run_test(data: u8) {
2424

2525
// ensure that no other client is messing with our filesystem
2626
while syscall!(client.uptime()).uptime < Duration::from_secs(1) {
27-
syscall!(client.write_file(location, path.clone(), write_data.clone(), None));
27+
syscall!(client.write_file(location, path.clone(), write_data.clone()));
2828
let read_data = syscall!(client.read_file(location, path.clone())).data;
2929
assert_eq!(write_data, read_data);
3030
}

0 commit comments

Comments
 (0)