create directory if apply
This commit is contained in:
parent
cd3f7ad0dd
commit
041ebff9b7
|
@ -18,6 +18,7 @@ public class ConfigFileLoader extends CommonConfigFileLoader<ConfigFileLoader.Pr
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum ProjectConfiguration {
|
public enum ProjectConfiguration {
|
||||||
|
UPLOADS_PATHS
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -4,9 +4,12 @@ import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
import static tv.mangrana.config.ConfigFileLoader.ProjectConfiguration.UPLOADS_PATHS;
|
||||||
|
|
||||||
class FileCopier {
|
class FileCopier {
|
||||||
void hardLink(Path source, Path destination) {
|
void hardLink(Path source, Path destination) {
|
||||||
try {
|
try {
|
||||||
|
createDestinationFolderIfApply(destination);
|
||||||
Files.createLink(destination, source);
|
Files.createLink(destination, source);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.printf("error when creating hardlink with destination %s, error: %s%n",
|
System.out.printf("error when creating hardlink with destination %s, error: %s%n",
|
||||||
|
@ -14,4 +17,14 @@ class FileCopier {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createDestinationFolderIfApply(Path destination) throws IOException {
|
||||||
|
if (isTemporaryDestination(destination) && !Files.exists(destination))
|
||||||
|
Files.createDirectory(destination);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isTemporaryDestination(Path destination) {
|
||||||
|
return destination.toString()
|
||||||
|
.contains(UPLOADS_PATHS.name().toLowerCase());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue