In Java what exactly does File.canExecute() do?

后端 未结 3 1754
深忆病人
深忆病人 2021-01-13 20:46

I have created a plain file which does not have execute permission but when I create a Java File object using this file\'s path/name and then call File.canExecute() I get tr

相关标签:
3条回答
  • 2021-01-13 20:52

    Nothing to do with Java - you're running as root, and root is allowed everything, not matter what the permissions say.

    0 讨论(0)
  • 2021-01-13 21:12

    Though I'm not an expert, and this will not answer your question properly, I'd like to add that this behavior is not specific to Java. From the find (GNU findutils) 4.4.0 manpage on my Ubuntu 8.10 install, regarding the -executable flag:

    Matches files which are executable and directories which are searchable (in a file name resolution sense). This takes into account access control lists and other permissions artefacts which the -perm test ignores. This test makes use of the access(2) system call, and so can be fooled by NFS servers which do UID mapping (or root-squashing), since many systems implement access(2) in the client’s kernel and so cannot make use of the UID mapping information held on the server. Because this test is based only on the result of the access(2) system call, there is no guarantee that a file for which this test succeeds can actually be executed.

    0 讨论(0)
  • 2021-01-13 21:14

    Here is a bug which was opened on JDK on this:

    http://bugs.sun.com/bugdatabase/view_bug.do;jsessionid=8b833c54cb93d6c9cf416667dc02?bug_id=6379654

    The conclusion is that File.canExecute() simply translates into a native posix call to access(path, X_OK). Linux returns false and solaris returns true for that call when run as root.

    Finally, the bug was closed as Wont Fix! :)

    0 讨论(0)
提交回复
热议问题