]> source.dussan.org Git - gitblit.git/commitdiff
Fixes to symlink handling (issue-174)
authorJames Moger <james.moger@gitblit.com>
Tue, 4 Dec 2012 02:29:32 +0000 (21:29 -0500)
committerJames Moger <james.moger@gitblit.com>
Tue, 4 Dec 2012 02:29:32 +0000 (21:29 -0500)
src/com/gitblit/utils/CompressionUtils.java

index 414519061d3c56c46677e7461efcb4728418090a..a8dcdd8f53f2f456804f83fc8cbcdc5abf835482 100644 (file)
@@ -27,6 +27,7 @@ import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
 import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;\r
 import org.apache.commons.compress.compressors.CompressorException;\r
 import org.apache.commons.compress.compressors.CompressorStreamFactory;\r
+import org.apache.wicket.util.io.ByteArrayOutputStream;\r
 import org.eclipse.jgit.lib.Constants;\r
 import org.eclipse.jgit.lib.FileMode;\r
 import org.eclipse.jgit.lib.MutableObjectId;\r
@@ -256,7 +257,6 @@ public class CompressionUtils {
                        }\r
                        tw.setRecursive(true);\r
                        MutableObjectId id = new MutableObjectId();\r
-                       ObjectReader reader = tw.getObjectReader();\r
                        long modified = commit.getAuthorIdent().getWhen().getTime();\r
                        while (tw.next()) {\r
                                FileMode mode = tw.getFileMode(0);\r
@@ -265,16 +265,24 @@ public class CompressionUtils {
                                }\r
                                tw.getObjectId(id, 0);\r
                                \r
-                               TarArchiveEntry entry = new TarArchiveEntry(tw.getPathString());\r
-                               entry.setSize(reader.getObjectSize(id, Constants.OBJ_BLOB));\r
-                               \r
-                               entry.setMode(mode.getBits());\r
-                               entry.setModTime(modified);\r
-                               tos.putArchiveEntry(entry);\r
-                               \r
-                               ObjectLoader ldr = repository.open(id);\r
-                               ldr.copyTo(tos);                                        \r
-                               tos.closeArchiveEntry();\r
+                               ObjectLoader loader = repository.open(id);\r
+                               if (FileMode.SYMLINK == mode) {\r
+                                       TarArchiveEntry entry = new TarArchiveEntry(tw.getPathString(),TarArchiveEntry.LF_SYMLINK);\r
+                                       ByteArrayOutputStream bos = new ByteArrayOutputStream();\r
+                                       loader.copyTo(bos);\r
+                                       entry.setLinkName(bos.toString());\r
+                                       entry.setModTime(modified);\r
+                                       tos.putArchiveEntry(entry);\r
+                                       tos.closeArchiveEntry();\r
+                               } else {\r
+                                       TarArchiveEntry entry = new TarArchiveEntry(tw.getPathString());\r
+                                       entry.setMode(mode.getBits());\r
+                                       entry.setModTime(modified);\r
+                                       entry.setSize(loader.getSize());\r
+                                       tos.putArchiveEntry(entry);                                     \r
+                                       loader.copyTo(tos);\r
+                                       tos.closeArchiveEntry();\r
+                               }\r
                        }\r
                        tos.finish();\r
                        tos.close();\r