MCPcopy Index your code
hub / github.com/GerritCodeReview/gerrit / InitCache

Class InitCache

java/com/google/gerrit/pgm/init/InitCache.java:33–92  ·  view source on GitHub ↗

Initialize the cache configuration section.

Source from the content-addressed store, hash-verified

31
32/** Initialize the {@code cache} configuration section. */
33@Singleton
34class InitCache implements InitStep {
35 private final ConsoleUI ui;
36 private final InitFlags flags;
37 private final SitePaths site;
38 private final Section cache;
39
40 @Inject
41 InitCache(
42 final ConsoleUI ui,
43 final InitFlags flags,
44 final SitePaths site,
45 final Section.Factory sections) {
46 this.ui = ui;
47 this.flags = flags;
48 this.site = site;
49 this.cache = sections.get("cache", null);
50 }
51
52 @Override
53 public void run() {
54 ui.header("Cache");
55 String path = cache.get("directory");
56
57 if (path != null && path.isEmpty()) {
58 // Explicitly set to empty implies the administrator has
59 // disabled the on disk cache and doesn't want it enabled.
60 //
61 return;
62 }
63
64 if (path == null) {
65 path = "cache";
66 cache.set("directory", path);
67 }
68
69 Path loc = site.resolve(path);
70 FileUtil.mkdirsOrDie(loc, "cannot create cache.directory");
71 List<Path> cacheFiles = new ArrayList<>();
72 try (DirectoryStream<Path> stream = Files.newDirectoryStream(loc, "*.{lock,h2,trace}.db")) {
73 for (Path entry : stream) {
74 cacheFiles.add(entry);
75 }
76 } catch (IOException e) {
77 ui.message("IO error during cache directory scan");
78 return;
79 }
80 if (!cacheFiles.isEmpty()) {
81 for (Path entry : cacheFiles) {
82 if (flags.deleteCaches || ui.yesno(false, "Delete cache file %s", entry)) {
83 try {
84 Files.deleteIfExists(entry);
85 } catch (IOException e) {
86 ui.message("Could not delete " + entry);
87 }
88 }
89 }
90 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected