Skip to content

Add partial implementation of mount#46

Open
lizhuohua wants to merge 15 commits intomesalock-linux:masterfrom
lizhuohua:master
Open

Add partial implementation of mount#46
lizhuohua wants to merge 15 commits intomesalock-linux:masterfrom
lizhuohua:master

Conversation

@lizhuohua
Copy link
Copy Markdown

Most LSB features are supported, except -v (print diagnostic messages), -n (mount without writing in /etc/mtab), and -s (ignore mount options not supported by a file system type). Also, user mountable devices are not supported yet.

Some tests need root privilege, they are marked as #[ignore]. To run them, use the following command: sudo cargo test root_test_mount -- --ignored --test-threads 1. (We have to disable parallel tests, because the tests will mount the same device.)

@codecov
Copy link
Copy Markdown

codecov bot commented Aug 22, 2018

Codecov Report

Merging #46 into master will decrease coverage by 0.93%.
The diff coverage is 2.28%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #46      +/-   ##
==========================================
- Coverage   19.95%   19.01%   -0.94%     
==========================================
  Files          46       47       +1     
  Lines        4680     5027     +347     
  Branches     1081     1183     +102     
==========================================
+ Hits          934      956      +22     
- Misses       3355     3663     +308     
- Partials      391      408      +17
Impacted Files Coverage Δ
libmesabox/src/lib.rs 59.01% <ø> (ø) ⬆️
libmesabox/src/lsb/mount/mod.rs 2.28% <2.28%> (ø)
libmesabox/src/posix/cat.rs 35.01% <0%> (-4.75%) ⬇️
libmesabox/src/gnu/arch.rs 71.42% <0%> (-3.58%) ⬇️
libmesabox/src/gnu/base32/common.rs 56.25% <0%> (ø) ⬆️
libmesabox/src/posix/head.rs 46.82% <0%> (-0.34%) ⬇️
libmesabox/src/posix/echo.rs 51.25% <0%> (+1.25%) ⬆️
libmesabox/src/posix/sh/ast.rs 27.52% <0%> (+0.07%) ⬆️
libmesabox/src/posix/sh/mod.rs 31.53% <0%> (+0.24%) ⬆️
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 17de43b...2f51827. Read the comment docs.

@mssun
Copy link
Copy Markdown
Contributor

mssun commented Sep 4, 2018

Can you refactor your code according to the dummy utility here? #47

Copy link
Copy Markdown
Contributor

@Arcterus Arcterus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reviewed like half of this PR. I don't have time to finish the rest right now, so I'm just giving you my current feedback. I'll try to get around to reviewing the rest this week.

Comment thread Cargo.toml Outdated
tar_util = ["libmesabox/tar_util"]
lsb = [
"tar_util"
"mount", "tar_util"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please split into multiple lines.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread libmesabox/Cargo.toml Outdated
tar_util = ["tar", "globset"]
lsb = [
"tar"
"mount", "tar"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please split into multiple lines.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

extern crate clap;
extern crate lazy_static;
extern crate libc;
extern crate nix;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please separate extern crate and use statements by an empty line.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread libmesabox/src/lsb/mount/mod.rs Outdated
}

impl Uuid {
fn new() -> MountResult<Self> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code for this and Label (and maybe more that I haven't looked at yet) is almost exactly the same. With how minor the differences are, the common code should be split out into a separate function.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I combined Label and Uuid together

Ok(Self { path_map: path_map })
}

fn get_device_path(&self, input: &OsString) -> MountResult<&Path> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue. This is almost exactly the same as for Label.

Comment thread libmesabox/src/lsb/mount/mod.rs Outdated
fn new(path: &str) -> MountResult<Self> {
// all of these files should exist and can be read, but just in case
let file = fs::File::open(path).or(Err(MountError::OpenFileError(String::from(path))))?;
let mut entries = Vec::new();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use vec![] instead of Vec::new().

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread libmesabox/src/lsb/mount/mod.rs Outdated
let file = fs::File::open(path).or(Err(MountError::OpenFileError(String::from(path))))?;
let mut entries = Vec::new();
for line in BufReader::new(file).lines() {
let line = line.or(Err(MountError::FSDescFileFormatError(String::from(path))))?;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think these files are guaranteed to be valid UTF-8, so I think using Strings here is wrong.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. If these files contain invalid UTF-8, the program will return an error. Now I use read_until to read them in bytes.

Comment thread libmesabox/src/lsb/mount/mod.rs Outdated
}
Some(_) => {}
}
let a: Vec<&str> = line.split_whitespace().collect();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than constructing a Vec, you can just use the iterator from line.split_whitespace() to get the data and if it returns None at some point than clearly you have less than six (6) columns. You can just do .count() after getting the data and see if there are exactly two (2) left columns.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread libmesabox/src/lsb/mount/mod.rs Outdated
Ok(Self { entries: entries })
}

fn get_output(&self, fs_type: &OsString) -> String {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, String seems wrong because the filesystem directory doesn't need to be valid UTF-8.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The returned string is used for output, and it is generated by to_string_lossy. I guess this is the only way to get a printable OsString.

Comment thread libmesabox/src/lsb/mount/mod.rs Outdated

impl MountOptions {
fn from_matches(matches: &clap::ArgMatches) -> MountResult<Self> {
let mut mount_list: Vec<Box<Mountable + Send>> = Vec::new();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend trying to find another way to store the data, as this setup requires dynamic dispatch. If you can't, I suppose it's fine for this utility as this part doesn't need to be super fast.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I defined an enum to do the dispatching.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants