thrau / jarchivelib

A simple archiving and compression library for Java
https://github.com/thrau/jarchivelib
Apache License 2.0
198 stars 36 forks source link

Support for symlinks #40

Open thrau opened 9 years ago

thrau commented 9 years ago

Currently links are not supported at all. Depending on the archive type, weird things will happen.

DavidZemon commented 7 years ago

I was really hoping to use your wrapper because it truly is the API I think Apache should have provided from the start! Unfortunately, I just discovered this bug/missing feature for myself. Any chance you implement it?

thrau commented 7 years ago

Unfortunately, there is no clear way to generalize handling of symlinks across archive formats. Also, I don't see any easy solution without Java 7+ nio. So this is definitely not on my radar for now, sorry.

DavidZemon commented 7 years ago

That's too bad. Thanks for getting back quickly so I know to find another solution though.

I found a solution that should work quite nicely, though it isn't pure java. Some context: my application already requires being able to invoke external processes that may be found via the PATH environment variable, so I already created a class called ExecutableFinder which will search PATH and return the absolute directory of an exe.

final File tarExe = executableFinder.find("tar");
if (tarExe.exists()) {
  ArchiverFactory.createArchive("tar", "gz").extract(theArchivePath, theOutputPath);
} else {
  final int exitCode = new ProcessBuilder("tar", "xf", theArchivePath)
      .directory(theOutputPath)
      .start()
      .waitFor();
  if (0 != exitCode) {
    // handle error
  }
}

I like this because any system that doesn't have tar available on PATH (aka, Windows) won't support symlinks anyway. This should be 99.9% perfect. It won't work on Windows systems that have mounted a filesystem that supports symlinks, and it won't work on *nix systems that don't have tar on PATH... but I'll bet those are pretty rare cases.