Skip to content

Commit

Permalink
Defer existing Enigma dir deletion to writer visit pass start (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
NebelNidas authored Oct 16, 2023
1 parent 6e7de77 commit a301899
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ public final class EnigmaDirWriter extends EnigmaWriterBase {
public EnigmaDirWriter(Path dir, boolean deleteExistingFiles) throws IOException {
super(null);
this.dir = dir.toAbsolutePath().normalize();
this.deleteExistingFiles = deleteExistingFiles;
}

@Override
public boolean visitHeader() throws IOException {
if (deleteExistingFiles && Files.exists(dir)) {
Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
@Override
Expand All @@ -59,6 +63,8 @@ public FileVisitResult postVisitDirectory(Path file, IOException exc) throws IOE
}
});
}

return super.visitHeader();
}

@Override
Expand Down Expand Up @@ -143,4 +149,5 @@ public boolean visitElementContent(MappedElementKind targetKind) throws IOExcept
}

private final Path dir;
private final boolean deleteExistingFiles;
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public Set<MappingFlag> getFlags() {
return flags;
}

@Override
public boolean visitHeader() throws IOException {
return false;
}

@Override
public void visitNamespaces(String srcNamespace, List<String> dstNamespaces) { }

Expand Down

0 comments on commit a301899

Please sign in to comment.