-
Notifications
You must be signed in to change notification settings - Fork 252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Symbolic link without actual file link caused FileNotFoundException #122
Comments
I took a look and I'm not sure what is the best solution here. You are trying to pack a folder with broken links, right? Best result is that the links itself end up in the archive and just continue being broken? This is very similar functionality to We use Apache Commons for copying but since Java 7 there is the Files.copy method https://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#copy(java.io.InputStream,%20java.nio.file.Path,%20java.nio.file.CopyOption...) which actually will copy the symbolic links and not the destination. Currently we are supporting Java 6 but not sure preserving this is a great idea. I think the most correct solution would be update to Java 7 and start preserving the links. |
I am not sure if the CopyOption is actually can resolve the issue because it is only able to support either follow the symlink or not follow. https://docs.oracle.com/javase/7/docs/api/java/nio/file/LinkOption.html. For this issue, we should either preserving the links as it is or discard the symlink if preserving is not possible. |
Quick test on my Mojave showed that it works in a way where it copies over the link - whether broken or not. I see that in later versions of Commons IO it also relies on this https://docs.oracle.com/javase/7/docs/api/java/nio/file/StandardCopyOption.html#REPLACE_EXISTING |
o...okay. great. I think I used the wrong option (LinkOption). |
I think I'll throw away the current copying, start relying on Java 7 and bump the requirements. Anybody still on Java 6 will have to do with the current functionality. |
Yes let's throw Java 6 and move on Java 7 . Very few companies are still using Java 6 . |
At https://github.com/zeroturnaround/zt-zip/blob/master/src/main/java/org/zeroturnaround/zip/ZipUtil.java#L1736 -
String[] filenames = dir.list(); doesn't guarantee return the list of files which are exists in the directory. If there is a symbolic link which link to not exists file, dir.list will return the file name but access the file will throw FileNotFoundException.
Steps to reproduce (must at Linux environment)
The solution should always ensure the file is exists.
for (int i = 0; i < filenames.length; i++) { String filename = filenames[i]; File file = new File(dir, filename) if(!file.exists()) { continue; }
The text was updated successfully, but these errors were encountered: