GP-3952 Updated the script categories to simplify and reduce the number of folders.

This commit is contained in:
ghidra_blue 2025-06-13 15:00:15 +00:00
parent 7772d98143
commit 7db176b2bd
82 changed files with 885 additions and 981 deletions

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -14,7 +14,7 @@
* limitations under the License.
*/
//Script to allow repository admins the ability to terminate multiple file checkouts belonging to a single user.
//@category MultiUser
//@category Update
import java.io.IOException;
@ -33,25 +33,25 @@ public class RemoveUserCheckoutsScript extends GhidraScript {
@Override
protected void run() throws Exception {
Project project = state.getProject();
ProjectData projectData = project.getProjectData();
RepositoryAdapter repository = projectData.getRepository();
if (repository == null) {
printerr("Project is not a shared project");
return;
}
User currentUser = repository.getUser();
if (!currentUser.isAdmin()) {
printerr("You are not a repository administrator for " + repository.getName());
return;
}
String uname = askString("Remove User Checkouts" , "Enter user ID to be cleared");
String uname = askString("Remove User Checkouts", "Enter user ID to be cleared");
boolean found = false;
for (User u : repository.getUserList()) {
if (uname.equals(u.getName())) {
@ -61,31 +61,34 @@ public class RemoveUserCheckoutsScript extends GhidraScript {
}
if (!found) {
if (OptionDialog.showYesNoDialogWithNoAsDefaultButton(null, "User Name Confirmation",
"User '" + uname + "' not a registered server user.\nDo you still want to search for and remove checkouts for this user?") != OptionDialog.YES_OPTION) {
"User '" + uname +
"' not a registered server user.\nDo you still want to search for and remove checkouts for this user?") != OptionDialog.YES_OPTION) {
return;
}
}
if (projectData.getFileCount() > 1000) {
if (OptionDialog.showYesNoDialogWithNoAsDefaultButton(null, "Large Repository Confirmation",
"Repository contains a large number of failes and could be slow to search.\nDo you still want to search for and remove checkouts?") != OptionDialog.YES_OPTION) {
if (OptionDialog.showYesNoDialogWithNoAsDefaultButton(null,
"Large Repository Confirmation",
"Repository contains a large number of failes and could be slow to search.\nDo you still want to search for and remove checkouts?") != OptionDialog.YES_OPTION) {
return;
}
}
int count = removeCheckouts(repository, "/", uname, monitor);
popup("Removed " + count + " checkouts");
}
private String getPath(String folderPath, String childName) {
if (!folderPath.endsWith("/")) {
folderPath += "/";
}
return folderPath + childName;
}
private int removeCheckouts(RepositoryAdapter repository, String folderPath, String uid, TaskMonitor monitor) throws IOException, CancelledException {
private int removeCheckouts(RepositoryAdapter repository, String folderPath, String uid,
TaskMonitor monitor) throws IOException, CancelledException {
int count = 0;
for (RepositoryItem item : repository.getItemList(folderPath)) {
monitor.checkCancelled();
@ -96,16 +99,20 @@ public class RemoveUserCheckoutsScript extends GhidraScript {
}
return count;
}
private int removeCheckouts(RepositoryAdapter repository, RepositoryItem item, String uid) throws IOException {
private int removeCheckouts(RepositoryAdapter repository, RepositoryItem item, String uid)
throws IOException {
int count = 0;
ItemCheckoutStatus[] checkouts = repository.getCheckouts(item.getParentPath(), item.getName());
ItemCheckoutStatus[] checkouts =
repository.getCheckouts(item.getParentPath(), item.getName());
for (ItemCheckoutStatus checkout : checkouts) {
if (uid.equals(checkout.getUser())) {
try {
repository.terminateCheckout(item.getParentPath(), item.getName(), checkout.getCheckoutId(), false);
repository.terminateCheckout(item.getParentPath(), item.getName(),
checkout.getCheckoutId(), false);
++count;
} catch (IOException e) {
}
catch (IOException e) {
printerr("Failed to remove checkout: " + e.getMessage());
}
}