Skip to content

#2372: Add --retention-delay option to ide cleanup - #2378

Open
krystynaShatkovska wants to merge 2 commits into
devonfw:mainfrom
krystynaShatkovska:feature/issue-2372-retention-delay
Open

#2372: Add --retention-delay option to ide cleanup#2378
krystynaShatkovska wants to merge 2 commits into
devonfw:mainfrom
krystynaShatkovska:feature/issue-2372-retention-delay

Conversation

@krystynaShatkovska

@krystynaShatkovska krystynaShatkovska commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

This PR fixes #2372

Implemented changes:

Adds a --retention-delay option to ide cleanup. It takes an ISO-8601 duration (e.g. P30D, PT2H30M; default 1 year) and deletes stale files (not modified within that period) in $IDE_HOME/updates, $IDE_ROOT/_ide/tmp and ~/Downloads/ide. After deletion it deletes empty folders (but keeps the scanned roots). Invalid durations are rejected with a clear error.

Testing instructions

  1. Automated tests
    Run the test class; it covers all the core cases:
    mvn -pl cli test -Dtest=CleanupCommandletTest

  2. Manual test
    a.Create a test file in each scanned folder and backdate it so it's older than your retention delay:
    (create a "stale" file older than 30 days)
    New-Item -Path "$IDE_HOME\updates\stale.bin" -Value "x" -Force
    (Get-Item "$IDE_HOME\updates\stale.bin").LastWriteTime = (Get-Date).AddDays(-31)
    b Run cleanup with a retention delay shorter than the file's age:
    ide cleanup --retention-delay=P30D

  3. Confirm the stale file is gone, and that a recent file in the same folder is kept:

  4. Test-Path "$IDE_HOME/updates/stale.bin" (expected: False)

  5. Verify invalid input is rejected:
    ide cleanup --retention-delay=PT6M10D


Checklist for this PR

Make sure everything is checked before merging this PR. For further info please also see
our DoD.

  • When running mvn clean test locally all tests pass and build is successful
  • PR title is of the form #«issue-id»: «brief summary» (e.g. #921: fixed setup.bat and not feature/921 fixed setup.bat). If no issue ID exists, title only.
  • PR top-level comment summaries what has been done and contains link to addressed issue(s)
  • PR and issue(s) have suitable labels
  • Issue is set to In Progress and assigned to you or there is no issue (might happen for very small PRs)
  • You followed all coding conventions
  • You have added the issue implemented by your PR in CHANGELOG.adoc unless issue is labelled
    with internal
  • You have not changed any dependency in pom.xml files or otherwise if runtime dependencies changed, you have updated our LICENSE.asciidoc
  • You have formulated clear instructions on how to test your contribution under "Testing instructions"

Adds a --retention-delay option to the cleanup commandlet to delete stale
files that have not been modified within a configurable period. Files are
scanned recursively under $IDE_HOME/updates, $IDE_ROOT/_ide/tmp and
~/Downloads/ide.

The option accepts a time-based ISO-8601 duration (e.g. P30D) and defaults
to 1 year (365 days) if not provided. Empty folders left behind after
deleting stale files are removed, while the scanned roots themselves are kept.
@coveralls

coveralls commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 33050346294

Coverage increased (+0.07%) to 73.694%

Details

  • Coverage increased (+0.07%) from the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • 10 coverage regressions across 2 files.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

10 previously-covered lines in 2 files lost coverage.

File Lines Losing Coverage Coverage
com/devonfw/tools/ide/commandlet/cleanup/CleanupCommandlet.java 9 91.34%
com/devonfw/tools/ide/version/VersionSegment.java 1 91.86%

Coverage Stats

Coverage Status
Relevant Lines: 18260
Covered Lines: 14064
Line Coverage: 77.02%
Relevant Branches: 8110
Covered Branches: 5369
Branch Coverage: 66.2%
Branches in Coverage %: Yes
Coverage Strength: 3.29 hits per line

💛 - Coveralls

@krystynaShatkovska krystynaShatkovska moved this from 🆕 New to Team Review in IDEasy board Aug 27, 2026
@samuelkos17 samuelkos17 self-assigned this Aug 27, 2026

