Browse Source

Move createSymLink/readSymLink to FileUtils

Bug: 475070
Change-Id: I258f4bf291e02ef8e6f867b5d71c04ec902b6bcb
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
stable-4.1
Andrey Loskutov 9 years ago committed by Christian Halstrick
parent
commit
2e5c7c5db4
  1. 14
      org.eclipse.jgit/.settings/.api_filters
  2. 3
      org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
  3. 1
      org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
  4. 7
      org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java
  5. 10
      org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java
  6. 12
      org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32.java
  7. 10
      org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java
  8. 35
      org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtil.java
  9. 28
      org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java

14
org.eclipse.jgit/.settings/.api_filters

@ -21,4 +21,18 @@
</message_arguments> </message_arguments>
</filter> </filter>
</resource> </resource>
<resource path="src/org/eclipse/jgit/util/FileUtil.java" type="org.eclipse.jgit.util.FileUtil">
<filter id="338792546">
<message_arguments>
<message_argument value="org.eclipse.jgit.util.FileUtil"/>
<message_argument value="createSymLink(File, String)"/>
</message_arguments>
</filter>
<filter id="338792546">
<message_arguments>
<message_argument value="org.eclipse.jgit.util.FileUtil"/>
<message_argument value="readSymlink(File)"/>
</message_arguments>
</filter>
</resource>
</component> </component>

3
org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties

@ -241,7 +241,6 @@ errorInvalidProtocolWantedOldNewRef=error: invalid protocol: wanted 'old new ref
errorListing=Error listing {0} errorListing=Error listing {0}
errorOccurredDuringUnpackingOnTheRemoteEnd=error occurred during unpacking on the remote end: {0} errorOccurredDuringUnpackingOnTheRemoteEnd=error occurred during unpacking on the remote end: {0}
errorReadingInfoRefs=error reading info/refs errorReadingInfoRefs=error reading info/refs
errorSymlinksNotSupported=Symlinks are not supported with this OS/JRE
exceptionCaughtDuringExecutionOfHook=Exception caught during execution of "{0}" hook. exceptionCaughtDuringExecutionOfHook=Exception caught during execution of "{0}" hook.
exceptionCaughtDuringExecutionOfAddCommand=Exception caught during execution of add command exceptionCaughtDuringExecutionOfAddCommand=Exception caught during execution of add command
exceptionCaughtDuringExecutionOfArchiveCommand=Exception caught during execution of archive command exceptionCaughtDuringExecutionOfArchiveCommand=Exception caught during execution of archive command
@ -465,7 +464,7 @@ peeledLineBeforeRef=Peeled line before ref.
peerDidNotSupplyACompleteObjectGraph=peer did not supply a complete object graph peerDidNotSupplyACompleteObjectGraph=peer did not supply a complete object graph
personIdentEmailNonNull=E-mail address of PersonIdent must not be null. personIdentEmailNonNull=E-mail address of PersonIdent must not be null.
personIdentNameNonNull=Name of PersonIdent must not be null. personIdentNameNonNull=Name of PersonIdent must not be null.
prefixRemote=remote: prefixRemote=remote:
problemWithResolvingPushRefSpecsLocally=Problem with resolving push ref specs locally: {0} problemWithResolvingPushRefSpecsLocally=Problem with resolving push ref specs locally: {0}
progressMonUploading=Uploading {0} progressMonUploading=Uploading {0}
propertyIsAlreadyNonNull=Property is already non null propertyIsAlreadyNonNull=Property is already non null

1
org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java

