Repository: apache/flink
File: flink-runtime-web/src/main/java/org/apache/flink/runtime/webmonitor/history/HistoryServer.java (Java)

Code before:
        }
        archiveFetcher =
                new HistoryServerArchiveFetcher(
                        refreshDirs,
                        webDir,
                        jobArchiveEventListener,
                        cleanupExpiredArchives,
                        maxHistorySize);

        this.shutdownHook =
                ShutdownHookUtil.addShutdownHook(
                        HistoryServer.this::stop, HistoryServer.class.getSimpleName(), LOG);
    }

    private File prepareWebDir(Configuration config) throws IOException {
        final File webDir;
        String webDirectory = config.get(HistoryServerOptions.HISTORY_SERVER_WEB_DIR);
        if (webDirectory == null) {
            webDirectory =
                    System.getProperty("java.io.tmpdir")
                            + File.separator
                            + "flink-web-history-"
                            + UUID.randomUUID();
        }
        webDir = new File(webDirectory);
        LOG.info("Reset the web directory {}", webDir);
        if (webDir.exists() && webDir.isDirectory() && webDir.listFiles() != null) {
            // Reset the current working directory to eliminate the risk of local file leakage.
            // This is because when the current process is forcibly terminated by an external
            // command,
            // the hook methods for cleaning up local files will not be called.
            for (File subFile : webDir.listFiles()) {
                FileUtils.deleteFileOrDirectory(subFile);
            }
        }
        return webDir;
    }

    @VisibleForTesting
    File getWebDir() {
        return webDir;
    }

    @VisibleForTesting
    int getWebPort() {
        return netty.getServerPort();
    }

    @VisibleForTesting
    void fetchArchives() {
        executor.execute(getArchiveFetchingRunnable());

Review comment (suggestion):
nit: I suggest saying `Clear `or 'empty' rather than `Reset` - also the method name would be more self explanatory if it was` clearWebDir ` I, think. But it is up to you

Code after:
        }
        archiveFetcher =
                new HistoryServerArchiveFetcher(
                        refreshDirs,
                        webDir,
                        jobArchiveEventListener,
                        cleanupExpiredArchives,
                        maxHistorySize);

        this.shutdownHook =
                ShutdownHookUtil.addShutdownHook(
                        HistoryServer.this::stop, HistoryServer.class.getSimpleName(), LOG);
    }

    private File clearWebDir(Configuration config) throws IOException {
        String webDirectory = config.get(HistoryServerOptions.HISTORY_SERVER_WEB_DIR);
        if (webDirectory == null) {
            webDirectory =
                    System.getProperty("java.io.tmpdir")
                            + File.separator
                            + "flink-web-history-"
                            + UUID.randomUUID();
        }
        final File webDir = new File(webDirectory);
        LOG.info("Clear the web directory {}", webDir);
        if (webDir.exists() && webDir.isDirectory() && webDir.listFiles() != null) {
            // Reset the current working directory to eliminate the risk of local file leakage.
            // This is because when the current process is forcibly terminated by an external
            // command,
            // the hook methods for cleaning up local files will not be called.
            for (File subFile : webDir.listFiles()) {
                FileUtils.deleteFileOrDirectory(subFile);
            }
        }
        return webDir;
    }

    @VisibleForTesting
    File getWebDir() {
        return webDir;
    }

    @VisibleForTesting
    int getWebPort() {
        return netty.getServerPort();
    }

    @VisibleForTesting
    void fetchArchives() {
        executor.execute(getArchiveFetchingRunnable());
    }