mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-11-22 10:15:52 +01:00
Don't follow symlinks for directory copies
This commit is contained in:
parent
622ef32b4e
commit
118ac28e4c
@ -6,6 +6,7 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.LinkOption;
|
||||
import java.util.*;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
@ -267,7 +268,7 @@ public final class Util {
|
||||
* @param to Destination
|
||||
*/
|
||||
public static void copyDirectory(File from, File to) {
|
||||
if (from.isDirectory()) {
|
||||
if (from.isDirectory() && !Files.isSymbolicLink(from.toPath())) {
|
||||
if (!to.exists()) {
|
||||
to.mkdirs();
|
||||
}
|
||||
@ -281,37 +282,10 @@ public final class Util {
|
||||
copyDirectory(srcFile, destFile);
|
||||
}
|
||||
} else {
|
||||
if (to.exists()) {
|
||||
to.delete();
|
||||
}
|
||||
InputStream in = null;
|
||||
OutputStream out = null;
|
||||
|
||||
try {
|
||||
in = new FileInputStream(from);
|
||||
out = new FileOutputStream(to, false);
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
|
||||
int length;
|
||||
while ((length = in.read(buffer)) > 0) {
|
||||
out.write(buffer, 0, length);
|
||||
}
|
||||
|
||||
in.close();
|
||||
out.close();
|
||||
Files.copy(from.toPath(), to.toPath(), LinkOption.NOFOLLOW_LINKS);
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
if (in != null) in.close();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
if (out != null) out.close();
|
||||
} catch (IOException e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.LinkOption;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@ -264,7 +265,7 @@ public final class Util {
|
||||
* @param to Destination
|
||||
*/
|
||||
public static void copyDirectory(File from, File to) {
|
||||
if (from.isDirectory()) {
|
||||
if (from.isDirectory() && !Files.isSymbolicLink(from.toPath())) {
|
||||
if (!to.exists()) {
|
||||
to.mkdirs();
|
||||
}
|
||||
@ -278,34 +279,10 @@ public final class Util {
|
||||
copyDirectory(srcFile, destFile);
|
||||
}
|
||||
} else {
|
||||
InputStream in = null;
|
||||
OutputStream out = null;
|
||||
|
||||
try {
|
||||
in = new FileInputStream(from);
|
||||
out = new FileOutputStream(to);
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
|
||||
int length;
|
||||
while ((length = in.read(buffer)) > 0) {
|
||||
out.write(buffer, 0, length);
|
||||
}
|
||||
|
||||
in.close();
|
||||
out.close();
|
||||
Files.copy(from.toPath(), to.toPath(), LinkOption.NOFOLLOW_LINKS);
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
if (in != null) in.close();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
if (out != null) out.close();
|
||||
} catch (IOException e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.LinkOption;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@ -264,7 +265,7 @@ public final class Util {
|
||||
* @param to Destination
|
||||
*/
|
||||
public static void copyDirectory(File from, File to) {
|
||||
if (from.isDirectory()) {
|
||||
if (from.isDirectory() && !Files.isSymbolicLink(from.toPath())) {
|
||||
if (!to.exists()) {
|
||||
to.mkdirs();
|
||||
}
|
||||
@ -278,34 +279,10 @@ public final class Util {
|
||||
copyDirectory(srcFile, destFile);
|
||||
}
|
||||
} else {
|
||||
InputStream in = null;
|
||||
OutputStream out = null;
|
||||
|
||||
try {
|
||||
in = new FileInputStream(from);
|
||||
out = new FileOutputStream(to);
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
|
||||
int length;
|
||||
while ((length = in.read(buffer)) > 0) {
|
||||
out.write(buffer, 0, length);
|
||||
}
|
||||
|
||||
in.close();
|
||||
out.close();
|
||||
Files.copy(from.toPath(), to.toPath(), LinkOption.NOFOLLOW_LINKS);
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
if (in != null) in.close();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
if (out != null) out.close();
|
||||
} catch (IOException e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiEngine</artifactId>
|
||||
<version>19w03a</version>
|
||||
<version>19w03b</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -6,6 +6,7 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.LinkOption;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@ -264,48 +265,22 @@ public final class Util {
|
||||
* @param to Destination
|
||||
*/
|
||||
public static void copyDirectory(File from, File to) {
|
||||
if (from.isDirectory()) {
|
||||
if (from.isDirectory() && !Files.isSymbolicLink(from.toPath())) {
|
||||
if (!to.exists()) {
|
||||
to.mkdirs();
|
||||
}
|
||||
|
||||
String files[] = from.list();
|
||||
|
||||
for (String file : files) {
|
||||
for (String file : from.list()) {
|
||||
File srcFile = new File(from, file);
|
||||
File destFile = new File(to, file);
|
||||
|
||||
copyDirectory(srcFile, destFile);
|
||||
}
|
||||
} else {
|
||||
InputStream in = null;
|
||||
OutputStream out = null;
|
||||
|
||||
try {
|
||||
in = new FileInputStream(from);
|
||||
out = new FileOutputStream(to);
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
|
||||
int length;
|
||||
while ((length = in.read(buffer)) > 0) {
|
||||
out.write(buffer, 0, length);
|
||||
}
|
||||
|
||||
in.close();
|
||||
out.close();
|
||||
Files.copy(from.toPath(), to.toPath(), LinkOption.NOFOLLOW_LINKS);
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
if (in != null) in.close();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
if (out != null) out.close();
|
||||
} catch (IOException e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user