[porcupineks] fix null pointer exception and file bundle extraction on Windows OS (#12234)

Signed-off-by: Miguel Álvarez Díez <miguelwork92@gmail.com>
This commit is contained in:
GiviMAD 2022-02-07 18:53:14 +01:00 committed by GitHub
parent d46367dfd0
commit 4e6bc0976e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 0 deletions

View File

@ -120,8 +120,16 @@ public class PorcupineKSService implements KSService {
File localFile = new File(EXTRACTION_FOLDER,
relativePath.substring(relativePath.lastIndexOf(File.separator) + 1));
if (!localFile.exists()) {
if (File.separator.equals("\\")) {
// bundle requires unix path separator
logger.debug("use unix path separator");
relativePath = relativePath.replace("\\", "/");
}
URL porcupineResource = bundleContext.getBundle().getEntry(relativePath);
logger.debug("extracting binary {} from bundle to extraction folder", relativePath);
if (porcupineResource == null) {
throw new IOException("Missing bundle file: " + relativePath);
}
extractFromBundle(porcupineResource, localFile);
} else {
logger.debug("binary {} already extracted", relativePath);