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

Request termux-saf-realpath and termux-saf-realname feature #498

Open
knyipab opened this issue Mar 14, 2022 · 2 comments
Open

Request termux-saf-realpath and termux-saf-realname feature #498

knyipab opened this issue Mar 14, 2022 · 2 comments

Comments

@knyipab
Copy link

knyipab commented Mar 14, 2022

I really appreciate the new SAF API. On top of the current utils, it would be good to have realpath equivalent and get name of the file.
Feature description

  • termux-saf-realpath returns the URI in path. If it is online storage (e.g. GDrive), then perhaps return a empty string
  • termux-saf-realname returns to name of the file
    Reference implementation
    Nasib's answer in this stackoverflow post seems promising to handle media files.
    Many more stackoverflow posts should help.

I may make pull requests if it's preferred and when I have time to write and test the codes. Thanks!

@knyipab knyipab changed the title Request termux-saf-realpath and termux-saf-realname feature Request termux-saf-realpath and termux-saf-realname feature Mar 14, 2022
@tareksander
Copy link
Member

  • termux-saf-realname returns to name of the file

You can do that with termux-saf-stat. I recommend jq to use JSON in the shell, it's also in the Termux repo.
To get the name just use termux-saf-stat URI | jq -r '.name'.

  • termux-saf-realpath returns the URI in path. If it is online storage (e.g. GDrive), then perhaps return a empty string

Do you mean the path of the real file? There may not be a real file involved, only for the MediaStore, which you can already access with termux-setup-storage, and for the SD card and internal storage, which you can't access without the SAF or without root anyways.

@knyipab
Copy link
Author

knyipab commented Mar 15, 2022

Hi. Thanks a lot for the answer in realname!

For realpath, the use case is below:
Let's say a Termux program asks a user to pick a folder (termux-saf-managedir) or a file (termux-storage-get). If the returned URI actually refers to a file/folder under the shared storage granted by termux-setup-storage, it would be great to have termux-saf-realpath to convert the URI back to file path and avoid the hassle handling URI. If it isn't, perhaps return a failure (like unix realpath can fail).

I, personally, highly prefer such way Termux interact with user (in GUI) to specify which file/folder in shared storage to work on. So SAFAPI and StorageGetAPI can do more than just granting URI access, but also offer the functionality "Open ..." resembling many desktop GUI applications (this is still a gap in Termux. It can't be done with am start, neither app_process)

Note that termux-storage-get does not return a URI in the current implementation, so I made a pull requests here to empower the tool. I could trim some functionalities if that pull request is too much.

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

No branches or pull requests

2 participants