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

[Bug]: How to delete a file with a weird name? #3228

Closed
qidizi opened this issue Feb 3, 2023 · 11 comments
Closed

[Bug]: How to delete a file with a weird name? #3228

qidizi opened this issue Feb 3, 2023 · 11 comments
Labels

Comments

@qidizi
Copy link

qidizi commented Feb 3, 2023

Problem description

archive same chinese/japanese/english/thai/Russian files into a.zip with mixplorer app;
then unzip a.zip from termux;
rm -rfv *.flac
ls --al *.flac
no flac file deleted.

Steps to reproduce the behavior.

Welcome to Termux!

Docs:       https://termux.dev/docs
Donate:     https://termux.dev/donate
Community:  https://termux.dev/community

Working with packages:

 - Search:  pkg search <query>
 - Install: pkg install <package>
 - Upgrade: pkg upgrade

Subscribing to additional repositories:

 - Root:    pkg install root-repo
 - X11:     pkg install x11-repo

For fixing any repository issues,
try 'termux-change-repo' command.

Report issues at https://termux.dev/issues
~ $ sd
/sdcard/, $ pwd
/sdcard/,
/sdcard/, $ ls
aa.sh        m          tts                 小说
aaa          menlo.ttf  updateMp3IdTags.sh
android-ime  music      zzzz
/sdcard/, $ cd zzzz/
.../,/zzzz $ ls --al
ls: option '--al' is ambiguous; possibilities: '--all' '--almost-all'
Try 'ls --help' for more information.
.../,/zzzz $ ls --all
'Because I Love You@Shakină'$'\302\200\302\201''Stevens.flac'
'bitgii asuu 别问我@松布尔.flac'
'my personal paradise@imagine musică'$'\302\200\302\201''sergey zubarev.flac'
'sigma@epic soul factory、cesc vilà、fran soto.flac'
 unzip-zzz.zip
'Моменты жизни-2 (Детство)@Amure.mp3'
 уголёк@lx24.flac
 一无所有@王杰.flac
.../,/zzzz $ ls -al
total 153176
-rw-rw---- 1 root everybody 20896320 Sep 19 18:13 'Because I Love You@Shakină'$'\302\200\302\201''Stevens.flac'
-rw-rw---- 1 root everybody 26484469 Oct  2 23:30 'bitgii asuu 别问我@松布尔.flac'
-rw-rw---- 1 root everybody 21332391 Sep 30 14:50 'my personal paradise@imagine musică'$'\302\200\302\201''sergey zubarev.flac'
-rw-rw---- 1 root everybody 19540797 Sep 24 18:44 'sigma@epic soul factory、cesc vilà、fran soto.flac'
drwxrwx--- 2 root everybody     4096 Feb  3 22:05  unzip-zzz.zip
-rw-rw---- 1 root everybody 13322630 Sep 30 18:02 'Моменты жизни-2 (Детство)@Amure.mp3'
-rw-rw---- 1 root everybody 24929885 Oct  2 16:01  уголёк@lx24.flac
-rw-rw---- 1 root everybody 30266073 Oct  2 21:43  一无所有@王杰.flac
.../,/zzzz $ cd unzip-zzz.zip/
.../zzzz/unzip-zzz.zip $ ls
'Because I Love You@Shakin-'$'\342''-'$'\307''-'$'\374''Stevens.flac'
'bitgii asuu '$'\325\352\275\332\371\253\265\352\346''@'$'\265''إթ'$'\342''զ'$'\366''.flac'
'my personal paradise@imagine music-'$'\342''-'$'\307''-'$'\374''sergey zubarev.flac'
'sigma@epic soul factory'$'\322\307\374''cesc vila'$'\246\307\322\307\374''fran soto.flac'
 zzzz.zip
