Move createSymLink/readSymLink to FileUtils
Bug: 475070 Change-Id: I258f4bf291e02ef8e6f867b5d71c04ec902b6bcb Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
This commit is contained in:
parent
91b1ab90e2
commit
2e5c7c5db4
|
@ -21,4 +21,18 @@
|
|||
</message_arguments>
|
||||
</filter>
|
||||
</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>
|
||||
|
|
|
@ -241,7 +241,6 @@ errorInvalidProtocolWantedOldNewRef=error: invalid protocol: wanted 'old new ref
|
|||
errorListing=Error listing {0}
|
||||
errorOccurredDuringUnpackingOnTheRemoteEnd=error occurred during unpacking on the remote end: {0}
|
||||
errorReadingInfoRefs=error reading info/refs
|
||||
errorSymlinksNotSupported=Symlinks are not supported with this OS/JRE
|
||||
exceptionCaughtDuringExecutionOfHook=Exception caught during execution of "{0}" hook.
|
||||
exceptionCaughtDuringExecutionOfAddCommand=Exception caught during execution of add command
|
||||
exceptionCaughtDuringExecutionOfArchiveCommand=Exception caught during execution of archive command
|
||||
|
|
|
@ -300,7 +300,6 @@ public static JGitText get() {
|
|||
/***/ public String errorListing;
|
||||
/***/ public String errorOccurredDuringUnpackingOnTheRemoteEnd;
|
||||
/***/ public String errorReadingInfoRefs;
|
||||
/***/ public String errorSymlinksNotSupported;
|
||||
/***/ public String exceptionCaughtDuringExecutionOfHook;
|
||||
/***/ public String exceptionCaughtDuringExecutionOfAddCommand;
|
||||
/***/ public String exceptionCaughtDuringExecutionOfArchiveCommand;
|
||||
|
|
|
@ -67,7 +67,6 @@
|
|||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.eclipse.jgit.api.errors.JGitInternalException;
|
||||
import org.eclipse.jgit.errors.SymlinksNotSupportedException;
|
||||
import org.eclipse.jgit.internal.JGitText;
|
||||
import org.eclipse.jgit.lib.Constants;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
|
@ -623,8 +622,7 @@ protected static File resolveGrandparentFile(File grandchild) {
|
|||
* @since 3.0
|
||||
*/
|
||||
public String readSymLink(File path) throws IOException {
|
||||
throw new SymlinksNotSupportedException(
|
||||
JGitText.get().errorSymlinksNotSupported);
|
||||
return FileUtils.readSymLink(path);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -707,8 +705,7 @@ public void setHidden(File path, boolean hidden) throws IOException {
|
|||
* @since 3.0
|
||||
*/
|
||||
public void createSymLink(File path, String target) throws IOException {
|
||||
throw new SymlinksNotSupportedException(
|
||||
JGitText.get().errorSymlinksNotSupported);
|
||||
FileUtils.createSymLink(path, target);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -295,16 +295,6 @@ public void setHidden(File path, boolean hidden) throws IOException {
|
|||
// 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
|
||||
*/
|
||||
|
|
|
@ -168,7 +168,7 @@ private void detectSymlinkSupport() {
|
|||
try {
|
||||
tempFile = File.createTempFile("tempsymlinktarget", ""); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
File linkName = new File(tempFile.getParentFile(), "tempsymlink"); //$NON-NLS-1$
|
||||
FileUtil.createSymLink(linkName, tempFile.getPath());
|
||||
createSymLink(linkName, tempFile.getPath());
|
||||
supportSymlinks = Boolean.TRUE;
|
||||
linkName.delete();
|
||||
} catch (IOException | UnsupportedOperationException e) {
|
||||
|
@ -233,16 +233,6 @@ public void setHidden(File path, boolean hidden) throws IOException {
|
|||
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
|
||||
*/
|
||||
|
|
|
@ -218,16 +218,6 @@ public void setHidden(File path, boolean hidden) throws IOException {
|
|||
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
|
||||
*/
|
||||
|
|
|
@ -55,7 +55,6 @@
|
|||
import java.nio.file.attribute.PosixFileAttributes;
|
||||
import java.nio.file.attribute.PosixFilePermission;
|
||||
import java.text.Normalizer;
|
||||
import java.text.Normalizer.Form;
|
||||
|
||||
import org.eclipse.jgit.lib.Constants;
|
||||
import org.eclipse.jgit.util.FS.Attributes;
|
||||
|
@ -65,40 +64,6 @@
|
|||
*/
|
||||
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
|
||||
* @return {@code true} if the passed path is a symlink
|
||||
|
|
|
@ -48,7 +48,12 @@
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
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.Normalizer;
|
||||
import java.text.Normalizer.Form;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
@ -350,18 +355,33 @@ public static void createNewFile(File f) throws IOException {
|
|||
*/
|
||||
public static void createSymLink(File path, String target)
|
||||
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
|
||||
* @return the target of the symbolic link, or null if it is not a symbolic
|
||||
* link
|
||||
* @return target path of the symlink, or null if it is not a symbolic link
|
||||
* @throws IOException
|
||||
* @since 3.0
|
||||
*/
|
||||
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…
Reference in New Issue