为什么在Guava中不推荐使用Files.deleteDirectoryContents()? [英] Why is Files.deleteDirectoryContents() deprecated in Guava?

查看:74
本文介绍了为什么在Guava中不推荐使用Files.deleteDirectoryContents()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Guava 10+中,Google弃用了 Files.deleteDirectoryContents()。 JavaDoc说

In Guava 10+, Google deprecated Files.deleteDirectoryContents(). JavaDoc says


已弃用。此方法遭受不良的符号链接检测和竞争
的条件。只有
掏空到诸如rm -rf或del / s之类的操作系统命令中,才能适当地支持此功能。
该方法计划在Guava版本
11.0

Deprecated. This method suffers from poor symlink detection and race conditions. This functionality can be supported suitably only by shelling out to an operating system command such as rm -rf or del /s. This method is scheduled to be removed from Guava in Guava release 11.0

我对为什么要这样做感到困惑是比赛条件。我认为使用此方法实际上是有用的,并且发现将其炮轰给操作系统不是一个好的解决方案。作者可以分享做出这个决定的原因吗?

I am confused on why there is a race condition. I think having this method is actually useful and find shelling out to operating system a poor solution. Can the authors share why the made this decision?

推荐答案


我对为什么出现比赛条件感到困惑。

I am confused on why there is a race condition.

例如,假设一个线程调用 Files.deleteDirectoryContents(),第二个线程调用(或外部过程)同时在目录中创建一个新文件。

For example, suppose that one thread calls Files.deleteDirectoryContents() and a second thread (or an external process) simultaneously creates a new file in the directory.

当您从通话中返回时,可以依靠目录为空吗?

When you return from the call, can you rely on the directory being empty? Nope!

无论如何,如果您发现此方法的功能很有用……尽管它有缺陷……您可以自由获取代码副本,对其进行调整,并将其嵌入到您的应用程序中。 (只需检查Guava源代码许可,并确保您遵守该许可即可。)

Anyway, if you find the functionality of this method to be useful ... despite its flaws ... you are free to take a copy of the code, tweak it, and embed it in your application. (Just check the Guava source code license and make sure that you conform to it.)


作者能否分享做出此决定的原因?

Can the authors share why the made this decision?

我认为他们已经拥有了;请参阅弃用通知。如果您想要更多,请尝试搜索问题跟踪器和Guava讨论组。您甚至可以尝试在讨论小组中礼貌地询问,尽管如果您的议程是改变主意,我怀疑您会成功。

I think that they already have; see the deprecation notice. If you want more, try searching the issue tracker and the Guava discussion group. You could even try asking politely on the discussion group, though if your agenda is to change their minds, I doubt that you will succeed.

这篇关于为什么在Guava中不推荐使用Files.deleteDirectoryContents()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