''$'\320\342\360\246\360\245\360''+'$'\320\346\360\246''@lx24.flac'
''$'\360\243\360\245\360''+'$'\360\301\360\242\320\351\320\357'' '$'\360\302\360\251\360\300\360\242\360\251''-2 ('$'\360\366\360\301\320\351\320\374\320\351\360\246\360\245'')@Amure.mp3'
''$'\365\251''ǵ'$'\371\341\265\353''ǵ'$'\243\353''@'$'\376\304\357\265''ئ.flac'
.../zzzz/unzip-zzz.zip $ ls -al
total 306044
-rw-rw---- 1 root everybody  20896320 Sep 19 18:13 'Because I Love You@Shakin-'$'\342''-'$'\307''-'$'\374''Stevens.flac'
-rw-rw---- 1 root everybody  26484469 Oct  2 23:30 'bitgii asuu '$'\325\352\275\332\371\253\265\352\346''@'$'\265''إթ'$'\342''զ'$'\366''.flac'
-rw-rw---- 1 root everybody  21332391 Sep 30 14:50 'my personal paradise@imagine music-'$'\342''-'$'\307''-'$'\374''sergey zubarev.flac'
-rw-rw---- 1 root everybody  19540797 Sep 24 18:44 'sigma@epic soul factory'$'\322\307\374''cesc vila'$'\246\307\322\307\374''fran soto.flac'
-rw-rw---- 1 root everybody 156540554 Feb  3 22:04  zzzz.zip
-rw-rw---- 1 root everybody  24929885 Oct  2 16:01 ''$'\320\342\360\246\360\245\360''+'$'\320\346\360\246''@lx24.flac'
-rw-rw---- 1 root everybody  13322630 Sep 30 18:02 ''$'\360\243\360\245\360''+'$'\360\301\360\242\320\351\320\357'' '$'\360\302\360\251\360\300\360\242\360\251''-2 ('$'\360\366\360\301\320\351\320\374\320\351\360\246\360\245'')@Amure.mp3'
-rw-rw---- 1 root everybody  30266073 Oct  2 21:43 ''$'\365\251''ǵ'$'\371\341\265\353''ǵ'$'\243\353''@'$'\376\304\357\265''ئ.flac'
.../zzzz/unzip-zzz.zip $
.../zzzz/unzip-zzz.zip $ rm -rfv +.flac
.../zzzz/unzip-zzz.zip $
.../zzzz/unzip-zzz.zip $
.../zzzz/unzip-zzz.zip $ ls -al
total 306044
-rw-rw---- 1 root everybody  20896320 Sep 19 18:13 'Because I Love You@Shakin-'$'\342''-'$'\307''-'$'\374''Stevens.flac'
-rw-rw---- 1 root everybody  26484469 Oct  2 23:30 'bitgii asuu '$'\325\352\275\332\371\253\265\352\346''@'$'\265''إթ'$'\342''զ'$'\366''.flac'
-rw-rw---- 1 root everybody  21332391 Sep 30 14:50 'my personal paradise@imagine music-'$'\342''-'$'\307''-'$'\374''sergey zubarev.flac'
-rw-rw---- 1 root everybody  19540797 Sep 24 18:44 'sigma@epic soul factory'$'\322\307\374''cesc vila'$'\246\307\322\307\374''fran soto.flac'
-rw-rw---- 1 root everybody 156540554 Feb  3 22:04  zzzz.zip
-rw-rw---- 1 root everybody  24929885 Oct  2 16:01 ''$'\320\342\360\246\360\245\360''+'$'\320\346\360\246''@lx24.flac'
-rw-rw---- 1 root everybody  13322630 Sep 30 18:02 ''$'\360\243\360\245\360''+'$'\360\301\360\242\320\351\320\357'' '$'\360\302\360\251\360\300\360\242\360\251''-2 ('$'\360\366\360\301\320\351\320\374\320\351\360\246\360\245'')@Amure.mp3'
-rw-rw---- 1 root everybody  30266073 Oct  2 21:43 ''$'\365\251''ǵ'$'\371\341\265\353''ǵ'$'\243\353''@'$'\376\304\357\265''ئ.flac'
.../zzzz/unzip-zzz.zip $
.../zzzz/unzip-zzz.zip $
.../zzzz/unzip-zzz.zip $ ls -i
3178615 'Because I Love You@Shakin-'$'\342''-'$'\307''-'$'\374''Stevens.flac'
3178616 'bitgii asuu '$'\325\352\275\332\371\253\265\352\346''@'$'\265''إթ'$'\342''զ'$'\366''.flac'
3178617 'my personal paradise@imagine music-'$'\342''-'$'\307''-'$'\374''sergey zubarev.flac'
3178618 'sigma@epic soul factory'$'\322\307\374''cesc vila'$'\246\307\322\307\374''fran soto.flac'
3178613  zzzz.zip
3178620 ''$'\320\342\360\246\360\245\360''+'$'\320\346\360\246''@lx24.flac'
3178619 ''$'\360\243\360\245\360''+'$'\360\301\360\242\320\351\320\357'' '$'\360\302\360\251\360\300\360\242\360\251''-2 ('$'\360\366\360\301\320\351\320\374\320\351\360\246\360\245'')@Amure.mp3'
3178621 ''$'\365\251''ǵ'$'\371\341\265\353''ǵ'$'\243\353''@'$'\376\304\357\265''ئ.flac'
.../zzzz/unzip-zzz.zip $
.../zzzz/unzip-zzz.zip $
.../zzzz/unzip-zzz.zip $ find . -type f -inum 3178615
./Because I Love You@Shakin-?-?-?Stevens.flac
.../zzzz/unzip-zzz.zip $
.../zzzz/unzip-zzz.zip $ find . -type f -inum 3178615 -delete
find: cannot delete ‘./Because I Love You@Shakin-\342-\307-\374Stevens.flac’: No such file or directory
.../zzzz/unzip-zzz.zip $
.../zzzz/unzip-zzz.zip $
.../zzzz/unzip-zzz.zip $ find . -type f -inum 3178615
./Because I Love You@Shakin-?-?-?Stevens.flac
.../zzzz/unzip-zzz.zip $
.../zzzz/unzip-zzz.zip $

