Skip to content

Commit

Permalink
Merge pull request #394 from crowdin/improve-delete-obsolete
Browse files Browse the repository at this point in the history
Improve '--delete-obsolete' logic
  • Loading branch information
andrii-bodnar authored Sep 7, 2021
2 parents 444d876 + 87962a4 commit 5d54ac1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ public void act(Outputter out, PropertiesWithFiles pb, ProjectClient client) {
})
.collect(Collectors.toList());
ConcurrencyUtil.executeAndWaitSingleThread(tasks, debug);
if (deleteObsolete) {
deleteObsoleteProjectFilesSubAction.postAct();
}
if (errorsPresented.get()) {
throw new RuntimeException(RESOURCE_BUNDLE.getString("error.errors_presented"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public class DeleteObsoleteProjectFilesSubAction {
private Boolean preserveHierarchy;
private boolean plainView;

private boolean isAnyFileDeleted = false;
private boolean isAnyDirectoryDeleted = false;

public DeleteObsoleteProjectFilesSubAction(@NonNull Outputter out, @NonNull ProjectClient client) {
this.out = out;
this.client = client;
Expand Down Expand Up @@ -66,19 +69,25 @@ public void act(@NonNull String sourcePattern, List<String> ignorePatterns, @Non
if (!plainView) {
out.println(OK.withIcon(String.format(RESOURCE_BUNDLE.getString("message.delete_obsolete.obsolete_file_delete"), obsoleteProjectFilePath)));
}
}
if (obsoleteProjectFiles.isEmpty() && !plainView) {
out.println(OK.withIcon(RESOURCE_BUNDLE.getString("message.delete_obsolete.obsolete_directory_delete")));
isAnyFileDeleted = true;
}
for (String obsoleteDirPath : obsoleteDirs.keySet()) {
client.deleteDirectory(obsoleteDirs.get(obsoleteDirPath));
directoryIds.remove(obsoleteDirPath);
if (!plainView) {
out.println(OK.withIcon(String.format(RESOURCE_BUNDLE.getString("message.delete_obsolete.no_obsolete_files_found"), obsoleteDirPath)));
}
isAnyDirectoryDeleted = true;
}
}

public void postAct() {
if (!isAnyFileDeleted && !plainView) {
out.println(OK.withIcon(RESOURCE_BUNDLE.getString("message.delete_obsolete.obsolete_directory_delete")));
}
if (obsoleteDirs.isEmpty() && !plainView) {
if (!isAnyDirectoryDeleted && !plainView) {
out.println(OK.withIcon(RESOURCE_BUNDLE.getString("message.delete_obsolete.no_obsolete_directories_found")));
}
}

}

0 comments on commit 5d54ac1

Please sign in to comment.