Skip to content

Commit

Permalink
fixes #21 by creating/deleting the directory in the provider rather t…
Browse files Browse the repository at this point in the history
…han the factory. (#32)
  • Loading branch information
xgp authored Apr 29, 2024
1 parent ca232bb commit d0f5b01
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
<main.java.package>io.phasetwo.keycloak.themes</main.java.package>
<freemarker.version>2.3.31</freemarker.version>
<junit.version>5.8.2</junit.version>
<keycloak.version>24.0.0</keycloak.version>
<lombok.version>1.18.30</lombok.version>
<keycloak.version>24.0.3</keycloak.version>
<lombok.version>1.18.32</lombok.version>
<auto-service.version>1.1.1</auto-service.version>
<ossrh.url>https://s01.oss.sonatype.org</ossrh.url>
</properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.phasetwo.keycloak.themes.theme;

import com.google.common.collect.ImmutableSet;
import com.google.common.io.Files;
import java.io.File;
import java.io.IOException;
import java.util.Set;
Expand All @@ -16,9 +17,9 @@ public class AttributeThemeProvider implements ThemeProvider {
private final KeycloakSession session;
private final File tmpdir;

public AttributeThemeProvider(KeycloakSession session, File tmpdir) {
public AttributeThemeProvider(KeycloakSession session) {
this.session = session;
this.tmpdir = tmpdir;
this.tmpdir = Files.createTempDir();
}

public File getTmpDir() {
Expand Down Expand Up @@ -52,5 +53,12 @@ public boolean hasTheme(String name, Theme.Type type) {
}

@Override
public void close() {}
public void close() {
log.trace("Attempting to recursively delete tmpdir");
try {
AttributeThemeProviderFactory.deleteRecursively(tmpdir);
} catch (Exception e) {
log.warnf(e, "Error removing tmpdir", tmpdir);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.phasetwo.keycloak.themes.theme;

import com.google.auto.service.AutoService;
import com.google.common.io.Files;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
Expand All @@ -20,13 +19,10 @@ public class AttributeThemeProviderFactory implements ThemeProviderFactory {

public static final String PROVIDER_ID = "ext-theme-provider-attribute";

private File tmpdir;

@Override
public ThemeProvider create(KeycloakSession session) {
log.trace("Creating AttributeThemeProvider");
this.tmpdir = Files.createTempDir();
return new AttributeThemeProvider(session, tmpdir);
return new AttributeThemeProvider(session);
}

@Override
Expand All @@ -36,15 +32,9 @@ public void init(Config.Scope config) {}
public void postInit(KeycloakSessionFactory factory) {}

@Override
public void close() {
try {
deleteRecursively(tmpdir);
} catch (Exception e) {
log.warnf(e, "Error removing tmpdir", tmpdir);
}
}
public void close() {}

private static void deleteRecursively(File dir) throws IOException {
static void deleteRecursively(File dir) throws IOException {
Path toDelete = dir.toPath();

java.nio.file.Files.walk(toDelete)
Expand Down

0 comments on commit d0f5b01

Please sign in to comment.