What is the expected behavior?

rm all flac

or

how to delete then

thank you .

Screenshot_2023-02-03-22-20-38-288_com mixplorer
Screenshot_2023-02-03-22-20-42-411_com mixplorer
Screenshot_2023-02-03-22-20-50-462_com miui securitycenter
Screenshot_2023-02-03-22-26-08-315_com termux
Screenshot_2023-02-03-22-26-18-392_com termux
Screenshot_2023-02-03-22-26-25-158_com termux
Screenshot_2023-02-03-22-26-31-306_com termux

System information

  • Termux application version: 0.118.0
  • Android OS version: 11
  • Device model: xiao mi 9
@ghost
Copy link

ghost commented Feb 9, 2023

I'm pretty sure termux lacks UTF-8 or UTF-16 support for that matter so you are off better using an actual file manager/explorer.

The is also the issue with https://developer.android.com/guide/topics/resources/internationalization and https://developer.android.com/google/play/requirements/target-sdk and how far back termux support goes as is the case with other apps that got booted or stopped getting support on say play store.

@sylirre
Copy link
Member

sylirre commented Feb 10, 2023

Encoding isn't the case here (on Termux and CLI side) and support of utf8 is present.

Command

find . -type f -inum <inode number> -delete

should work regardless of encoding support as it doesn't operate on file name.

@qidizi should try delete file using file manager Android app.

P.S. I remember this issue was posted previously somewhere (Reddit?), it was very similar and it was not possible to delete file even using Mixplorer app...

@qidizi
Copy link
Author

qidizi commented Feb 10, 2023

rm do not work

IMG_20230210_083603

com.android.fikeexplorer xiao mi mod not work

Picsart_23-02-10_08-59-27-288

@qidizi
Copy link
Author

qidizi commented Feb 10, 2023

com.google.android.apps.nbu.files not work
Screenshot_2023-02-10-09-09-42-426_com google android apps nbu f_1675994199697

@qidizi
Copy link
Author

qidizi commented Feb 10, 2023

any way ? let me try.do not want to reset phone.they cost over 5GB. THKS.

IMG_20230210_100342

@qidizi
Copy link
Author

qidizi commented Feb 10, 2023

i think some op like rm by inode will work.because name mix encoded, rm by utf8_name/gbk_name not work. but find . -type f -inum <inode number> -delete not work too.

@sylirre
Copy link
Member

sylirre commented Feb 10, 2023

Normally the find . -type f -inum <inode number> -delete and rm -rf ./dir-with-weird-files should work as operations do not involve any name string conversion. Encoding can't be an issue in these cases.

However the mentioned case may happen if issue is actually with file system. Directories /sdcard or /storage/emulated/0 do not have a real file system. Instead there is mounted FAT32 or exFAT compatible overlay and real data is stored at /data/media/0. I guess the issue comes from there. This can't be resolved by Termux.

I was able to reproduce the issue on my device and this is what I have found:

  • Problem happens only at /sdcard or /storage/emulated/0
  • Problem doesn't happen at Termux home directory and /storage/emulated/0/Android/data/com.termux/files (this proves coreutils and findutils packages do not have issues with encoding, at least not in this case)

So basically we dealing with Android bug. I will try to find a way to delete the file and report here.


If someone wants to try undeletable file, it can be created this way:

termux-setup-storage
cd /sdcard
touch 'bitgii asuu '$'\325\352\275\332\371\253\265\352\346''@'$'\265''إթ'$'\342''զ'$'\366''.flac'

