From ebfe85d0374aee1992d01029c12338da3d67e26b Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Thu, 6 Jun 2013 12:31:46 -0700 Subject: Add long filename, large file, and non-ASCII filename support to TarFormat Attempts to write entries with too-long filenames currently error out: $ jgit.pgm/target/jgit archive HEAD >test.tar java.lang.RuntimeException: file name 'org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/DefaultReceivePackFactory.java' is too long ( > 100 bytes) at org.apache.commons.compress.archivers.tar.TarArchiveOutputStream.putArchiveEntry(TarArchiveOutputStream.java:288) at org.eclipse.jgit.archive.TarFormat.putEntry(TarFormat.java:92) at org.eclipse.jgit.archive.TarFormat.putEntry(TarFormat.java:62) at org.eclipse.jgit.api.ArchiveCommand.writeArchive(ArchiveCommand.java:293) at org.eclipse.jgit.api.ArchiveCommand.call(ArchiveCommand.java:322) at org.eclipse.jgit.pgm.Archive.run(Archive.java:97) at org.eclipse.jgit.pgm.TextBuiltin.execute(TextBuiltin.java:174) at org.eclipse.jgit.pgm.Main.execute(Main.java:213) at org.eclipse.jgit.pgm.Main.run(Main.java:121) at org.eclipse.jgit.pgm.Main.main(Main.java:95) That's because the default longFileMode is LONGFILE_ERROR, which throws an exception for filenames longer than 100 characters. Switch to LONGFILE_POSIX. While at it, handle large files and filenames with strange encodings, too. This requires commons compress 1.4, which introduced support for large files and POSIX long filenames. Change-Id: I04d5427eec0968b129f55d7a4c6021039a494828 --- .../tst/org/eclipse/jgit/pgm/ArchiveTest.java | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'org.eclipse.jgit.pgm.test/tst/org/eclipse') diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java index cb2a7258a6..a2a5044a5a 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java @@ -228,6 +228,36 @@ public class ArchiveTest extends CLIRepositoryTestCase { assertTarContainsEntry("with-modes.tar", "l", "symlink -> plain"); } + @Test + public void testArchiveWithLongFilename() throws Exception { + String filename = "1234567890"; + for (int i = 0; i < 20; i++) + filename = filename + "/1234567890"; + writeTrashFile(filename, "file with long path"); + git.add().addFilepattern("1234567890").call(); + git.commit().setMessage("file with long name").call(); + + final byte[] result = CLIGitCommand.rawExecute( // + "git archive HEAD", db); + assertArrayEquals(new String[] { filename }, + listZipEntries(result)); + } + + @Test + public void testTarWithLongFilename() throws Exception { + String filename = "1234567890"; + for (int i = 0; i < 20; i++) + filename = filename + "/1234567890"; + writeTrashFile(filename, "file with long path"); + git.add().addFilepattern("1234567890").call(); + git.commit().setMessage("file with long name").call(); + + final byte[] result = CLIGitCommand.rawExecute( // + "git archive --format=tar HEAD", db); + assertArrayEquals(new String[] { filename }, + listTarEntries(result)); + } + @Test public void testArchivePreservesContent() throws Exception { final String payload = "“The quick brown fox jumps over the lazy dog!”"; -- cgit v1.2.3