termux / termux-app

Termux - a terminal emulator application for Android OS extendible by variety of packages.
https://f-droid.org/en/packages/com.termux
Other
35.48k stars 3.72k forks source link

[Bug]: Can't manipulate files from external app #2415

Open ghost opened 2 years ago

ghost commented 2 years ago

Problem description

I use the Acode app to edit files on Termux. If I try to delete a non-empty Termux directory using Acode app, then it shows a FileNotFoundException error. However, if the directory is empty, or is a file, then it can be deleted without any error. However, I can never rename or cut any file or directory in Termux using the Acode app, doing so shows the same error. The bug is not in Acode app, but maybe in Termux (or maybe a restriction in the Android framework?). I can manipulate (delete/cut/paste) any file or directory in the device internal storage without any single error from Acode app. I also tried with other code editors (like QuickEdit), and the same happens.

Steps to reproduce the behavior.

Suppose, I have a folder named Projects in the home directory. Projects folder contains many other folders and files in it: ~/ IMG_20211122_204209

Now if I try to delete (or rename or cut or copy) the Projects folder: Screenshot_2021-11-22-20-40-55-536_com foxdebug acode

It shows error: Screenshot_2021-11-22-20-41-01-737_com foxdebug acode

What is the expected behavior?

I should be able to rename, cut, copy, paste any file or directory in Termux from any outside app.

System information

tareksander commented 2 years ago

That is definitely a Termux bug. You also can't delete a folder with files in it from the file explorer. This line is likely responsible for it. The delete method only works for empty directories. Implementing a recursive delete for directories should fix it.

For renaming and moving the Android storage framework has special methods which are just not implemented in Termux. There is already a pull request for that.

ghost commented 2 years ago

That is definitely a Termux bug. You also can't delete a folder with files in it from the file explorer. This line is likely responsible for it. The delete method only works for empty directories. Implementing a recursive delete for directories should fix it.

For renaming and moving the Android storage framework has special methods which are just not implemented in Termux. There is already a pull request for that.

So why not the PR is getting merged? I can see there is no problem merging it.

agnostic-apollo commented 2 years ago

So why not the PR is getting merged?

I didn't get time to look into SAF to merge it. Moreover, the termux-shared library provides FileUtils, which are more reliable and safe to use than directly using File API like "normally" done, like done in PR, specially for symlinks. So such functions should ideally be re-written with FileUtils functions. I'll try taking time to do that, if someone else doesn't.

https://github.com/termux/termux-app/blob/v0.117/termux-shared/src/main/java/com/termux/shared/file/filesystem/FileTypes.java#L36

ghost commented 2 years ago

@Hax4us is this issue solved? If solved then when I'll get the Termux release with this fix?

agnostic-apollo commented 2 years ago

The pull request #2538 is already open for it. You can grab github actions builds at https://github.com/termux/termux-app/actions/runs/1728733273. Should be available in next release whenever that happens, assuming pull request is approved and merged.

PiprTuff commented 2 years ago

Any progress on this?