S3Guard { public static FileStatus[] dirListingUnion(MetadataStore ms, Path path, List<FileStatus> backingStatuses, DirListingMetadata dirMeta, boolean isAuthoritative) throws IOException { if (isNullMetadataStore(ms)) { return backingStatuses.toArray(new FileStatus[backingStatuses.size()]); } assertQualified(path); if (dirMeta == null) { dirMeta = new DirListingMetadata(path, DirListingMetadata.EMPTY_DIR, false); } Set<Path> deleted = dirMeta.listTombstones(); boolean changed = false; for (FileStatus s : backingStatuses) { if (deleted.contains(s.getPath())) { continue; } boolean updated = dirMeta.put(s); changed = changed || updated; } changed = changed || (!dirMeta.isAuthoritative() && isAuthoritative); if (changed && isAuthoritative) { dirMeta.setAuthoritative(true); ms.put(dirMeta); } return dirMetaToStatuses(dirMeta); } private  S3Guard(); @Retries.OnceTranslated static MetadataStore getMetadataStore(FileSystem fs); static S3AFileStatus putAndReturn(MetadataStore ms,
      S3AFileStatus status,
      S3AInstrumentation instrumentation); static FileStatus[] dirMetaToStatuses(DirListingMetadata dirMeta); static FileStatus[] dirListingUnion(MetadataStore ms, Path path,
      List<FileStatus> backingStatuses, DirListingMetadata dirMeta,
      boolean isAuthoritative); static boolean isNullMetadataStore(MetadataStore ms); @Deprecated @Retries.OnceExceptionsSwallowed static void makeDirsOrdered(MetadataStore ms, List<Path> dirs,
      String owner, boolean authoritative); static void addMoveDir(MetadataStore ms, Collection<Path> srcPaths,
      Collection<PathMetadata> dstMetas, Path srcPath, Path dstPath,
      String owner); static void addMoveFile(MetadataStore ms, Collection<Path> srcPaths,
      Collection<PathMetadata> dstMetas, Path srcPath, Path dstPath,
      long size, long blockSize, String owner); static void addMoveAncestors(MetadataStore ms,
      Collection<Path> srcPaths, Collection<PathMetadata> dstMetas,
      Path srcRoot, Path srcPath, Path dstPath, String owner); static void addAncestors(MetadataStore metadataStore,
      Path qualifiedPath, String username); static void assertQualified(Path p); static void assertQualified(Path...paths); @InterfaceAudience.Private
  @InterfaceStability.Unstable
  @VisibleForTesting
  static final String S3GUARD_DDB_CLIENT_FACTORY_IMPL; }
@Test public void testDirListingUnion() throws Exception { MetadataStore ms = new LocalMetadataStore(); Path dirPath = new Path("s3a: PathMetadata m1 = makePathMeta("s3a: PathMetadata m2 = makePathMeta("s3a: DirListingMetadata dirMeta = new DirListingMetadata(dirPath, Arrays.asList(m1, m2), false); List<FileStatus> s3Listing = Arrays.asList( makeFileStatus("s3a: makeFileStatus("s3a: ); FileStatus[] result = S3Guard.dirListingUnion(ms, dirPath, s3Listing, dirMeta, false); assertEquals("listing length", 4, result.length); assertContainsPath(result, "s3a: assertContainsPath(result, "s3a: assertContainsPath(result, "s3a: assertContainsPath(result, "s3a: }