mirror of
https://github.com/google/nomulus.git
synced 2025-04-30 12:07:51 +02:00
Cleanup gpg-agent instances and home directories (#1629)
* Cleanup gpg-agent instances and home directories The GpgSystemCommandException leaks home directories, but more importantly it leaks gpg-agent instances. This can cause problems with inotify limits, since the agent seems to make use of inotify. Do a proper cleanup in afterEach(). * Don't fail if we can't kill the agent
This commit is contained in:
parent
fd9fe398ae
commit
33ffcfdab3
1 changed files with 23 additions and 1 deletions
|
@ -21,6 +21,7 @@ import static com.google.common.base.Strings.isNullOrEmpty;
|
||||||
import static com.google.common.truth.Truth.assertWithMessage;
|
import static com.google.common.truth.Truth.assertWithMessage;
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
|
||||||
|
import com.google.common.flogger.FluentLogger;
|
||||||
import com.google.common.io.ByteSource;
|
import com.google.common.io.ByteSource;
|
||||||
import com.google.common.io.CharStreams;
|
import com.google.common.io.CharStreams;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -43,6 +44,7 @@ import org.junit.jupiter.api.extension.ExtensionContext;
|
||||||
*/
|
*/
|
||||||
public final class GpgSystemCommandExtension implements BeforeEachCallback, AfterEachCallback {
|
public final class GpgSystemCommandExtension implements BeforeEachCallback, AfterEachCallback {
|
||||||
|
|
||||||
|
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||||
private static final File DEV_NULL = new File("/dev/null");
|
private static final File DEV_NULL = new File("/dev/null");
|
||||||
private static final String TEMP_FILE_PREFIX = "gpgtest";
|
private static final String TEMP_FILE_PREFIX = "gpgtest";
|
||||||
|
|
||||||
|
@ -122,9 +124,29 @@ public final class GpgSystemCommandExtension implements BeforeEachCallback, Afte
|
||||||
.isEqualTo(0);
|
.isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void deleteTree(File dir) {
|
||||||
|
for (File file : dir.listFiles()) {
|
||||||
|
if (file.isDirectory()) {
|
||||||
|
deleteTree(file);
|
||||||
|
} else {
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dir.delete();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterEach(ExtensionContext context) {
|
public void afterEach(ExtensionContext context) {
|
||||||
// TODO(weiminyu): we should delete the cwd tree.
|
// Kill the gpg-agent.
|
||||||
|
try {
|
||||||
|
exec("gpgconf", "--homedir", conf.getPath(), "--kill", "gpg-agent");
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.atInfo().log("Unable to kill gpg-agent: %s", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean up the temporary directory.
|
||||||
|
deleteTree(cwd);
|
||||||
|
|
||||||
cwd = DEV_NULL;
|
cwd = DEV_NULL;
|
||||||
conf = DEV_NULL;
|
conf = DEV_NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue