Java Code Examples for net.lingala.zip4j.model.ZipParameters#setSymbolicLinkAction()

The following examples show how to use net.lingala.zip4j.model.ZipParameters#setSymbolicLinkAction() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CreateZipFileIT.java    From zip4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddSymlinkWithLinkOnly() throws IOException {
  File targetFile = getTestFileFromResources("sample.pdf");
  File symlink = createSymlink(targetFile, temporaryFolder.getRoot());
  ZipFile zipFile = new ZipFile(generatedZipFile);

  ZipParameters zipParameters = new ZipParameters();
  zipParameters.setSymbolicLinkAction(ZipParameters.SymbolicLinkAction.INCLUDE_LINK_ONLY);

  zipFile.addFile(symlink, zipParameters);

  assertThat(zipFile.getFileHeaders()).hasSize(1);
  assertThat(zipFile.getFileHeaders().get(0).getFileName()).isEqualTo(symlink.getName());
  verifyZipFileByExtractingAllFiles(generatedZipFile, null, outputFolder, 1, false);

  verifyGeneratedSymlink(symlink, targetFile);
}
 
Example 2
Source File: CreateZipFileIT.java    From zip4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddSymlinkWithLinkAndLinkedFile() throws IOException {
  File targetFile = getTestFileFromResources("sample.pdf");
  File symlink = createSymlink(targetFile, temporaryFolder.getRoot());
  ZipFile zipFile = new ZipFile(generatedZipFile);

  ZipParameters zipParameters = new ZipParameters();
  zipParameters.setSymbolicLinkAction(ZipParameters.SymbolicLinkAction.INCLUDE_LINK_AND_LINKED_FILE);

  zipFile.addFile(symlink, zipParameters);

  List<FileHeader> fileHeaders = zipFile.getFileHeaders();
  assertThat(fileHeaders).hasSize(2);
  assertThat(fileHeaders.get(0).getFileName()).isEqualTo(symlink.getName());
  assertThat(fileHeaders.get(1).getFileName()).isEqualTo(targetFile.getName());
  verifyZipFileByExtractingAllFiles(generatedZipFile, null, outputFolder, 2, false);

  verifyGeneratedSymlink(symlink, targetFile);
  File generatedTargetFile = Paths.get(outputFolder.getAbsolutePath(), targetFile.getName()).toFile();
  ZipFileVerifier.verifyFileCrc(targetFile, generatedTargetFile);
}
 
Example 3
Source File: CreateZipFileIT.java    From zip4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddSymlinksInAFolderWithLinkOnly() throws IOException {
  File testFolder = createTestFolderWithSymlinks();
  ZipFile zipFile = new ZipFile(generatedZipFile);
  ZipParameters zipParameters = new ZipParameters();
  zipParameters.setSymbolicLinkAction(ZipParameters.SymbolicLinkAction.INCLUDE_LINK_ONLY);

  zipFile.addFolder(testFolder, zipParameters);

  verifyZipFileByExtractingAllFiles(generatedZipFile, null, outputFolder, 6, false);
  verifyFileNamesInZip(zipFile,
      "test-folder/",
      "test-folder/symlink.link",
      "test-folder/sub-folder1/",
      "test-folder/sub-folder1/symlink.link",
      "test-folder/sub-folder2/",
      "test-folder/sub-folder2/symlink.link");
}
 
Example 4
Source File: CreateZipFileIT.java    From zip4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddSymlinksInAFolderWithLinkedFilesOnly() throws IOException {
  File testFolder = createTestFolderWithSymlinks();
  ZipFile zipFile = new ZipFile(generatedZipFile);
  ZipParameters zipParameters = new ZipParameters();
  zipParameters.setSymbolicLinkAction(ZipParameters.SymbolicLinkAction.INCLUDE_LINKED_FILE_ONLY);

  zipFile.addFolder(testFolder, zipParameters);

  verifyZipFileByExtractingAllFiles(generatedZipFile, null, outputFolder, 6, false);
  verifyFileNamesInZip(zipFile,
      "test-folder/",
      "test-folder/sample.pdf",
      "test-folder/sub-folder1/",
      "test-folder/sub-folder1/file_PDF_1MB.pdf",
      "test-folder/sub-folder2/",
      "test-folder/sub-folder2/sample_text_large.txt");
}
 
Example 5
Source File: CreateZipFileIT.java    From zip4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddSymlinksInAFolderWithLinkAndLinkedFilesOnly() throws IOException {
  File testFolder = createTestFolderWithSymlinks();
  ZipFile zipFile = new ZipFile(generatedZipFile);
  ZipParameters zipParameters = new ZipParameters();
  zipParameters.setSymbolicLinkAction(ZipParameters.SymbolicLinkAction.INCLUDE_LINK_AND_LINKED_FILE);

  zipFile.addFolder(testFolder, zipParameters);

  verifyZipFileByExtractingAllFiles(generatedZipFile, null, outputFolder, 9, false);
  verifyFileNamesInZip(zipFile,
      "test-folder/",
      "test-folder/symlink.link",
      "test-folder/sample.pdf",
      "test-folder/sub-folder1/",
      "test-folder/sub-folder1/symlink.link",
      "test-folder/sub-folder1/file_PDF_1MB.pdf",
      "test-folder/sub-folder2/",
      "test-folder/sub-folder2/sample_text_large.txt",
      "test-folder/sub-folder2/symlink.link");
}
 