@samuelkos17 samuelkos17 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the --retention-dely to the cleanup commandlet. I tried to follow your testing steps, however the commands you provided didn't work out for me. I've manually moved the files to /_ide/tmp though and then ran the cleanup command and it worked!
While reviewing I found some problems that could lead to issues and that really need to get addressed before moving this to In Review. You can find them in the Comments here.
Besides that I still have on recommendation:
documentation/tmp.adoc line 18 needs to be updated according to the new functionality.

Comment on lines +104 to +117
private Duration getRetentionDelay() {

String value = this.retentionDelay.getValueAsString();
if (value == null) {
return DEFAULT_RETENTION_DELAY;
}
try {
return Duration.parse(value);
} catch (DateTimeParseException e) {
throw new CliException(
"Invalid value '" + value + "' for --retention-delay. Please provide a time-based ISO-8601 duration such as P30D or PT2H30M.",
e);
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duration.parse() legally accepts negative and zero values. This means it won't throw the CliException and later down the line in isStale() every file under all roots becomes stale, which leads to every file being deleted. You should add a positivity check here.

Comment on lines +433 to +446
private void discoverStaleFilesRecursive(Path folder, Duration retentionDelay, List<Path> staleFiles) {

if (!Files.isDirectory(folder)) {
return;
}

for (Path child : this.context.getFileAccess().listChildren(folder, child -> true)) {
if (Files.isDirectory(child)) {
discoverStaleFilesRecursive(child, retentionDelay, staleFiles);
} else if (isStale(child, retentionDelay)) {
staleFiles.add(child);
}
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Files.isDirectory(child) follows links. If a symlink inside any root (e.g. ~/Downloads/ide/work -> C:\data) makes the scan descend outside the roots and delete the target's stale files, which would be a huge problem. Furthermore a self-referencing link causes unbounded recursion. You need to check for link children here and skip these.

Comment on lines 14 to 15
cmd.cleanup=Commandlet to clean up the IDEasy installation by uninstalling all unused tools.
cmd.cleanup.detail=This will remove any installed tools that are currently not in use by an IDEasy project. Before anything is deleted you are asked for confirmation. Run "ide -b -f cleanup" to skip the confirmation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be updated to match the new functionality.

Comment on lines 14 to 15
cmd.cleanup=Werkzeug zum Aufräumen der IDEasy-Installation durch Deinstallieren aller ungenutzten Werkzeuge.
cmd.cleanup.detail=Dies wird alle installierten Werkzeuge entfernen, die derzeit von keinem IDEasy-Projekt verwendet werden. Bevor etwas gelöscht wird, wirst du um Bestätigung gebeten. Führe "ide -b -f cleanup" aus, um die Bestätigung zu überspringen.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be updated to match the new functionality.

cmd.claude.detail=Claude Code CLI ist ein KI-gestützter Programmierassistent, der über die Befehlszeile ausgeführt wird. Detaillierte Dokumentation ist zu finden unter https://code.claude.com/docs/de/overview
cmd.cleanup=Werkzeug zum Aufräumen der IDEasy-Installation durch Deinstallieren aller ungenutzten Werkzeuge.
cmd.cleanup.detail=Dies wird alle installierten Werkzeuge entfernen, die derzeit von keinem IDEasy-Projekt verwendet werden. Bevor etwas gelöscht wird, wirst du um Bestätigung gebeten. Führe "ide -b -f cleanup" aus, um die Bestätigung zu überspringen.
cmd.cleanup.opt.--retention-delay=die Aufbewahrungsdauer von Dateien in den Ordnern 'updates', '_ide/tmp' und 'Downloads/ide', d.h. Dateien, die innerhalb dieses Zeitraums nicht modifiziert wurden, werden als veraltet gelöscht. Eine zeitbasierte ISO-8601-Dauer (z. B. 'P30D' für 30 Tage oder 'PT2H30M' für 2 Stunden und 30 Minuten). Standardmäßig 1 Jahr (365 Tage), wenn nicht angegeben.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cmd.cleanup.opt.--retention-delay=die Aufbewahrungsdauer von Dateien in den Ordnern 'updates', '_ide/tmp' und 'Downloads/ide', d.h. Dateien, die innerhalb dieses Zeitraums nicht modifiziert wurden, werden als veraltet gelöscht. Eine zeitbasierte ISO-8601-Dauer (z. B. 'P30D' für 30 Tage oder 'PT2H30M' für 2 Stunden und 30 Minuten). Standardmäßig 1 Jahr (365 Tage), wenn nicht angegeben.
cmd.cleanup.opt.--retention-delay=Die Altersgrenze von Dateien in den Ordnern 'updates', '_ide/tmp' und 'Downloads/ide', d.h. Dateien, die innerhalb dieses Zeitraums nicht modifiziert wurden, werden als veraltet gelöscht. Eine zeitbasierte ISO-8601-Dauer (z. B. 'P30D' für 30 Tage oder 'PT2H30M' für 2 Stunden und 30 Minuten). Standardmäßig 1 Jahr (365 Tage), wenn nicht angegeben.

Furthermore the folders you mention here are correct for Windows and Linux, however on macOS there are somewhere else, maybe just remove the path descriptions and describe the folders?

if (hasSoftwareToDelete(installedSoftware.getTools())) {
List<Path> staleRoots = new ArrayList<>();
List<Path> staleFiles = new ArrayList<>();
if (this.context.getIdeHome() != null) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if-guard prevents any clean-up from happening, however _ide/tmp and the download cache cleanup would work when IDE_HOME is null. I'm not sure if this intentional, but you might want to change that if it's not.

cmd.claude.detail=Claude Code CLI is a command-line interface for interacting with the Claude AI assistant. Detailed documentation can be found at https://code.claude.com/docs/en/overview
cmd.cleanup=Commandlet to clean up the IDEasy installation by uninstalling all unused tools.
cmd.cleanup.detail=This will remove any installed tools that are currently not in use by an IDEasy project. Before anything is deleted you are asked for confirmation. Run "ide -b -f cleanup" to skip the confirmation.
cmd.cleanup.opt.--retention-delay=the retention period of files in the 'updates', '_ide/tmp' and 'Downloads/ide' folders, i.e. files that were not modified within this period are deleted as stale. A time-based ISO-8601 duration (e.g. 'P30D' for 30 days or 'PT2H30M' for 2 hours and 30 minutes). Defaults to 1 year (365 days) if not provided.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cmd.cleanup.opt.--retention-delay=the retention period of files in the 'updates', '_ide/tmp' and 'Downloads/ide' folders, i.e. files that were not modified within this period are deleted as stale. A time-based ISO-8601 duration (e.g. 'P30D' for 30 days or 'PT2H30M' for 2 hours and 30 minutes). Defaults to 1 year (365 days) if not provided.
cmd.cleanup.opt.--retention-delay=The retention period of files in the 'updates', '_ide/tmp' and 'Downloads/ide' folders, i.e. files that were not modified within this period are deleted as stale. A time-based ISO-8601 duration (e.g. 'P30D' for 30 days or 'PT2H30M' for 2 hours and 30 minutes). Defaults to 1 year (365 days) if not provided.

Furthermore the folders you mention here are correct for Windows and Linux, however on macOS there are somewhere else, maybe just remove the path descriptions and describe the folders?

@@ -1,16 +1,22 @@
package com.devonfw.tools.ide.commandlet;

import static org.assertj.core.api.Assertions.assertThatThrownBy;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import static org.assertj.core.api.Assertions.assertThatThrownBy;

dead code


LOG.debug("Start cleanup commandlet");

Duration retentionDelay = getRetentionDelay();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to rename this since you already have a StringProperty called retentionDelay in the class.

Comment on lines +504 to +514
private void logStaleFilesToBeDeleted(List<Path> staleFiles, Duration retentionDelay) {

if (staleFiles.isEmpty()) {
LOG.info("No stale files older than {} will be deleted.", retentionDelay);
} else {
for (Path staleFile : staleFiles) {
LOG.info("\t - {} will be deleted", staleFile);
}
LOG.info("Summary: {} stale file(s) older than {} will be deleted.", staleFiles.size(), retentionDelay);
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to format the duration human-readably.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: Team Review

Development

Successfully merging this pull request may close these issues.

Implement --retention-delay option for ide cleanup (stale files in updates, _ide/tmp and ~/Downloads/ide)

3 participants