You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by mb...@apache.org on 2022/02/02 18:55:38 UTC

[asterixdb] 09/12: Merge branch 'gerrit/stabilization-02ea049d7a'

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

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

commit 967981118e78484dcdc92196f72b7783ae77840c
Merge: 69d5504 4ae6e5f
Author: Michael Blow <mi...@couchbase.com>
AuthorDate: Tue Feb 1 19:25:44 2022 -0500

    Merge branch 'gerrit/stabilization-02ea049d7a'
    
    Change-Id: I92fc9437db11351d904644bfed9b56b825d72e48

 .../PersistentLocalResourceRepository.java         | 48 ++++------------------
 .../java/org/apache/hyracks/api/util/IoUtil.java   | 37 +++++++++++++++++
 2 files changed, 46 insertions(+), 39 deletions(-)

diff --cc hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/IoUtil.java
index 6ad53ab,825fdd6..2887721
--- a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/IoUtil.java
+++ b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/IoUtil.java
@@@ -19,13 -19,16 +19,18 @@@
  package org.apache.hyracks.api.util;
  
  import java.io.File;
+ import java.io.FileFilter;
  import java.io.FileNotFoundException;
+ import java.io.FilenameFilter;
  import java.io.IOException;
 +import java.nio.channels.FileChannel;
  import java.nio.file.Files;
  import java.nio.file.NoSuchFileException;
  import java.nio.file.Path;
 +import java.nio.file.StandardOpenOption;
+ import java.util.ArrayList;
+ import java.util.Collection;
+ import java.util.Objects;
  
  import org.apache.commons.io.FileUtils;
  import org.apache.hyracks.api.exceptions.ErrorCode;
@@@ -134,22 -137,35 +139,54 @@@ public class IoUtil 
          return files;
      }
  
+     /**
+      * Gets a collection of files matching {@code filter} by searching {@code root} directory and
+      * all of its subdirectories
+      *
+      * @param root
+      * @param filter
+      * @return a collection of matching files
+      */
+     public static Collection<File> getMatchingFiles(Path root, FilenameFilter filter) {
+         if (!Files.isDirectory(root)) {
+             throw new IllegalArgumentException("Parameter 'root' is not a directory: " + root);
+         }
+         Objects.requireNonNull(filter);
+         Collection<File> files = new ArrayList<>();
+         FileFilter dirOrMatchingFileFilter = file -> file.isDirectory() || filter.accept(file, file.getName());
+         collectDirFiles(root.toFile(), dirOrMatchingFileFilter, files);
+         return files;
+     }
+ 
+     private static void collectDirFiles(File dir, FileFilter filter, Collection<File> files) {
+         File[] matchingFiles = dir.listFiles(filter);
+         if (matchingFiles != null) {
+             for (File file : matchingFiles) {
+                 if (file.isDirectory()) {
+                     collectDirFiles(file, filter, files);
+                 } else {
+                     files.add(file);
+                 }
+             }
+         }
+     }
++
 +    public static void flushDirectory(File directory) throws IOException {
 +        flushDirectory(directory.toPath());
 +    }
 +
 +    public static void flushDirectory(Path path) throws IOException {
 +        if (!Files.isDirectory(path)) {
 +            throw new IOException("Not a directory: " + path);
 +        }
 +        if (Files.getFileStore(path).supportsFileAttributeView("posix")) {
 +            try (FileChannel ch = FileChannel.open(path, StandardOpenOption.READ)) {
 +                ch.force(true);
 +            }
 +        } else {
 +            if (LOGGER.isTraceEnabled()) {
 +                LOGGER.trace("Unable to flush directory " + path);
 +            }
 +        }
 +    }
  }