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

fix(cd): on android/termux fails to cd into /sdcard #10329

Merged
merged 1 commit into from
Dec 19, 2023

Conversation

hardfau1t
Copy link
Contributor

@hardfau1t hardfau1t commented Sep 12, 2023

fix on android/termux fails to cd into /sdcard or any directory that user has access via group

fixes #8095

I am not aware how this works on other platform so feel free to modify this pr or even close it if it is not correct

Description

on android or on linux to check if the user belongs to given directory group, use libc::getgroups function

User-Facing Changes

NA

Tests + Formatting

After Submitting

Copy link
Collaborator

@WindSoilder WindSoilder left a comment

Choose a reason for hiding this comment

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

Hi, thanks for your pr, I've leaved some comments, would you please have a look?

@@ -271,7 +271,14 @@ fn have_permission(dir: impl AsRef<Path>) -> PermissionResult<'static> {
}
}

#[cfg(unix)]
#[cfg(any(target_os = "linux", target_os = "android"))]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not really sure for this, the pr is handled for android, so it should be #[cfg(target_os = "android")]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this works for both linux and android, this implementation of any_group is more efficient than former one, but i wasn't sure whether osx comes under linux or not and whether this logic works on osx or not, so considered for only linux and android

user_groups.iter().any(|gid| gid.as_raw() == owner_group)
}

#[cfg(all(unix, not(any(target_os = "linux", target_os = "android"))))]
Copy link
Collaborator

Choose a reason for hiding this comment

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

So this can be [cfg(all(unix, not(target_os = "android")))]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as above, this more efficient way of checking group for linux can done using above implementation so

crates/nu-command/src/filesystem/util.rs Show resolved Hide resolved
crates/nu-command/src/filesystem/util.rs Show resolved Hide resolved
cd-fix.patch Outdated Show resolved Hide resolved
Copy link
Member

@sholderbach sholderbach left a comment

Choose a reason for hiding this comment

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

I don't have a setup to validate that this can resolve the access issues for Android but things sound good to me to simplify getting the groups on Linux (without taking the detour of inquiring the username). Implementation looks safe to me,

Don't have the system knowledge to say whether we could do the same on MacOS or the BSDs.

or any directory that user has access via group
on android or on linux to check if the user belongs to given directory group, use libc::getgroups function

Co-authored-by: Stefan Holderbach <[email protected]>

rfmt
Copy link
Collaborator

@WindSoilder WindSoilder left a comment

Choose a reason for hiding this comment

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

OK, thank you for your explanation. Then it looks good to me :-D

@WindSoilder
Copy link
Collaborator

And BTW, please don't rebase and force-push the branch during a pr, in case we can track changes in pr more easily :)

For more information you can read: https://amtoine.github.io/posts/you-shall-not-rebase/

@WindSoilder WindSoilder merged commit 729373a into nushell:main Dec 19, 2023
19 checks passed
dmatos2012 pushed a commit to dmatos2012/nushell that referenced this pull request Feb 20, 2024
fix on android/termux fails to cd into /sdcard or any directory that
user has access via group

fixes nushell#8095

I am not aware how this works on other platform so feel free to modify
this pr or even close it if it is not correct

# Description
on android or on linux to check if the user belongs to given directory
group, use `libc::getgroups` function

# User-Facing Changes
NA
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.

Cannot cd into /storage/emulated/0 and any subdirectories of it on Termux
3 participants