Push Command.destroy down through DispatchCommand redirection
When we redirect through a DispatchCommand to a different name we need to ensure the destroy event is pushed down too, in case the daemon terminates before the command is run. Change-Id: Idc4446f4a0426aadcbb03c48ff2321071cded25b Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -37,6 +37,7 @@ final class DispatchCommand extends BaseCommand {
|
||||
private final Provider<CurrentUser> currentUser;
|
||||
private final String prefix;
|
||||
private final Map<String, Provider<Command>> commands;
|
||||
private Command cmd;
|
||||
|
||||
@Inject
|
||||
DispatchCommand(final Provider<CurrentUser> cu, @Assisted final String pfx,
|
||||
@@ -74,6 +75,11 @@ final class DispatchCommand extends BaseCommand {
|
||||
final Provider<Command> p = commands.get(name);
|
||||
if (p != null) {
|
||||
final Command cmd = p.get();
|
||||
|
||||
synchronized (this) {
|
||||
this.cmd = cmd;
|
||||
}
|
||||
|
||||
if (cmd.getClass().getAnnotation(AdminCommand.class) != null) {
|
||||
final CurrentUser u = currentUser.get();
|
||||
if (!u.isAdministrator()) {
|
||||
@@ -102,6 +108,16 @@ final class DispatchCommand extends BaseCommand {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
synchronized (this) {
|
||||
if (cmd != null) {
|
||||
cmd.destroy();
|
||||
cmd = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void usage() throws IOException, UnsupportedEncodingException {
|
||||
final StringBuilder usage = new StringBuilder();
|
||||
if (prefix.indexOf(' ') < 0) {
|
||||
|
Reference in New Issue
Block a user