This is an automated email from the ASF dual-hosted git repository.

spmallette pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git

commit 25364f764ea9eea28e97df5eff5443e7b86b539f
Merge: 2f5d57a 0024651
Author: Stephen Mallette <[email protected]>
AuthorDate: Mon Nov 9 08:57:19 2020 -0500

    Merge branch '3.4-dev'

 .../apache/tinkerpop/gremlin/util/TestSupport.java | 69 ++++++++++++++--------
 .../tinkerpop/gremlin/AbstractGraphProvider.java   |  2 +-
 2 files changed, 45 insertions(+), 26 deletions(-)

diff --cc 
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/TestSupport.java
index 0f89200,ee10491..f6e29b3
--- 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/TestSupport.java
+++ 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/TestSupport.java
@@@ -25,7 -27,9 +25,8 @@@ import java.io.FileOutputStream
  import java.io.IOException;
  import java.io.InputStream;
  import java.net.URL;
+ import java.nio.file.Files;
  import java.util.List;
 -import java.util.Random;
  import java.util.stream.Collectors;
  import java.util.stream.Stream;
  
@@@ -163,13 -171,27 +168,27 @@@ public class TestSupport 
                                                      final String 
resourceName, final String extension, final boolean overwrite) throws 
IOException {
          final File temp = makeTestDataPath(graphClass, "resources");
          final File tempFile = new File(temp, resourceName + extension);
-         if (!tempFile.exists() || overwrite) {
-             try (final FileOutputStream outputStream = new 
FileOutputStream(tempFile)) {
-                 int data;
-                 try (final InputStream inputStream = 
resourceClass.getResourceAsStream(resourceName)) {
-                     while ((data = inputStream.read()) != -1) {
-                         outputStream.write(data);
-                     }
+ 
+         // these checks are present mostly for windows compatibility where an 
outputstream created on a non-existent
 -        // file will cause an error. 
++        // file will cause an error.
+         if(tempFile.exists() && !overwrite){
+             // overwrite is disabled and file already exists -> reuse as-is
+             return tempFile;
+         }
+         if(!tempFile.getParentFile().exists()){
+             Files.createDirectories(tempFile.getParentFile().toPath());
+         }
+         // either the file does not exist or needs to be overwritten, drop it
+         Files.deleteIfExists(tempFile.toPath());
+         // create the new file
+         Files.createFile(tempFile.toPath());
+ 
+         // fill it with the desired contents
+         try (final FileOutputStream outputStream = new 
FileOutputStream(tempFile)) {
+             int data;
+             try (final InputStream inputStream = 
resourceClass.getResourceAsStream(resourceName)) {
+                 while ((data = inputStream.read()) != -1) {
+                     outputStream.write(data);
                  }
              }
          }

Reply via email to