[#5614] SchemaVersionProvider might cause deletion of schemas that were not updated
This commit is contained in:
parent
a79e8008f0
commit
ca0331280a
@ -598,14 +598,14 @@ abstract class AbstractGenerator implements Generator {
|
||||
* If file is a file, delete it.
|
||||
*/
|
||||
protected void empty(File file, String suffix) {
|
||||
empty(file, suffix, Collections.<File>emptySet());
|
||||
empty(file, suffix, Collections.<File>emptySet(), Collections.<File>emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* If file is a directory, recursively empty its children.
|
||||
* If file is a file, delete it, except if it is in the list of files to keep.
|
||||
*/
|
||||
protected void empty(File file, String suffix, Set<File> keep) {
|
||||
protected void empty(File file, String suffix, Set<File> keep, Set<File> ignore) {
|
||||
if (file != null) {
|
||||
|
||||
// Just a Murphy's Law safeguard in case a user misconfigures their config...
|
||||
@ -614,12 +614,17 @@ abstract class AbstractGenerator implements Generator {
|
||||
return;
|
||||
}
|
||||
|
||||
// [#5614] Don't go into these directories
|
||||
for (File i : ignore)
|
||||
if (file.getAbsolutePath().startsWith(i.getAbsolutePath()))
|
||||
return;
|
||||
|
||||
if (file.isDirectory()) {
|
||||
File[] children = file.listFiles();
|
||||
|
||||
if (children != null)
|
||||
for (File child : children)
|
||||
empty(child, suffix, keep);
|
||||
empty(child, suffix, keep, ignore);
|
||||
|
||||
File[] childrenAfterDeletion = file.listFiles();
|
||||
|
||||
|
||||
@ -176,10 +176,17 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
private Map<CatalogDefinition, String> catalogVersions;
|
||||
|
||||
/**
|
||||
* All files modified by this generator
|
||||
* All files modified by this generator.
|
||||
*/
|
||||
private Set<File> files = new LinkedHashSet<File>();
|
||||
|
||||
/**
|
||||
* These directories were not modified by this generator, but flagged as not
|
||||
* for removal (e.g. because of {@link #schemaVersions} or
|
||||
* {@link #catalogVersions}).
|
||||
*/
|
||||
private Set<File> directoriesNotForRemoval = new LinkedHashSet<File>();
|
||||
|
||||
private final boolean scala;
|
||||
private final String tokenVoid;
|
||||
|
||||
@ -271,7 +278,8 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
|
||||
// [#5556] Clean up common parent directory
|
||||
log.info("Removing excess files");
|
||||
empty(getStrategy().getFileRoot(), (scala ? ".scala" : ".java"), files);
|
||||
empty(getStrategy().getFileRoot(), (scala ? ".scala" : ".java"), files, directoriesNotForRemoval);
|
||||
directoriesNotForRemoval.clear();
|
||||
files.clear();
|
||||
}
|
||||
|
||||
@ -323,6 +331,10 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
}
|
||||
else {
|
||||
log.info("Existing version " + oldVersion + " is up to date with " + newVersion + " for catalog " + catalog.getInputName() + ". Ignoring catalog.");
|
||||
|
||||
// [#5614] If a catalog is not regenerated, we must flag it as "not for removal", because its contents
|
||||
// will not be listed in the files directory.
|
||||
directoriesNotForRemoval.add(getStrategy().getFile(catalog).getParentFile());
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -361,6 +373,10 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
}
|
||||
else {
|
||||
log.info("Existing version " + oldVersion + " is up to date with " + newVersion + " for schema " + schema.getInputName() + ". Ignoring schema.");
|
||||
|
||||
// [#5614] If a schema is not regenerated, we must flag it as "not for removal", because its contents
|
||||
// will not be listed in the files directory.
|
||||
directoriesNotForRemoval.add(getStrategy().getFile(schema).getParentFile());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user