|
34 | 34 | import java.nio.channels.FileChannel; |
35 | 35 | import java.nio.charset.Charset; |
36 | 36 | import java.nio.charset.StandardCharsets; |
| 37 | +import java.nio.file.Files; |
37 | 38 | import java.util.ArrayList; |
38 | 39 | import java.util.Collection; |
39 | 40 | import java.util.Date; |
@@ -3029,61 +3030,9 @@ public static void moveToDirectory(final File src, final File destDir, final boo |
3029 | 3030 | * @since 2.0 |
3030 | 3031 | */ |
3031 | 3032 | public static boolean isSymlink(final File file) throws IOException { |
3032 | | - if ( Java7Support.isAtLeastJava7() ) |
3033 | | - { |
3034 | | - return Java7Support.isSymLink( file ); |
3035 | | - } |
3036 | | - |
3037 | 3033 | if (file == null) { |
3038 | 3034 | throw new NullPointerException("File must not be null"); |
3039 | 3035 | } |
3040 | | - if (FilenameUtils.isSystemWindows()) { |
3041 | | - return false; |
3042 | | - } |
3043 | | - File fileInCanonicalDir = null; |
3044 | | - if (file.getParent() == null) { |
3045 | | - fileInCanonicalDir = file; |
3046 | | - } else { |
3047 | | - final File canonicalDir = file.getParentFile().getCanonicalFile(); |
3048 | | - fileInCanonicalDir = new File(canonicalDir, file.getName()); |
3049 | | - } |
3050 | | - |
3051 | | - if (fileInCanonicalDir.getCanonicalFile().equals(fileInCanonicalDir.getAbsoluteFile())) { |
3052 | | - return isBrokenSymlink(file); |
3053 | | - } else { |
3054 | | - return true; |
3055 | | - } |
3056 | | - } |
3057 | | - |
3058 | | - /** |
3059 | | - * Determines if the specified file is possibly a broken symbolic link. |
3060 | | - * |
3061 | | - * @param file the file to check |
3062 | | -
|
3063 | | - * @return true if the file is a Symbolic Link |
3064 | | - * @throws IOException if an IO error occurs while checking the file |
3065 | | - */ |
3066 | | - private static boolean isBrokenSymlink(final File file) throws IOException { |
3067 | | - // if file exists then if it is a symlink it's not broken |
3068 | | - if (file.exists()) { |
3069 | | - return false; |
3070 | | - } |
3071 | | - // a broken symlink will show up in the list of files of its parent directory |
3072 | | - final File canon = file.getCanonicalFile(); |
3073 | | - File parentDir = canon.getParentFile(); |
3074 | | - if (parentDir == null || !parentDir.exists()) { |
3075 | | - return false; |
3076 | | - } |
3077 | | - |
3078 | | - // is it worthwhile to create a FileFilterUtil method for this? |
3079 | | - // is it worthwhile to create an "identity" IOFileFilter for this? |
3080 | | - File[] fileInDir = parentDir.listFiles( |
3081 | | - new FileFilter() { |
3082 | | - public boolean accept(File aFile) { |
3083 | | - return aFile.equals(canon); |
3084 | | - } |
3085 | | - } |
3086 | | - ); |
3087 | | - return fileInDir != null && fileInDir.length > 0; |
| 3036 | + return Files.isSymbolicLink(file.toPath()); |
3088 | 3037 | } |
3089 | 3038 | } |
0 commit comments