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 {
|
||||
UPLOADS_PATHS
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,9 +4,12 @@ import java.io.IOException;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static tv.mangrana.config.ConfigFileLoader.ProjectConfiguration.UPLOADS_PATHS;
|
||||
|
||||
class FileCopier {
|
||||
void hardLink(Path source, Path destination) {
|
||||
try {
|
||||
createDestinationFolderIfApply(destination);
|
||||
Files.createLink(destination, source);
|
||||
} catch (IOException e) {
|
||||
System.out.printf("error when creating hardlink with destination %s, error: %s%n",
|
||||
|
@ -14,4 +17,14 @@ class FileCopier {
|
|||
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