Skip to content

Clean up old binary versions after download#3252

Open
Catnap7 wants to merge 2 commits into
tari-project:mainfrom
Catnap7:codex/cleanup-old-binary-versions
Open

Clean up old binary versions after download#3252
Catnap7 wants to merge 2 commits into
tari-project:mainfrom
Catnap7:codex/cleanup-old-binary-versions

Conversation

@Catnap7

@Catnap7 Catnap7 commented May 22, 2026

Copy link
Copy Markdown

Summary

Fixes #3028 by cleaning up stale downloaded binary version folders after a binary version is resolved.

This change:

  • removes older version directories from the binary download folder after the current version is downloaded or already present
  • keeps the selected versions for all managers that share the same binary folder, so shared Tari suite binaries are not removed prematurely
  • ignores non-version sibling directories and files such as caches/checksums
  • logs cleanup failures without failing the download/startup path, so a locked old file does not break recovery
  • adds focused unit coverage for retained shared versions, non-version siblings, and missing parent folders

Verification

  • git diff --check

I could not run cargo fmt --check or cargo test cleanup_old_binary_versions --lib in this Windows environment because cargo/rustc are not installed on PATH here.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a cleanup mechanism for old binary versions within the binaries_manager.rs file. It adds a new function, cleanup_old_binary_versions, which iterates through the binary directory and removes any subdirectories that do not match the current version, accompanied by relevant unit tests. The reviewer suggested improving the robustness of this cleanup logic by ensuring the process continues even if an individual directory removal fails, rather than exiting early on the first error.

Comment on lines +515 to +534
for entry in std::fs::read_dir(binary_folder)? {
let entry = entry?;
let path = entry.path();

if !path.is_dir() {
continue;
}

if entry.file_name().to_string_lossy() == current_version {
continue;
}

std::fs::remove_dir_all(&path)?;
info!(
target: LOG_TARGET_APP_LOGIC,
"Removed old binary version folder: {}",
path.display()
);
removed_paths.push(path);
}

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.

medium

The current implementation of cleanup_old_binary_versions stops immediately if it fails to read a directory entry or remove a specific folder (due to the ? operator). This means that if one old version directory is locked or inaccessible (common on Windows), other potentially removable old versions will be left behind. It is more robust to log the error for the failing entry and continue the loop to ensure as much cleanup as possible is performed.

    for entry in std::fs::read_dir(binary_folder)? {
        let Ok(entry) = entry else { continue };
        let path = entry.path();

        if !path.is_dir() || entry.file_name().to_string_lossy() == current_version {
            continue;
        }

        match std::fs::remove_dir_all(&path) {
            Ok(_) => {
                info!(
                    target: LOG_TARGET_APP_LOGIC,
                    "Removed old binary version folder: {}",
                    path.display()
                );
                removed_paths.push(path);
            }
            Err(error) => {
                warn!(
                    target: LOG_TARGET_APP_LOGIC,
                    "Failed to remove old binary version folder {}: {error:?}",
                    path.display()
                );
            }
        }
    }

@Catnap7 Catnap7 May 22, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Addressed in 1dbce200: remove_dir_all failures are now logged and skipped so cleanup continues with later old version folders. Entry and file-type read failures were already handled the same way.

git diff --check passes locally; Rust tests still cannot run in this Windows environment because cargo is not installed on PATH.

@Catnap7 Catnap7 force-pushed the codex/cleanup-old-binary-versions branch from 9d15d76 to d5e1fe2 Compare May 22, 2026 18:32
Verification on Windows:

- git diff --check origin/main...HEAD

Rust tests were not rerun because cargo is not installed on PATH in this environment.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cleanup old binary files

1 participant