You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by GitBox <gi...@apache.org> on 2018/01/08 18:04:44 UTC

[GitHub] tteofili closed pull request #1: SLING-7358: FileDistributionPackageBuilder temp directory fallback

tteofili closed pull request #1: SLING-7358: FileDistributionPackageBuilder temp directory fallback
URL: https://github.com/apache/sling-org-apache-sling-distribution-core/pull/1
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/main/java/org/apache/sling/distribution/packaging/impl/FileDistributionPackageBuilder.java b/src/main/java/org/apache/sling/distribution/packaging/impl/FileDistributionPackageBuilder.java
index da8c496..66fd0b3 100644
--- a/src/main/java/org/apache/sling/distribution/packaging/impl/FileDistributionPackageBuilder.java
+++ b/src/main/java/org/apache/sling/distribution/packaging/impl/FileDistributionPackageBuilder.java
@@ -70,8 +70,15 @@ public FileDistributionPackageBuilder(String type,
         this.distributionContentSerializer = distributionContentSerializer;
         this.nodeFilters = VltUtils.parseFilters(nodeFilters);
         this.propertyFilters = VltUtils.parseFilters(propertyFilters);
-        this.tempDirectory = VltUtils.getTempFolder(tempFilesFolder);
         this.digestAlgorithm = digestAlgorithm;
+
+        File tempDirectory = VltUtils.getTempFolder(tempFilesFolder);
+
+        if (tempDirectory == null) {
+            tempDirectory = new File(System.getProperty("java.io.tmpdir"));
+        }
+
+        this.tempDirectory = tempDirectory;
     }
 
     @Override
diff --git a/src/test/java/org/apache/sling/distribution/packaging/impl/FileDistributionPackageBuilderTest.java b/src/test/java/org/apache/sling/distribution/packaging/impl/FileDistributionPackageBuilderTest.java
new file mode 100644
index 0000000..ea6072c
--- /dev/null
+++ b/src/test/java/org/apache/sling/distribution/packaging/impl/FileDistributionPackageBuilderTest.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.distribution.packaging.impl;
+
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.mock;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.distribution.DistributionRequest;
+import org.apache.sling.distribution.common.DistributionException;
+import org.apache.sling.distribution.packaging.DistributionPackage;
+import org.apache.sling.distribution.serialization.DistributionContentSerializer;
+import org.apache.sling.distribution.serialization.DistributionExportOptions;
+import org.junit.Test;
+
+public class FileDistributionPackageBuilderTest {
+
+    @Test
+    public void testDefaultTempDirectory() throws DistributionException, IOException {
+        FileDistributionPackageBuilder builder = new FileDistributionPackageBuilder("test", new TestSerializer(), null, null, new String[0],
+                new String[0]);
+        DistributionPackage createdPackage = builder.createPackageForAdd(mock(ResourceResolver.class), mock(DistributionRequest.class));
+
+        try {
+            assertNotNull(createdPackage.createInputStream());
+            DistributionPackage gotPackage = builder.getPackageInternal(mock(ResourceResolver.class), createdPackage.getId());
+            assertNotNull(gotPackage.createInputStream()); // this will throw an exception when the file doesn't exist
+        } finally {
+            createdPackage.delete();
+        }
+    }
+
+    class TestSerializer implements DistributionContentSerializer {
+
+        @Override public void exportToStream(ResourceResolver resourceResolver, DistributionExportOptions exportOptions,
+                OutputStream outputStream) throws DistributionException {
+            try {
+                outputStream.write("test".getBytes());
+            } catch (IOException ex) {
+                throw new DistributionException(ex);
+            }
+        }
+
+        @Override public void importFromStream(ResourceResolver resourceResolver, InputStream inputStream) throws DistributionException {
+            throw new DistributionException("unsupported");
+        }
+
+        @Override public String getName() {
+            return "test";
+        }
+
+        @Override public boolean isRequestFiltering() {
+            return true;
+        }
+    }
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services