Length of symbolic link is the number of bytes, not characters

Change-Id: I6b615f0d5da4339f1f23a29bcaeb80f0346f5764
This commit is contained in:
Robin Rosenberg 2013-07-10 17:33:50 +02:00 committed by Matthias Sohn
parent 7c19c45544
commit 1b5bb265dc
2 changed files with 8 additions and 7 deletions

View File

@ -85,16 +85,16 @@ public void tearDown() throws Exception {
@Test
public void testSymlinkAttributes() throws IOException, InterruptedException {
FS fs = FS.DETECTED;
File link = new File(trash, "x");
File target = new File(trash, "y");
fs.createSymLink(link, "y");
File link = new File(trash, "ä");
File target = new File(trash, "å");
fs.createSymLink(link, "å");
assertTrue(fs.exists(link));
String targetName = fs.readSymLink(link);
assertEquals("y", targetName);
assertEquals("å", targetName);
assertTrue(fs.lastModified(link) > 0);
assertTrue(fs.exists(link));
assertFalse(fs.canExecute(link));
assertEquals(1, fs.length(link));
assertEquals(2, fs.length(link));
assertFalse(fs.exists(target));
assertFalse(fs.isFile(target));
assertFalse(fs.isDirectory(target));

View File

@ -52,7 +52,7 @@
import java.text.Normalizer;
import java.text.Normalizer.Form;
import org.eclipse.jgit.util.SystemReader;
import org.eclipse.jgit.lib.Constants;
class FileUtil {
@ -113,7 +113,8 @@ public static void setHidden(File path, boolean hidden) throws IOException {
public static long getLength(File path) throws IOException {
Path nioPath = path.toPath();
if (Files.isSymbolicLink(nioPath))
return Files.readSymbolicLink(nioPath).toString().length();
return Files.readSymbolicLink(nioPath).toString()
.getBytes(Constants.CHARSET).length;
return Files.size(nioPath);
}