try (RemoteTempFile tar = sftp.buildRemoteTemp()) {
try (OutputStream os = sftp.writeFile(tar.getSshPath(), WriteMode.Overwrite)) {
imageData.copyTo(os);
}
RemoteFile tempVolume = getImagePath(tempImageId);
{
String cmd = "sudo btrfs subvolume create " + tempVolume.getSshPath();
SshCommand sshCommand = new SshCommand(sshConfig, cmd);
sshCommand.run();
}
{
ShellCommand cmd = ShellCommand.create("/bin/tar");
cmd.literal("--numeric-owner");
cmd.literal("-f").arg(tar.getSshPath());
cmd.literal("-C").arg(tempVolume.getSshPath());
cmd.literal("-xz");
cmd.useSudo();
SshCommand sshCommand = cmd.withSsh(sshConfig);
sshCommand.run();
}
RemoteFile imageVolume = getImagePath(imageId);
{
String cmd = "sudo btrfs subvolume snapshot -r " + tempVolume.getSshPath() + " "
+ imageVolume.getSshPath();
SshCommand sshCommand = new SshCommand(sshConfig, cmd);
sshCommand.run();
}
}
}