@sylirre
Copy link
Member

sylirre commented Feb 10, 2023

Things appear to be quite bad. I can't delete file using PC thorough MTP and ADB.

02-10 14:50:21.533  6084 14427 E MtpUtils: deletePath stat failed for /storage/emulated/0/bitgii asuu ��������@�إթ�զ�.flac: No such file or directory

I will try some other methods but it looks like can be done only by using root.


Update: wrote a simple C program to delete all files in current working directory:

#include <stdio.h>
#include <dirent.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>

int main(void) {
  DIR *d = opendir(".");
  if (d) {
    struct dirent *entry;
    struct stat st;

    while ((entry = readdir(d))) {
      if (stat(entry->d_name, &st) != -1) {
        if (S_ISDIR(st.st_mode)) {
          printf("Skipping directory: %s\n", entry->d_name);
        } else {
          printf("Attempting to delete file: %s\n", entry->d_name);
          unlink(entry->d_name);
        }
      } else {
        printf("Unable to stat file: %s\n", entry->d_name);
        continue;
      }
    }
  }
}

It still has no effect on file with weird characters, but there is some interesting detail in strace log:

newfstatat(AT_FDCWD, "Documents", {st_mode=S_IFDIR|S_ISGID|0770, st_size=3452, ...}, 0) = 0
write(1, "Skipping directory: Documents\n", 30Skipping directory: Documents
) = 30
newfstatat(AT_FDCWD, "bitgii asuu \325\352\275\332\371\253\265\352\346@\265\330\245\325\251\342\325\246\366.flac", {st_mode=S_IFREG|0660, st_size=0, ...}, 0) = 0
write(1, "Attempting to delete file: bitgi"..., 64Attempting to delete file: bitgii asuu ���������@�إթ�զ�.flac
) = 64
unlinkat(AT_FDCWD, "bitgii asuu \325\352\275\332\371\253\265\352\346@\265\330\245\325\251\342\325\246\366.flac", 0) = -1 ENOENT (No such file or directory)

The stat system call for checking the file passes, which means that file is present and we have no problems accessing it by name. However the unlink system call returns ENOENT code.


I'm closing the issue. Nothing really can be done on unrooted device with such file. I know similar issues was possible quite easily resolve on older Android versions, but on Android 13 things are different.

What I can suggest:

  • Non-rooted users of Android 11+ (not sure if A10 is affected): do factory reset and since then play with files only in secondary profiles or application sandbox (Termux home directory).
  • Non-rooted users of Android 9 and lower: try using file managers for deleting unwanted files. rm and find . -delete methods may work too. (confirmed to work at least on Samsung Galaxy S7 with Android 8 latest stock ROM)
  • Rooted users: use su to launch root shell and try to delete file manually in /data/media directory and then reboot.

@sylirre sylirre closed this as not planned Won't fix, can't repro, duplicate, stale Feb 10, 2023
@agnostic-apollo
Copy link
Member

I can confirm that deleting file with root via /data/media/0 works. The find -inum fails because it is also using unlinkat internally. Running mv or rename on invalid regular file to rename it to a valid name will fail too with both relative and absolute path. I guess some bug in sdcardfs. dmesg kernel logs don't log anything either.

However, you can still move the parent directory with mv. Like mkdir -p junk; mv aaa junk/ to move all such directories to a junk directory.

Also even though you cannot delete the file itself, you can overwrite it to set its size to 0 so that you can free the storage space at least. Simply running echo > /path/to/file will work. Or to recursively set all regular files in current directory to size 0, run find . -type f -print0 | xargs -0 truncate -s 0

@shiumano
Copy link

shiumano commented Apr 7, 2024

I was lucky enough to find a solution. Hopefully no one will need to factory reset after this.

  1. first, create a file with a funny name. (touch $' \200'a that should be enough)
  2. move the directory with the crazy file to the data directory of the app where it is OK to delete the data. (/sdcard/Android/[media|obb] can be edited with Termux permissions, /sdcard/Android/data with adb shell permissions)
  3. delete the sacrificed app data.

This allowed me to delete it; it was possible on Android 14, so probably on other Android versions as well.

Is it possible that the package installer has strong permissions and was able to remove it?

@sylirre
Copy link
Member

sylirre commented Apr 7, 2024

@shiumano Confirming, worked for me by moving directory containing the file to Android/media/<app.package.name>, then deleing app with <app.package.name>.

Although if file was created in storage root directory (/storage/emulated/0), then method not going to work - you can't move the file itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants