Skip to content

tail: Do not panic in path.is_tailable() check, but return false instead#3919

Closed
Joining7943 wants to merge 2 commits intouutils:mainfrom
Joining7943:tail-try-fix-panic-bad-file-descriptor
Closed

tail: Do not panic in path.is_tailable() check, but return false instead#3919
Joining7943 wants to merge 2 commits intouutils:mainfrom
Joining7943:tail-try-fix-panic-bad-file-descriptor

Conversation

@Joining7943
Copy link
Copy Markdown
Contributor

I'm just trying something here to deal with the spontanously occurring stdin bad file descriptor error on macos.

@Joining7943 Joining7943 marked this pull request as draft September 9, 2022 22:09
@Joining7943
Copy link
Copy Markdown
Contributor Author

I wasn't able to reproduce the bad file descriptor error. However, I've added debug output in case we're running into the todo(), so maybe we have chance to figure out what's going wrong.

Comment thread src/uu/tail/src/tail.rs
/// Return true if `path` is is a file type that can be tailed
fn is_tailable(&self) -> bool {
self.is_file() || self.exists() && self.metadata().unwrap().is_tailable()
self.is_file() || self.exists() && self.metadata().map_or(false, |meta| meta.is_tailable())
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 call to metadata() will return an error if user lacks permissions or the path does not exist. However, is_file() and exists() already return false if user cannot access metadata. So this unwrap should never be triggered.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

But that's what happened

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.

Then there could be an issue with time-of-check / time-of-use. You could try try_exists() instead of exists(), but it's only available in rust 1.63

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Why do you want to stick to unwrap()?

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.

Silencing this error doesn't feel right.
This unwrap triggers, but (according to documentation) it shouldn't, which means there's an issue somewhere up in the call stack.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's not about silencing the error but instead returning such a path as untailable, that's what the signature and name of the method states. No surprises.

Copy link
Copy Markdown
Contributor

@niyaznigmatullin niyaznigmatullin Sep 12, 2022

Choose a reason for hiding this comment

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

Why not just

fn is_tailable(&self) -> bool {
    self.metadata().map_or(false, |meta| meta.is_tailable())
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point

@sylvestre
Copy link
Copy Markdown
Contributor

Sorry but it is now conflicting

@Joining7943
Copy link
Copy Markdown
Contributor Author

No problem :)

@sylvestre
Copy link
Copy Markdown
Contributor

@Joining7943 should we abandon this PR?

@Joining7943
Copy link
Copy Markdown
Contributor Author

I'll close this one.

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.

4 participants