Skip to content

Commit

Permalink
Merge pull request #87 from rmgrimm/fix-parent-directory-npe
Browse files Browse the repository at this point in the history
Don't create parent directory on download if not specified
  • Loading branch information
rmgrimm authored Oct 27, 2023
2 parents c462c3d + 6ff7afb commit 6bd49ca
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.nio.file.Path;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.stream.Collectors;

@CommandLine.Command(
header = "Download 3scale CMS Content",
Expand Down Expand Up @@ -105,7 +104,7 @@ public Integer call() throws Exception {
List<File> deleteFiles = localPathsToDelete.stream()
.map(treeDetails.getLocalObjectsByCmsPath()::get)
.map(Pair::getRight)
.collect(Collectors.toList());
.toList();

List<Pair<CmsObject, Path>> remoteObjectsToDownload = remotePathsToDownload.stream()
.map(pathKey -> {
Expand All @@ -114,7 +113,7 @@ public Integer call() throws Exception {

return Pair.of(object, targetPath);
})
.collect(Collectors.toList());
.toList();

if (noop) {
for (File file : deleteFiles) {
Expand Down Expand Up @@ -167,8 +166,10 @@ private void performDownload(@Nonnull CmsObject cmsObject,
File targetFile = targetPath.toFile();
File parentDirectory = targetFile.getParentFile();

if (!parentDirectory.exists() && !parentDirectory.mkdirs()) {
throw new IllegalStateException("Unable to create parent directories for " + targetFile);
if (parentDirectory != null) {
if (!parentDirectory.exists() && !parentDirectory.mkdirs()) {
throw new IllegalStateException("Unable to create parent directories for " + targetFile);
}
}

switch (cmsObject.getType()) {
Expand Down

0 comments on commit 6bd49ca

Please sign in to comment.