Skip to content

Commit 7c7df79

Browse files
committed
refactor: use java paths for zip backups management
1 parent 5dd62c0 commit 7c7df79

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

core/src/main/java/com/orientechnologies/orient/core/compression/impl/OZIPCompressionUtil.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ public static List<String> compressDirectory(
6363
public static void uncompressDirectory(
6464
final InputStream in, final String out, final OCommandOutputListener iListener)
6565
throws IOException {
66-
final File outdir = new File(out);
67-
final String targetDirPath = outdir.getCanonicalPath() + File.separator;
66+
final Path outdir = Path.of(out).toAbsolutePath();
6867

6968
try (ZipInputStream zin = new ZipInputStream(in)) {
7069
ZipEntry entry;
@@ -73,8 +72,8 @@ public static void uncompressDirectory(
7372
while ((entry = zin.getNextEntry()) != null) {
7473
name = entry.getName();
7574

76-
final File file = new File(outdir, name);
77-
if (!file.getCanonicalPath().startsWith(targetDirPath))
75+
Path targetPath = outdir.resolve(name);
76+
if (!targetPath.startsWith(outdir))
7877
throw new IOException(
7978
"Expanding '"
8079
+ entry.getName()
@@ -100,20 +99,20 @@ public static void uncompressDirectory(
10099

101100
private static void extractFile(
102101
final ZipInputStream in,
103-
final File outdir,
102+
final Path outdir,
104103
final String name,
105104
final OCommandOutputListener iListener)
106105
throws IOException {
107106
if (iListener != null) iListener.onMessage("\n- Uncompressing file " + name + "...");
108107

109108
try (BufferedOutputStream out =
110-
new BufferedOutputStream(new FileOutputStream(new File(outdir, name)))) {
109+
new BufferedOutputStream(new FileOutputStream(outdir.resolve(name).toFile()))) {
111110
OIOUtils.copyStream(in, out);
112111
}
113112
}
114113

115-
private static void mkdirs(final File outdir, final String path) {
116-
final File d = new File(outdir, path);
114+
private static void mkdirs(final Path outdir, final String path) {
115+
final File d = outdir.resolve(path).toFile();
117116
if (!d.exists()) d.mkdirs();
118117
}
119118

0 commit comments

Comments
 (0)