Skip to content

Conversation

@mirror-shades
Copy link
Contributor

@mirror-shades mirror-shades commented May 30, 2025

Keep/Clean Releases

Description

Added commands to manage which Zig versions are kept or removed from cache

Changes

  • Added new subcommands:
    • any keep VERSION: Prevents a version from being removed
    • any clean: Removes all non-kept versions
    • any force-remove VERSION: Force removes a version (bypasses keep)
  • Added persistent keep markers using keep files in version directories
  • Enhanced list-installed to show kept status
  • Added utility functions:
    • keepCompiler() - Creates keep markers
    • cleanReleases() - Cleans non-kept versions
    • removeRelease() - Handles version deletion
  • Improved error handling for concurrent operations

Testing

  • Verified functionality on windows and arch linux (x64)

Notes

  • Keep system helps prevent accidental removal of important versions
  • Clean command helps manage cache size while respecting kept versions
  • Force-remove provides a method of removing kept versions
  • Similar keep file implementation to Zigup

@mirror-shades mirror-shades mentioned this pull request May 30, 2025
@marler8997
Copy link
Owner

marler8997 commented Jun 2, 2025

We seem to be lacking a normal "remove" command to remove a compiler that's not been marked to keep. I'm not sure we need a distinction between removing a version that's been marked to keep or not, if the user has explicitly asked anyzig to remove a specific version, I think we can infer they no longer want to keep it. With that, we could implement all the use cases by enhancing clean to take an optional version (or versions...).

@mirror-shades
Copy link
Contributor Author

mirror-shades commented Jun 2, 2025

There is a force-remove command which removes a single version regardless of its keep status. I chose force-remove only to be more explicit that it doesn't check for keep files, so in this case the fix should just be a matter of changing the command name. I can do that tonight. Or would you prefer a single command clean with optional arguments? I like more explicit commands but I understand wanting to keep the api simple

@marler8997
Copy link
Owner

I think I'd prefer just one command with optional arguments.

zig any clean [VERSIONS....]

@mirror-shades
Copy link
Contributor Author

Should be working as expected now

src/main.zig Outdated
try stdout.print("{}\t{s}{s}{s}\n", .{ version, p_path, std.fs.path.sep_str, hash });

// Check for keep file
const keep_file_path = try std.fs.path.join(global.arena, &.{ p_path, hash, "keep" });
Copy link
Owner

Choose a reason for hiding this comment

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

We should store the keep files in anyzig's appdata directory, not in zig's global cache directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is there any specific value in having the keep file outside of the release folder? by my eyes the current implementation actually makes the removal process a bit simpler

Copy link
Owner

@marler8997 marler8997 Jun 5, 2025

Choose a reason for hiding this comment

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

I'm not sure what you mean by "release folder"? You're storing the keep files in zig's global cache which horribly breaks how zig's caching system works. You've modified the contents of a "content addressable store"...which...would mean you'd need to change the path of what you're storing because you changed it's content.

It's the same idea as modifying the contents of a git commit and without updating the commit hash.

Copy link
Contributor Author

@mirror-shades mirror-shades Jun 5, 2025

Choose a reason for hiding this comment

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

Oh I see, I had some false assumptions about how the caching system works. I thought it was specific to the executable, not the folder contents. This makes a lot of sense, I will have to rework.

@mirror-shades
Copy link
Contributor Author

Let me know what you think about this implementation. It now creates/finds a kept-releases folder in the anyzig data folder to store keep files.

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.

2 participants