I've tried running the command in java but with no luck
rpm2cpio <rpmName> | cpio -imdv
This is my current Code
public static void decompress() {
System.out.println("Decompression has started");
Archiver archiver = ArchiverFactory.createArchiver(ArchiveFormat.TAR, CompressionType.GZIP);
try {
archiver.extract(autoUpdateFile, tempDestination);
for(File currentRPM: new File("./temp/patches/rpms/").listFiles()) {
if(currentRPM.getName().contains("Data")) {
ProcessBuilder decompressRPM = new ProcessBuilder(
new String[] {"rpm2cpio", currentRPM.getAbsolutePath(), "cpio -idmv"});
Process startDecompression = decompressRPM.start();
InputStream inputFromDecompression = startDecompression.getInputStream();
BufferedReader inputReader = new BufferedReader(new InputStreamReader(inputFromDecompression));
String line = null;
System.out.println("From Input Buffer");
while((line = inputReader.readLine()) != null) {
System.out.println(line);
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Decompression ended");
}
The main idea is that I have a compressed file which contains multiple files inside and in one of the files exists a list of rpms that I need decompressed to get some of the data out to update the project.
Is there any way that I can run such a command or do I need to use a library?
Thank you.
Update: thanks to @Brian I managed to fix it by changing from
ProcessBuilder decompressRPM = new ProcessBuilder(
new String[] {"rpm2cpio", currentRPM.getAbsolutePath(), "cpio -idmv"});
Process startDecompression = decompressRPM.start();
to
String[] decompressionCommand = {"/bin/sh", "-c", "rpm2cpio " + currentRPM.getAbsolutePath() + " | cpio -idmv"};
Process startDecompression = Runtime.getRuntime().exec(decompressionCommand);
But I ended up with another problem. I'm getting permission denied. I will be searching around for a solution and in case I find something I will post it here for future reference.