Example 6
Source File: CreateZipFileIT.java    From zip4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddSymlinksInAFolderWithLinkAndLinkedFilesOnlyWithoutRootFolder() throws IOException {
  File testFolder = createTestFolderWithSymlinks();
  ZipFile zipFile = new ZipFile(generatedZipFile);
  ZipParameters zipParameters = new ZipParameters();
  zipParameters.setIncludeRootFolder(false);
  zipParameters.setSymbolicLinkAction(ZipParameters.SymbolicLinkAction.INCLUDE_LINK_AND_LINKED_FILE);

  zipFile.addFolder(testFolder, zipParameters);

  verifyZipFileByExtractingAllFiles(generatedZipFile, null, outputFolder, 8, false);
  verifyFileNamesInZip(zipFile,
      "symlink.link",
      "sample.pdf",
      "sub-folder1/",
      "sub-folder1/symlink.link",
      "sub-folder1/file_PDF_1MB.pdf",
      "sub-folder2/",
      "sub-folder2/sample_text_large.txt",
      "sub-folder2/symlink.link");
}
 
Example 7
Source File: CreateZipFileIT.java    From zip4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddSymlinkWithLinkedFileOnly() throws IOException {
  File targetFile = getTestFileFromResources("sample.pdf");
  File symlink = createSymlink(targetFile, temporaryFolder.getRoot());
  ZipFile zipFile = new ZipFile(generatedZipFile);

  ZipParameters zipParameters = new ZipParameters();
  zipParameters.setSymbolicLinkAction(ZipParameters.SymbolicLinkAction.INCLUDE_LINKED_FILE_ONLY);

  zipFile.addFile(symlink, zipParameters);

  assertThat(zipFile.getFileHeaders()).hasSize(1);
  assertThat(zipFile.getFileHeaders().get(0).getFileName()).isEqualTo(targetFile.getName());
  verifyZipFileByExtractingAllFiles(generatedZipFile, outputFolder, 1);
}
 
Example 8
Source File: CreateZipFileIT.java    From zip4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddSymlinkWithLinkOnlyMissingTarget() throws IOException {
  File targetFile = Paths.get(temporaryFolder.getRoot().getAbsolutePath(), "foo").toFile();
  File symlink = createSymlink(targetFile, temporaryFolder.getRoot());
  ZipFile zipFile = new ZipFile(generatedZipFile);
  ZipParameters zipParameters = new ZipParameters();
  zipParameters.setSymbolicLinkAction(ZipParameters.SymbolicLinkAction.INCLUDE_LINK_ONLY);

  zipFile.addFile(symlink, zipParameters);

  assertThat(zipFile.getFileHeaders()).hasSize(1);
  assertThat(zipFile.getFileHeaders().get(0).getFileName()).isEqualTo(symlink.getName());
  verifyZipFileByExtractingAllFiles(generatedZipFile, null, outputFolder, 1, false);
  verifyGeneratedSymlink(symlink, targetFile);
}
 
Example 9
Source File: CreateZipFileIT.java    From zip4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddSymlinksInAFolderWithLinkOnlyMissingTarget() throws IOException {
  Path testFolderPath = temporaryFolder.newFolder("test-folder").toPath();
  Path subFolder1 = Files.createDirectory(Paths.get(testFolderPath.toString(), "sub-folder1"));
  Path subFolder2 = Files.createDirectory(Paths.get(testFolderPath.toString(), "sub-folder2"));

  File targetFile = Paths.get(temporaryFolder.getRoot().getAbsolutePath(), "foo").toFile();

  createSymlink(targetFile, testFolderPath.toFile());
  createSymlink(getTestFileFromResources("file_PDF_1MB.pdf"), subFolder1.toFile());
  createSymlink(getTestFileFromResources("sample_text_large.txt"), subFolder2.toFile());

  File testFolder = testFolderPath.toFile();

  ZipFile zipFile = new ZipFile(generatedZipFile);
  ZipParameters zipParameters = new ZipParameters();
  zipParameters.setSymbolicLinkAction(ZipParameters.SymbolicLinkAction.INCLUDE_LINK_ONLY);

  zipFile.addFolder(testFolder, zipParameters);

  verifyZipFileByExtractingAllFiles(generatedZipFile, null, outputFolder, 6, false);
  verifyFileNamesInZip(zipFile,
      "test-folder/",
      "test-folder/symlink.link",
      "test-folder/sub-folder1/",
      "test-folder/sub-folder1/symlink.link",
      "test-folder/sub-folder2/",
      "test-folder/sub-folder2/symlink.link");
}
 
Example 10
Source File: CreateZipFileIT.java    From zip4j with Apache License 2.0 5 votes vote down vote up
private void testAddSymlinkThrowsExceptionForMissingTarget(ZipParameters.SymbolicLinkAction symbolicLinkAction)
    throws IOException {
  File targetFile = Paths.get(temporaryFolder.getRoot().getAbsolutePath(), "foo").toFile();
  File symlink = createSymlink(targetFile, temporaryFolder.getRoot());
  ZipFile zipFile = new ZipFile(generatedZipFile);
  ZipParameters zipParameters = new ZipParameters();
  zipParameters.setSymbolicLinkAction(symbolicLinkAction);

  expectedException.expect(ZipException.class);
  expectedException.expectMessage("Symlink target '" + targetFile + "' does not exist for link '" + symlink + "'");

  zipFile.addFile(symlink, zipParameters);
}