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
tags/v4.8.0.201705170830-rc1
Christian Halstrick 7 years ago
parent
commit
501af12c19

+ 14
- 0
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java View File

@@ -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)
throws CorruptObjectException,
IOException {

+ 6
- 1
org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java View File

@@ -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;

Loading…
Cancel
Save