This is an automated email from the ASF dual-hosted git repository.
zjffdu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zeppelin.git
The following commit(s) were added to refs/heads/master by this push:
new 333a34a [HOTFIX] [ZEPPELIN-4305] make sure that destination directory
exists
333a34a is described below
commit 333a34a92f54783005fd5f3cadbfe5b10067f110
Author: Alex Ott <[email protected]>
AuthorDate: Thu Sep 5 08:47:11 2019 +0200
[HOTFIX] [ZEPPELIN-4305] make sure that destination directory exists
### What is this PR for?
This is a fix for issue reported in #3428 - this may happen when
destination directory doesn't exist. The given PR is explicitly create
destination directory.
### What type of PR is it?
Hot Fix
Author: Alex Ott <[email protected]>
Closes #3439 from alexott/ZEPPELIN-4305-fix and squashes the following
commits:
cd3d12b48 [Alex Ott] [HOTFIX] [ZEPPELIN-4305] make sure that destination
directory exists
---
.../apache/zeppelin/storage/LocalConfigStorage.java | 4 +++-
.../zeppelin/storage/LocalConfigStorageTest.java | 20 ++++++++++++++++++++
2 files changed, 23 insertions(+), 1 deletion(-)
diff --git
a/zeppelin-zengine/src/main/java/org/apache/zeppelin/storage/LocalConfigStorage.java
b/zeppelin-zengine/src/main/java/org/apache/zeppelin/storage/LocalConfigStorage.java
index 1bdb13b..0f5999d 100644
---
a/zeppelin-zengine/src/main/java/org/apache/zeppelin/storage/LocalConfigStorage.java
+++
b/zeppelin-zengine/src/main/java/org/apache/zeppelin/storage/LocalConfigStorage.java
@@ -115,7 +115,9 @@ public class LocalConfigStorage extends ConfigStorage {
static void atomicWriteToFile(String content, File file) throws IOException {
FileSystem defaultFileSystem = FileSystems.getDefault();
Path destinationFilePath =
defaultFileSystem.getPath(file.getCanonicalPath());
- File tempFile = Files.createTempFile(destinationFilePath.getParent(),
file.getName(), null).toFile();
+ Path destinationDirectory = destinationFilePath.getParent();
+ Files.createDirectories(destinationDirectory);
+ File tempFile = Files.createTempFile(destinationDirectory, file.getName(),
null).toFile();
try (FileOutputStream out = new FileOutputStream(tempFile)) {
IOUtils.write(content, out);
} catch (IOException iox) {
diff --git
a/zeppelin-zengine/src/test/java/org/apache/zeppelin/storage/LocalConfigStorageTest.java
b/zeppelin-zengine/src/test/java/org/apache/zeppelin/storage/LocalConfigStorageTest.java
index 9e4b6a8..cf0ac63 100644
---
a/zeppelin-zengine/src/test/java/org/apache/zeppelin/storage/LocalConfigStorageTest.java
+++
b/zeppelin-zengine/src/test/java/org/apache/zeppelin/storage/LocalConfigStorageTest.java
@@ -26,6 +26,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Random;
import static org.junit.Assert.*;
@@ -48,6 +50,24 @@ public class LocalConfigStorageTest {
}
@Test
+ public void testWritingAtomicallyNonExistingDir() throws IOException {
+ Random rnd = new Random();
+ final Path destDir = Paths.get(System.getProperty("java.io.tmpdir"),
"non-existing-" + rnd.nextLong());
+ final Path destination = Paths.get(destDir.toString(),"test-" +
rnd.nextLong() + "-file");
+ final File destinationFile = destination.toFile();
+ try {
+ LocalConfigStorage.atomicWriteToFile(TEST_STRING, destinationFile);
+ try (InputStream is = Files.newInputStream(destination)) {
+ String read = IOUtils.toString(is);
+ assertEquals(TEST_STRING, read);
+ }
+ } finally {
+ Files.deleteIfExists(destination);
+ Files.deleteIfExists(destDir);
+ }
+ }
+
+ @Test
public void testReading() throws IOException {
final Path destination = Files.createTempFile("test-", "file");
final File destinationFile = destination.toFile();