-
Couldn't load subscription status.
- Fork 51
Add per-image scoped temp dir cleanup functions #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
1f7246d to
aa11ddc
Compare
Benchmark Test ResultsBenchmark results from the latest changes vs base branch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've made some great improvements here! Having the image creation provide its own cleanup function is excellent because it lets image cleanup be handled directly alongside a caller's use of the image. This makes it much easier for consumers to manage the side effects had by image creation operations.
(Quick aside: One alternative approach to consider would be to have the image's cleanup function be a method on the image itself. This way, any consumer of the image is capable of cleaning up the image's backing data (similar to how database connection objects frequently have a conn.Close() method).
Primary concern: We need to avoid global state wherever possible, since it creates opportunities for bugs to arise in the future and it typically complicates the codebase. Fortunately, because of the cleanup functions being associated with image creation, we have an opportunity to associate an image's temp data with the image object directly. This would eliminate the need to maintain a global store of temp directories, a maintenance that has gotten a bit more complicated in the current draft.
Image handling would become more atomic, and a consumer of any given image wouldn't need to know about anything more global than the image itself.
|
@luhring The leveraging of global state is unfortunate, but also an existing behavior today. This PR has made a step in removing that global state (with the cleanup functions). I think we need to sync up on context on Monday as some perspectives have been over simplified. |
|
We're deferring this work for now |
aa11ddc to
72a2782
Compare
e677dca to
980163d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Signed-off-by: Alex Goodman <[email protected]>
980163d to
2f2d423
Compare
Signed-off-by: Alex Goodman <[email protected]>
This PR changes the tempfile generation to share the same parent directory for the same call to
GetImageorGetImageFromSource. This change requires that cleanup functions are exposed on theseGetImage*calls to cleanup temp dirs created by that particular call.Today the temp file generation is globally handled with the
Cleanupfunction, which (correctly) breaks when used as a test cleanup function, since it affects global state. Test cleanup calls now leverage the more narrowly-scoped cleanup function returned fromGetImage*functions.This PR also opts to leave the global
Cleanupfunction in tact. Why? Callers (such as syft and grype) may need to interrupt the process and exit, but also make certain that any temp directories are cleaned up. This PR updates thefile.TempDirGeneratortracks all temp generators created and temp directories created from a root object such that the root object can cleanup all temp directories from all nested generators. This allows callers to have the "clean everything up and exit" option for exceptional cases (today, syft needs this).Specific changes:
file.TempDirGeneratorTempDirGeneratornow keeps all created temp dirs within a shared parent dir.TempDirGeneratorsfrom aTempDirGenerator, which will create a sibling temp dir with the same prefix as the parent prefix. All directories created from the child generator are persisted in the sibling temp dir from the parent generator.TempDirGenerator.Cleanupcalls cleanup on all child generators as well as removing the shared top directory among all created temp dirs for the generator.image.Image.Cleanup()deletes the temp dir scoped for that particular image.Partially addresses anchore/syft#416
Fixes #96