From 501af12c19a4f7dfa0b22e46cdf19cc306370565 Mon Sep 17 00:00:00 2001 From: Christian Halstrick Date: Mon, 24 Apr 2017 14:33:47 +0200 Subject: [PATCH] Checkout should not use too long filenames DirCacheCheckout is generating names for temporary files. It was not checking the length of this filenames. It may happen that a generated filename is longer than 255 chars which causes problems on certain platforms. Make sure that filenames for temporary files do not exceed 255 chars. Bug: 508823 Change-Id: I9475c04351ce3faebdc6ad40ea4faa3c326815f4 --- .../org/eclipse/jgit/lib/DirCacheCheckoutTest.java | 14 ++++++++++++++ .../eclipse/jgit/dircache/DirCacheCheckout.java | 7 ++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java index 75b574e92..f8c2d4536 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java @@ -1672,6 +1672,20 @@ public class DirCacheCheckoutTest extends RepositoryTestCase { } } + @Test + public void testLongFilename() throws Exception { + char[] bytes = new char[253]; + Arrays.fill(bytes, 'f'); + String longFileName = new String(bytes); + // 1 + doit(mkmap(longFileName, "a"), mkmap(longFileName, "b"), + mkmap(longFileName, "a")); + writeTrashFile(longFileName, "a"); + checkout(); + assertNoConflicts(); + assertUpdated(longFileName); + } + public void assertWorkDir(Map i) throws CorruptObjectException, IOException { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java index 84f0da9e8..aed76ac66 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java @@ -1299,8 +1299,13 @@ public class DirCacheCheckout { return; } + String name = f.getName(); + if (name.length() > 200) { + name = name.substring(0, 200); + } File tmpFile = File.createTempFile( - "._" + f.getName(), null, parentDir); //$NON-NLS-1$ + "._" + name, null, parentDir); //$NON-NLS-1$ + EolStreamType nonNullEolStreamType; if (checkoutMetadata.eolStreamType != null) { nonNullEolStreamType = checkoutMetadata.eolStreamType;