@ -300,7 +300,6 @@ public class JGitText extends TranslationBundle {
/***/ public String errorListing; /***/ public String errorListing;
/***/ public String errorOccurredDuringUnpackingOnTheRemoteEnd; /***/ public String errorOccurredDuringUnpackingOnTheRemoteEnd;
/***/ public String errorReadingInfoRefs; /***/ public String errorReadingInfoRefs;
/***/ public String errorSymlinksNotSupported;
/***/ public String exceptionCaughtDuringExecutionOfHook; /***/ public String exceptionCaughtDuringExecutionOfHook;
/***/ public String exceptionCaughtDuringExecutionOfAddCommand; /***/ public String exceptionCaughtDuringExecutionOfAddCommand;
/***/ public String exceptionCaughtDuringExecutionOfArchiveCommand; /***/ public String exceptionCaughtDuringExecutionOfArchiveCommand;

7
org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java

@ -67,7 +67,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.errors.SymlinksNotSupportedException;
import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
@ -623,8 +622,7 @@ public abstract class FS {
* @since 3.0 * @since 3.0
*/ */
public String readSymLink(File path) throws IOException { public String readSymLink(File path) throws IOException {
throw new SymlinksNotSupportedException( return FileUtils.readSymLink(path);
JGitText.get().errorSymlinksNotSupported);
} }
/** /**
@ -707,8 +705,7 @@ public abstract class FS {
* @since 3.0 * @since 3.0
*/ */
public void createSymLink(File path, String target) throws IOException { public void createSymLink(File path, String target) throws IOException {
throw new SymlinksNotSupportedException( FileUtils.createSymLink(path, target);
JGitText.get().errorSymlinksNotSupported);
} }
/** /**

10
org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java

@ -295,16 +295,6 @@ public class FS_POSIX extends FS {
// no action on POSIX // no action on POSIX
} }
@Override
public String readSymLink(File path) throws IOException {
return FileUtil.readSymlink(path);
}
@Override
public void createSymLink(File path, String target) throws IOException {
FileUtil.createSymLink(path, target);
}
/** /**
* @since 3.3 * @since 3.3
*/ */

12
org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32.java

@ -168,7 +168,7 @@ public class FS_Win32 extends FS {
try { try {
tempFile = File.createTempFile("tempsymlinktarget", ""); //$NON-NLS-1$ //$NON-NLS-2$ tempFile = File.createTempFile("tempsymlinktarget", ""); //$NON-NLS-1$ //$NON-NLS-2$
File linkName = new File(tempFile.getParentFile(), "tempsymlink"); //$NON-NLS-1$ File linkName = new File(tempFile.getParentFile(), "tempsymlink"); //$NON-NLS-1$
FileUtil.createSymLink(linkName, tempFile.getPath()); createSymLink(linkName, tempFile.getPath());
supportSymlinks = Boolean.TRUE; supportSymlinks = Boolean.TRUE;
linkName.delete(); linkName.delete();
} catch (IOException | UnsupportedOperationException e) { } catch (IOException | UnsupportedOperationException e) {
@ -233,16 +233,6 @@ public class FS_Win32 extends FS {
FileUtil.setHidden(path, hidden); FileUtil.setHidden(path, hidden);
} }
@Override
public String readSymLink(File path) throws IOException {
return FileUtil.readSymlink(path);
}
@Override
public void createSymLink(File path, String target) throws IOException {
FileUtil.createSymLink(path, target);
}
/** /**
* @since 3.3 * @since 3.3
*/ */

10
org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java

@ -218,16 +218,6 @@ public class FS_Win32_Cygwin extends FS_Win32 {
FileUtil.setHidden(path, hidden); FileUtil.setHidden(path, hidden);
} }
@Override
public String readSymLink(File path) throws IOException {
return FileUtil.readSymlink(path);
}
@Override
public void createSymLink(File path, String target) throws IOException {
FileUtil.createSymLink(path, target);
}
/** /**
* @since 3.3 * @since 3.3
*/ */

35
org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtil.java

@ -55,7 +55,6 @@ import java.nio.file.attribute.PosixFileAttributeView;
import java.nio.file.attribute.PosixFileAttributes; import java.nio.file.attribute.PosixFileAttributes;
import java.nio.file.attribute.PosixFilePermission; import java.nio.file.attribute.PosixFilePermission;
import java.text.Normalizer; import java.text.Normalizer;
import java.text.Normalizer.Form;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.util.FS.Attributes; import org.eclipse.jgit.util.FS.Attributes;
@ -65,40 +64,6 @@ import org.eclipse.jgit.util.FS.Attributes;
*/ */
public class FileUtil { public class FileUtil {
/**
* @param path
* @return target path of the symlink
* @throws IOException
*/
public static String readSymlink(File path) throws IOException {
Path nioPath = path.toPath();
Path target = Files.readSymbolicLink(nioPath);
String targetString = target.toString();
if (SystemReader.getInstance().isWindows())
targetString = targetString.replace('\\', '/');
else if (SystemReader.getInstance().isMacOS())
targetString = Normalizer.normalize(targetString, Form.NFC);
return targetString;
}
/**
* @param path
* path of the symlink to be created
* @param target
* target of the symlink to be created
* @throws IOException
*/
public static void createSymLink(File path, String target)
throws IOException {
Path nioPath = path.toPath();
if (Files.exists(nioPath, LinkOption.NOFOLLOW_LINKS))
Files.delete(nioPath);
if (SystemReader.getInstance().isWindows())
target = target.replace('/', '\\');
Path nioTarget = new File(target).toPath();
Files.createSymbolicLink(nioPath, nioTarget);
}
/** /**
* @param path * @param path
* @return {@code true} if the passed path is a symlink * @return {@code true} if the passed path is a symlink

28
org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java

@ -48,7 +48,12 @@ package org.eclipse.jgit.util;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.channels.FileLock; import java.nio.channels.FileLock;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.text.Normalizer;
import java.text.Normalizer.Form;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -350,18 +355,33 @@ public class FileUtils {
*/ */
public static void createSymLink(File path, String target) public static void createSymLink(File path, String target)
throws IOException { throws IOException {
FS.DETECTED.createSymLink(path, target); Path nioPath = path.toPath();
if (Files.exists(nioPath, LinkOption.NOFOLLOW_LINKS)) {
Files.delete(nioPath);
}
if (SystemReader.getInstance().isWindows()) {
target = target.replace('/', '\\');
}
Path nioTarget = new File(target).toPath();
Files.createSymbolicLink(nioPath, nioTarget);
} }
/** /**
* @param path * @param path
* @return the target of the symbolic link, or null if it is not a symbolic * @return target path of the symlink, or null if it is not a symbolic link
* link
* @throws IOException * @throws IOException
* @since 3.0 * @since 3.0
*/ */
public static String readSymLink(File path) throws IOException { public static String readSymLink(File path) throws IOException {
return FS.DETECTED.readSymLink(path); Path nioPath = path.toPath();
Path target = Files.readSymbolicLink(nioPath);
String targetString = target.toString();
if (SystemReader.getInstance().isWindows()) {
targetString = targetString.replace('\\', '/');
} else if (SystemReader.getInstance().isMacOS()) {
targetString = Normalizer.normalize(targetString, Form.NFC);
}
return targetString;
} }
/** /**

Loading…
Cancel
Save