【问题标题】:File.delete() does not delete symlink on Android?File.delete() 不会删除 Android 上的符号链接?
【发布时间】:2010-11-19 15:49:27
【问题描述】:

我无法在 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));

升级后(从网上下载不同的 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 仍然存在!它与应用程序的其余部分具有相同的用户/组权限(lib 目录除外,该目录归 system 用户所有)。

有什么线索吗?

【问题讨论】:

  • 你在 exec 调用中试过 'rm -f' 吗?

标签: android


【解决方案1】:

我知道这有点晚了,但谷歌在尝试解决类似问题时将我发送到这里。 任何删除特定符号链接的尝试都失败,并显示令人困惑的消息“目录非空” 我挖得更深了,发现目标文件不存在。我创建了一个并且 rm 工作了:-)。

在我看来,这就像 Android 中的一个错误,但我对 Android 太陌生了,无法确定。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-28
    • 2020-11-27
    • 1970-01-01
    • 2010-09-17
    • 2020-10-19
    • 1970-01-01
    • 2020-11-10
    • 2018-12-01
    相关资源
    最近更新 更多