Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

bug fix: silently fails overwriting symlinks #12

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class Java7Support

private static Method delete;

private static Method deleteIfExists;

private static Method toPath;

private static Method exists;
Expand All @@ -66,6 +68,7 @@ public class Java7Support
Class<?> linkOption = cl.loadClass( "java.nio.file.LinkOption" );
isSymbolicLink = files.getMethod( "isSymbolicLink", path );
delete = files.getMethod( "delete", path );
deleteIfExists = files.getMethod( "deleteIfExists", path );
readSymlink = files.getMethod( "readSymbolicLink", path );

emptyFileAttributes = Array.newInstance( fa, 0 );
Expand Down Expand Up @@ -170,13 +173,10 @@ public static boolean exists( @Nonnull File file )
{
try
{
if ( !exists( symlink ) )
{
Object link = toPath.invoke( symlink );
Object path = createSymlink.invoke( null, link, toPath.invoke( target ), emptyFileAttributes );
return (File) toFile.invoke( path );
}
return symlink;
Object link = toPath.invoke( symlink );
deleteIfExists.invoke( null, link );
Object path = createSymlink.invoke( null, link, toPath.invoke( target ), emptyFileAttributes );
return (File) toFile.invoke( path );
}
catch ( IllegalAccessException e )
{
Expand Down