private static Optional<FilePermissions> determinePermissions(
      AbsoluteUnixPath path,
      Map<String, FilePermissions> extraDirectoryPermissions,
      Map<PathMatcher, FilePermissions> permissionsPathMatchers) {
    // The check is only for optimization. (`permissionsPathMatchers` is constructed from the map.)
    FilePermissions permissions = extraDirectoryPermissions.get(path.toString());
    if (permissions != null) {
      return Optional.of(permissions);
    }

    // Check for matching globs
    for (Map.Entry<PathMatcher, FilePermissions> entry : permissionsPathMatchers.entrySet()) {
      if (entry.getKey().matches(Paths.get(path.toString()))) {
        return Optional.of(entry.getValue());
      }
    }
    return Optional.empty();
  }
Returns a {@link FileEntriesLayer} for adding the extra directory to the container.

@param sourceDirectory the source extra directory path
@param targetDirectory the root directory on the container to place the files in
@param includes the list of glob patterns to include from the source directory
@param excludes the list of glob patterns to exclude from the source directory
@param extraDirectoryPermissions map from path on container to file permissions
@param modificationTimeProvider file modification time provider
@return a {@link FileEntriesLayer} for adding the extra directory to the container
@throws IOException if walking the extra directory fails
jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/JavaContainerBuilderHelper.java