Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FileManagerThread #11029

Merged
merged 1 commit into from May 11, 2016
Merged

Add FileManagerThread #11029

merged 1 commit into from May 11, 2016

Conversation

@izgzhen
Copy link
Contributor

izgzhen commented May 5, 2016

This is intended to support the File API implementation. Basically an event loop with three kinds of messages:

  • Select a file
  • Read a file with ID
  • Delete the ID from manager-owned map

The design decision in this PR is not the final (or best I think) version, welcome reviews :)

TODOs:

  • Add multiple file selection

This change is Reviewable

@highfive
Copy link

highfive commented May 5, 2016

Heads up! This PR modifies the following files:

  • @KiChjang: components/net/filemanager_thread.rs, components/net/lib.rs, components/net_traits/lib.rs, components/net_traits/lib.rs, components/net_traits/Cargo.toml, components/net_traits/Cargo.toml, components/net_traits/filemanager_thread.rs, components/net_traits/filemanager_thread.rs
@highfive
Copy link

highfive commented May 5, 2016

warning Warning warning

  • These commits modify net code, but no tests are modified.Please consider adding a test!
@izgzhen
Copy link
Contributor Author

izgzhen commented May 5, 2016

@Manishearth.
Related: #10851

@Manishearth Manishearth assigned Manishearth and unassigned pcwalton May 5, 2016
.and_then(|systime| systime.elapsed().map_err(|_| ()))
.and_then(|elapsed| Ok(elapsed.as_secs()));

let filename = path.file_name().and_then(|filename| filename.to_str())

This comment has been minimized.

@Manishearth

Manishearth May 5, 2016

Member

We should probably store this as a path, filenames aren't necessarily utf8.

This comment has been minimized.

@izgzhen

izgzhen May 6, 2016

Author Contributor

The problem is that both Path and OsStr don't implement the Serialize trait.

This comment has been minimized.

@Manishearth

Manishearth May 6, 2016

Member

PathBuf has an impl. Path/OsStr are slices.

If that doesn't work, just use a byte vector and work on getting an impl upstream in serde.

This comment has been minimized.

@izgzhen

izgzhen May 6, 2016

Author Contributor

OK, I will see if I can make OsString and PathBuf serializable in upstream.

};
}

fn read_file(&mut self, sender: IpcSender<FileManagerResult<Vec<u8>>>, id: Uuid) {

This comment has been minimized.

@Manishearth

Manishearth May 5, 2016

Member

This should probably send chunks. Not necessary right now, but eventually.

@Manishearth
Copy link
Member

Manishearth commented May 5, 2016

LGTM with the path change.

@izgzhen izgzhen force-pushed the izgzhen:filemanager_thread branch from c2add7e to de4d077 May 5, 2016
@highfive
Copy link

highfive commented May 5, 2016

New code was committed to pull request.

@izgzhen izgzhen force-pushed the izgzhen:filemanager_thread branch from de4d077 to 5c212bd May 6, 2016
@highfive
Copy link

highfive commented May 6, 2016

New code was committed to pull request.

@izgzhen izgzhen force-pushed the izgzhen:filemanager_thread branch from 5c212bd to 4f76350 May 6, 2016
@highfive
Copy link

highfive commented May 6, 2016

New code was committed to pull request.

@izgzhen izgzhen force-pushed the izgzhen:filemanager_thread branch from 4f76350 to 06edf6d May 6, 2016
@highfive
Copy link

highfive commented May 6, 2016

New code was committed to pull request.

@izgzhen izgzhen force-pushed the izgzhen:filemanager_thread branch from 06edf6d to fcc8be4 May 8, 2016
@highfive
Copy link

highfive commented May 8, 2016

New code was committed to pull request.


pub struct FileManager {
receiver: IpcReceiver<FileManagerThreadMsg>,
idmap: RefCell<HashMap<Uuid, String>>,

This comment has been minimized.

@Manishearth

Manishearth May 11, 2016

Member

String -> PathBuf?

This comment has been minimized.

@izgzhen

izgzhen May 11, 2016

Author Contributor

Currently, the libnfd returns a String in this way: CString::from_raw(*out_path).into_string(). Maybe there is encoding checking stuff. I will take a look at this.

This comment has been minimized.

@Manishearth

Manishearth May 11, 2016

Member

I suspect we should convert from CString to OSString to Path directly.

This comment has been minimized.

@izgzhen

izgzhen May 11, 2016

Author Contributor

Looks like a vital piece of conversion is missing: https://doc.servo.org/src/std/up/src/libstd/ffi/os_str.rs.html#59

impl FileManager {
fn select(&mut self, sender: SelectedPort) {
// TODO: Pull the dialog UI in and get selected
match sender {

This comment has been minimized.

@Manishearth

Manishearth May 11, 2016

Member

I sort of feel that this would be better as two functions with no SelectedPort, and have the dialog code take an argument specifying single or multiple.

This comment has been minimized.

@izgzhen

izgzhen May 11, 2016

Author Contributor

Do you mean split FileManager::select into two?

self.idmap.borrow_mut().insert(id, file_path.to_string());

// Unix Epoch: https://doc.servo.org/std/time/constant.UNIX_EPOCH.html
let epoch = handler.metadata().and_then(|metadata| metadata.modified()).map_err(|_| ())

This comment has been minimized.

@Manishearth

Manishearth May 11, 2016

Member

probably should leave a note about mtime vs ctime, iirc we haven't made that decision yet

}
}

fn create_entry(&mut self, file_path: &str) -> Option<(Uuid, PathBuf, u64)> {

This comment has been minimized.

@Manishearth

Manishearth May 11, 2016

Member

file_path should be Path or perhaps PathBuf

};
}

fn delete_fileid(&mut self, id: Uuid) {

This comment has been minimized.

@Manishearth

Manishearth May 11, 2016

Member

delete_file

This comment has been minimized.

@izgzhen

izgzhen May 11, 2016

Author Contributor

I thought about this name before as well, and I doubt if this name is kind of misleading?

This comment has been minimized.

@Manishearth

Manishearth May 11, 2016

Member

Nah, just consistency. This isn't really important, so feel free to keep it as is if you like this name.

@izgzhen izgzhen force-pushed the izgzhen:filemanager_thread branch from fcc8be4 to c618ee2 May 11, 2016
@highfive
Copy link

highfive commented May 11, 2016

New code was committed to pull request.

@Manishearth
Copy link
Member

Manishearth commented May 11, 2016

@bors r+

@KiChjang
Copy link
Member

KiChjang commented May 11, 2016

@bors-servo r=Manishearth

@bors-servo
Copy link
Contributor

bors-servo commented May 11, 2016

📌 Commit c618ee2 has been approved by Manishearth

@bors-servo
Copy link
Contributor

bors-servo commented May 11, 2016

Testing commit c618ee2 with merge b61ad41...

bors-servo added a commit that referenced this pull request May 11, 2016
Add FileManagerThread

This is intended to support the File API implementation. Basically an event loop with three kinds of messages:

+ Select a file
+ Read a file with ID
+ Delete the ID from manager-owned map

The design decision in this PR is not the final (or best I think) version, welcome reviews :)

TODOs:

- [x] Add multiple file selection

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11029)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented May 11, 2016

@bors-servo bors-servo merged commit c618ee2 into servo:master May 11, 2016
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@izgzhen
Copy link
Contributor Author

izgzhen commented May 11, 2016

Ping issue #11131

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

7 participants
You can’t perform that action at this time.