8000 unexpand: show error message if a directory is specified · Issue #5845 · uutils/coreutils · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

unexpand: show error message if a directory is specified #5845

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

Closed
cakebaker opened this issue Jan 15, 2024 · 8 comments · Fixed by #5864
Closed

unexpand: show error message if a directory is specified #5845

cakebaker opened this issue Jan 15, 2024 · 8 comments · Fixed by #5864

Comments

@cakebaker
Copy link
Contributor

GNU unexpand shows an error if the user specifies a directory and returns 1 as exit code:

$ echo "content" > file
$ unexpand dir file
unexpand: dir: Is a directory
content
$ echo $?
1

uutils unexpand, on the other hand, doesn't output anything and returns 0 as exit code:

$ echo "content" > file
$ cargo run unexpand dir file
$ echo $?
0
@biplab5464
Copy link
Contributor
biplab5464 commented Jan 15, 2024

i will try to fix the issue

@biplab5464
Copy link
Contributor

biplab@BIPLAB:/project/coreutils/src/uu/unexpand/src$ cat file
content
biplab@BIPLAB:
/project/coreutils/src/uu/unexpand/src$ cat file1
a b
biplab@BIPLAB:/project/coreutils/src/uu/unexpand/src$ unexpand file1 file
a b
content
biplab@BIPLAB:
/project/coreutils/src/uu/unexpand/src$ cargo run file1 file
Compiling uu_unexpand v0.0.23 (/home/biplab/project/coreutils/src/uu/unexpand)
Finished dev [unoptimized + debuginfo] target(s) in 0.92s
Running /home/biplab/project/coreutils/target/debug/unexpand file1 file
a b

uutils unexpand only talking the first argument and ignoring the subsequent element
i think this issue need to be fixed first

@cakebaker
Copy link
Contributor Author

Yes, you are right, good catch! Do you want to work on it? Or should I open a ticket?

@biplab5464
Copy link
Contributor
biplab5464 commented Jan 16, 2024

i am a beginner so better open a ticket

i can try but i need time and help

@sudhackar
Copy link
Contributor

Hey @biplab5464

See

let files = match matches.get_one::<String>(options::FILE) {

the fix to get all the files to process would be here

Another recommendation - use triple backticks ``` to start a code block when you are trying to share some code - more help on markdown

@biplab5464
Copy link
Contributor
biplab5464 commented Jan 17, 2024

Thank you for Help

I have fix the issue for multiple files

now i am trying to fix the original issue

i am in little problem File::Open is not throwing any error if is a Directory so i tried this way

fn open(path: &str) -> UResult<BufReader<Box<dyn Read + 'static>>> {
    let file_buf;
    let filename = Path::new(path);
    if filename.is_dir() {
        Err()
    } else if path == "-" {
        Ok(BufReader::new(Box::new(stdin()) as Box<dyn Read>))
    } else {
        file_buf = File::open(path).map_err_context(|| path.to_string())?;
        Ok(BufReader::new(Box::new(file_buf) as Box<dyn Read>))
    }
}

i was unable to find what error to return

@cakebaker
Copy link
Contributor Author

I think you can return a USimpleError.

@cakebaker
Copy link
Contributor Author

@biplab5464 I opened a ticket for the issue you mentioned in a comment above: #5852

cakebaker pushed a commit that referenced this issue Jan 24, 2024
… specified

* unexpand: should allow multiple files #5852 and unexpand: show error message if a directory is specified #5845

* test file added for #5845 #5852

* test case test_multiple_files improve

* cakebaker suggestion for a better code #5845 #5852

---------

Co-authored-by: biplab5464 <biplab5464@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
0