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>
|
</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>
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -300,7 +300,6 @@ public static JGitText get() {
|
||||||
/***/ 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;
|
||||||
|
|
|
@ -67,7 +67,6 @@
|
||||||
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 @@ protected static File resolveGrandparentFile(File grandchild) {
|
||||||
* @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 void setHidden(File path, boolean hidden) throws IOException {
|
||||||
* @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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -295,16 +295,6 @@ public void setHidden(File path, boolean hidden) throws IOException {
|
||||||
// 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
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -168,7 +168,7 @@ private void detectSymlinkSupport() {
|
||||||
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 void setHidden(File path, boolean hidden) throws IOException {
|
||||||
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
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -218,16 +218,6 @@ public void setHidden(File path, boolean hidden) throws IOException {
|
||||||
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
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -55,7 +55,6 @@
|
||||||
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 @@
|
||||||
*/
|
*/
|
||||||
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
|
||||||
|
|
|
@ -48,7 +48,12 @@
|
||||||
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 static void createNewFile(File f) throws IOException {
|
||||||
*/
|
*/
|
||||||
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…
Reference in New Issue