Ahmadin Badruddin created COMPRESS-690:
------------------------------------------
Summary: CpioArchiveEntry is missing getLinkName
Key: COMPRESS-690
URL: https://issues.apache.org/jira/browse/COMPRESS-690
Project: Commons Compress
Issue Type: Bug
Components: Archivers
Affects Versions: 1.27.1
Reporter: Ahmadin Badruddin
When trying to extract a cpio file that contains a symbolic link, there is a
method to check if
CpioArchiveEntry is a symbolic link (entry.isSymbolicLink()), but there is no
entry.getLinkName. There is a getName, but we cannot create a symlink without
the target link.
I'm {color:#FF0000}*hoping*{color} I can write a code to extract symlink from a
cpio like below code snippets
{code:java}
public void extractCpioSymbolicLink(File archiveFile, File targetDirectory)
throws IOException {
try (CpioArchiveInputStream cpioInputStream = new
CpioArchiveInputStream(new FileInputStream(archiveFile))) {
CpioArchiveEntry entry;
while ((entry = cpioInputStream.getNextEntry()) != null) {
if (entry.isSymbolicLink()) {
String linkTarget = entry.getLinkName(); // Get the link target
File linkFile = new File(targetDirectory, entry.getName());
// Create the symbolic link using the linkTarget on the target
system
Files.createSymbolicLink(linkFile.toPath(),
Paths.get(linkTarget));
} else {
// Handle other file types (regular files, directories) as
needed
}
}
}
} {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)