From 011283dc094e2380e350914b7532c264e745d3f5 Mon Sep 17 00:00:00 2001 From: szymon Date: Sat, 23 Jan 2021 18:46:49 +0100 Subject: [PATCH] Test 2 --- .../decompressors/GenericTarDecompressor.java | 28 +++++++++++++------ .../decompressors/ZipDecompressor.java | 28 ++++++++++++------- 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/main/java/net/szum123321/textile_backup/core/restore/decompressors/GenericTarDecompressor.java b/src/main/java/net/szum123321/textile_backup/core/restore/decompressors/GenericTarDecompressor.java index a305b5b..1a5a19d 100644 --- a/src/main/java/net/szum123321/textile_backup/core/restore/decompressors/GenericTarDecompressor.java +++ b/src/main/java/net/szum123321/textile_backup/core/restore/decompressors/GenericTarDecompressor.java @@ -50,19 +50,31 @@ public class GenericTarDecompressor { File file = target.toPath().resolve(entry.getName()).toFile(); if(entry.isDirectory()) { - file.mkdirs(); + try { + Files.createDirectories(file.toPath()); + } catch (IOException e) { + Statics.LOGGER.error("An exception occurred when trying to create {}", file, e); + } } else { File parent = file.getParentFile(); + try { + Files.createDirectories(parent.toPath()); + } catch (IOException e) { + Statics.LOGGER.error("An exception occurred when trying to create {}", file, e); + } + /* if (!parent.isDirectory() && !parent.mkdirs()) { Statics.LOGGER.error("Failed to create {}", parent); - } else { - try (OutputStream outputStream = Files.newOutputStream(file.toPath()); - BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream)) { - IOUtils.copy(archiveInputStream, bufferedOutputStream); - } catch (IOException e) { - Statics.LOGGER.error("An exception occurred while trying to decompress file: {}", file.getName(), e); - } + Statics.LOGGER.error("Skipping: {}", file); + continue; + }*/ + + try (OutputStream outputStream = Files.newOutputStream(file.toPath()); + BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream)) { + IOUtils.copy(archiveInputStream, bufferedOutputStream); + } catch (IOException e) { + Statics.LOGGER.error("An exception occurred while trying to decompress file: {}", file.getName(), e); } } } diff --git a/src/main/java/net/szum123321/textile_backup/core/restore/decompressors/ZipDecompressor.java b/src/main/java/net/szum123321/textile_backup/core/restore/decompressors/ZipDecompressor.java index a07e952..14ef543 100644 --- a/src/main/java/net/szum123321/textile_backup/core/restore/decompressors/ZipDecompressor.java +++ b/src/main/java/net/szum123321/textile_backup/core/restore/decompressors/ZipDecompressor.java @@ -47,19 +47,27 @@ public class ZipDecompressor { File file = target.toPath().resolve(entry.getName()).toFile(); if(entry.isDirectory()) { - file.mkdirs(); + try { + Files.createDirectories(file.toPath()); + } catch (IOException e) { + Statics.LOGGER.error("An exception occurred when trying to create {}", file, e); + } + //if(!file.isDirectory() && !file.mkdirs()) + // Statics.LOGGER.error("Failed to create: {}", file); } else { File parent = file.getParentFile(); - if (!parent.isDirectory() && !parent.mkdirs()) { - Statics.LOGGER.error("Failed to create {}", parent); - } else { - try (OutputStream outputStream = Files.newOutputStream(file.toPath()); - BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream)) { - IOUtils.copy(zipInputStream, bufferedOutputStream); - } catch (IOException e) { - Statics.LOGGER.error("An exception occurred while trying to decompress file: {}", file.getName(), e); - } + try { + Files.createDirectories(parent.toPath()); + } catch (IOException e) { + Statics.LOGGER.error("An exception occurred when trying to create {}", file, e); + } + + try (OutputStream outputStream = Files.newOutputStream(file.toPath()); + BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream)) { + IOUtils.copy(zipInputStream, bufferedOutputStream); + } catch (IOException e) { + Statics.LOGGER.error("An exception occurred while trying to decompress file: {}", file.getName(), e); } } }