问题描述
我无法在Android上删除符号链接。
不能使用File.delete()
,也不能使用exec("rm " + verFile.getPath())
我有一个符号链接
com.example.app/mydata/12345.ver --> com.example.app/lib/library.so
由创建
Runtime.getRuntime().exec(String.format("ln -s %s %s", target, link));
升级后(从Web下载不同的build.apk),我想通过以下方式删除此链接
File verFile = new File(dataDir, verFile);
Log.w("MyApp", "Deleting file " + verFile.getPath());
if (verFile.exists()) Log.w("MyApp", "File exists!");
try {
Runtime.getRuntime().exec("rm " + verFile.getPath());
} catch( IOException ioex ) { Log.w("MyApp", "Failed to delete"); }
我可以更换
Runtime.getRuntime().exec("rm " + verFile.getPath());
与
verFile.delete()
但没有效果(该文件仍不会删除)。
从adb logcat我可以看到
W/MyApp (13298): Deleting file /data/data/com.example.app/mydata/12345.ver
W/MyApp (13298): File exists!
但是文件12345.ver仍然存在!
它具有与应用程序其余部分相同的用户/组权限( system
用户拥有的lib
目录除外)。
有什么线索吗?
1楼
我知道这有些晚了,但是google在尝试解决类似问题时将我送到了这里。 任何尝试删除特定符号链接的尝试均会失败,并产生混乱的消息“目录不为空”,我对此进行了更深入的挖掘,发现目标文件不存在。 我创建了一个,并且rm工作了:-)。
在我看来,这就像是Android中的错误,但我对Android来说还太陌生。