-
-
Notifications
You must be signed in to change notification settings - Fork 173
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 size option (-s) in the ls
command
#1102
Conversation
* Lists the size of each file (in bytes) when `ls -s` is invoked
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! I left a few comments.
My top-level comment is that the default output of size should be in units of bytes, not in disk sectors. Kindly make that change and address my other comments, and then I can merge it in. Thanks!
applications/ls/src/lib.rs
Outdated
@@ -49,7 +58,12 @@ pub fn main(args: Vec<String>) -> isize { | |||
// Navigate to the path specified by first argument | |||
match path.get(&curr_wd) { | |||
Some(FileOrDir::Dir(dir)) => { | |||
print_children(&dir); | |||
if size_option { | |||
print_children(&dir, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment here, no need to duplicate code, just pass in size_option
directly as an argument.
kernel/fs_node/src/lib.rs
Outdated
@@ -190,4 +197,15 @@ impl FileOrDir { | |||
FileOrDir::Dir(_) => true, | |||
} | |||
} | |||
|
|||
/// Returns the size of the file in bytes, or directory disk space. | |||
pub fn get_file_size(file_or_dir: &FileOrDir) -> usize { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is redundant, see the existing len()
method for files (part of the KnownLength
trait). See my other comment about handling sizes for directories.
* Add '--' option in place for directory size * Remove remove redundant Kernel function and perform operation in `ls` appliciation instead
I have created the PR to the requested changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks! i left only one small comment about code duplication that you missed.
For future reference, kindly don't force push commits to your PR branch, as it removes all of my review comments (notice that they're all gone now). This makes it hard to track whether all of the comments have been addressed.
applications/ls/src/lib.rs
Outdated
if size_option && matches.free.is_empty() { | ||
print_children(&curr_wd, size_option); | ||
return 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this duplicated code block is unnecessary, you can remove it as it's redundant with the block below it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it I will remove that
Got it thank you! |
Nope, all you have to do is make another change, commit it to this same branch, and push it. Github will automatically show the new commit in this PR. |
Got it thanks - I won't force push |
I just removed the duplicated code block- thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks great!
This pull request is to add the
ls -s
option in the Theseus operating environment. Thels -s
is a standard linux command. It shows the sizes of files and directories in blocks, which is useful for getting a quick overview of file sizes. Below are some sample test cases:Default
ls
command still works: