Make buf generate --clean a per-plugin option that does a "smart" clean
See https://github.com/bufbuild/buf/pull/3124#issuecomment-2209407669 for an explanation.
For zip/tar files: sum the file beforehand, generate the new file, if there is a diff, overwrite, if the filename changed (somehow), delete the old one For directories: sum each file beforehand, generate the new files, for each file that no longer exists, delete, for each file that changed, overwrite
There are a few things happening here and I wonder if some of this should be separated out:
- For files that have not changed, ignore them
- For files that no longer exist, delete them
- For files where contents have changed, overwrite them
- For net new files, add them
For the first one, files that have not changed being ignored, would it be reasonable to implement this as the default behaviour of buf generate, regardless of the --clean flag/config? This seems like it would be backwards compatible.
Then --clean would only need to handle deleting files that no longer exist/have been renamed, overwriting files with new/different content, and adding new any new files.