简体   繁体   English

Java 7:了解文件是否为符号链接是否有帮助?

[英]Java 7 : Does knowing a file is symbolic link or not helps?

In Java 7 it provides me a way to detect whether a file is symbolic link or not , but why anyone would want to know that . 在Java 7中,它为我提供了一种检测文件是否为符号链接的方法,但是可以检测为什么有人想要知道该文件。

Files.isSymbolicLink(target) //here target is a path.

I never needed that so far, just wondering what will be the use of it ? 到目前为止,我一直不需要它,只是想知道它的用途是什么?

Suppose you're writing a recursive directory copy - you may decide not to follow symbolic links. 假设您正在编写一个递归目录副本-您可能决定不遵循符号链接。 Or maybe you're creating an archive in a format that doesn't support symbolic links - you may want to warn the user if you encounter one. 或者,也许您正在以一种不支持符号链接的格式创建档案文件-如果您遇到警告,则可能要警告用户。 Or maybe you're writing a diff program, and you want to skip pairs of files which are actually the same file really. 或者,也许您正在编写一个diff程序,并且想要跳过实际上实际上是同一文件的文件对。

Basically it's a reasonably common property of some files in a file system - why would Java not want to expose that information? 基本上它是在文件系统中的某些文件的合理的共同财产-为什么Java的希望暴露的信息?

One really good reason you might care about symbolic links is because of security. 您可能关心符号链接的一个很好的理由是安全。 Sometimes you might want to prevent letting people accessing files from outside a restricted area, so your app checks to make sure the file that is being accessed is not a symbolic link that leads outside of your application's sandbox. 有时,您可能希望阻止人们从限制区域之外访问文件,因此您的应用程序进行检查以确保所访问的文件不是通向应用程序沙箱之外的符号链接。

For example, if you're building a network accessible application that runs as a user and that accesses files by path, like maybe a file sharing application, and you want to restrict where people can look for files on your users system, symbolic links could be a security problem. 例如,如果您要构建一个可以以用户身份运行并且可以按路径访问文件的网络可访问应用程序(例如文件共享应用程序),并且想要限制人们可以在用户系统上查找文件的位置,则符号链接可以是一个安全问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM