Browse Source

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
stable-4.8
Christian Halstrick 8 years ago committed by Matthias Sohn
parent
commit
501af12c19
  1. 14
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java
  2. 7
      org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java

14
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<String, String> i) public void assertWorkDir(Map<String, String> i)
throws CorruptObjectException, throws CorruptObjectException,
IOException { IOException {

7
org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java vendored

@ -1299,8 +1299,13 @@ public class DirCacheCheckout {
return; return;
} }
String name = f.getName();
if (name.length() > 200) {
name = name.substring(0, 200);
}
File tmpFile = File.createTempFile( File tmpFile = File.createTempFile(
"._" + f.getName(), null, parentDir); //$NON-NLS-1$ "._" + name, null, parentDir); //$NON-NLS-1$
EolStreamType nonNullEolStreamType; EolStreamType nonNullEolStreamType;
if (checkoutMetadata.eolStreamType != null) { if (checkoutMetadata.eolStreamType != null) {
nonNullEolStreamType = checkoutMetadata.eolStreamType; nonNullEolStreamType = checkoutMetadata.eolStreamType;

Loading…
Cancel
Save