Skip to content

🐛 EnsureEmptyDirectory should recursively set writable perms prior to delete #1691

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

Merged
merged 1 commit into from
Feb 3, 2025

Conversation

joelanford
Copy link
Member

@joelanford joelanford commented Feb 3, 2025

This fix is required because If there are read-only files or directories in the cache dir when the process starts up (which can easily happen in catalogd), then we can't delete them and error out instead. This fix tries to set the files writable before deleting them.

Reviewer Checklist

  • API Go Documentation
  • Tests: Unit Tests (and E2E Tests, if appropriate)
  • Comprehensive Commit Messages
  • Links to related GitHub Issue(s)

@joelanford joelanford requested a review from a team as a code owner February 3, 2025 14:10
Copy link

netlify bot commented Feb 3, 2025

Deploy Preview for olmv1 ready!

Name Link
🔨 Latest commit 02b14c6
🔍 Latest deploy log https://app.netlify.com/sites/olmv1/deploys/67a0ee01b331900008e15f82
😎 Deploy Preview https://deploy-preview-1691--olmv1.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@joelanford joelanford changed the title 🐛 EnsureEmptyDirectory should recusrively set writable perms prior to delete 🐛 EnsureEmptyDirectory should recursively set writable perms prior to delete Feb 3, 2025
Copy link

codecov bot commented Feb 3, 2025

Codecov Report

Attention: Patch coverage is 45.45455% with 24 lines in your changes missing coverage. Please review.

Project coverage is 67.72%. Comparing base (9b08aea) to head (02b14c6).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
internal/fsutil/helpers.go 55.88% 10 Missing and 5 partials ⚠️
catalogd/internal/source/containers_image.go 0.00% 1 Missing and 4 partials ⚠️
internal/rukpak/source/containers_image.go 20.00% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1691      +/-   ##
==========================================
- Coverage   67.74%   67.72%   -0.03%     
==========================================
  Files          57       57              
  Lines        4620     4620              
==========================================
- Hits         3130     3129       -1     
- Misses       1265     1266       +1     
  Partials      225      225              
Flag Coverage Δ
e2e 53.35% <38.46%> (-0.09%) ⬇️
unit 54.48% <45.45%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

perdasilva
perdasilva previously approved these changes Feb 3, 2025
Copy link
Contributor

@azych azych left a comment

Choose a reason for hiding this comment

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

/lgtm

}

// DeleteReadOnlyRecursive deletes read-only directory with path given by `root`
func DeleteReadOnlyRecursive(root string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: would be nice to have the prerequisite of setting to writable mentioned in the doc

Copy link
Member Author

Choose a reason for hiding this comment

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

Setting to writable is not a prerequisite of this function. This function will attempt to set everything writable before attempting to delete.

Regardless, this PR is mainly about moving some existing code around to resolve a bug with EnsureEmptyDirectory, so I'd like to defer nice-to-have changes to a follow-up.

Copy link
Contributor

@azych azych Feb 3, 2025

Choose a reason for hiding this comment

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

  • setting everything writable is a prerequisite for actually recursively deleting root, which is what the function name and its doc comment says it will do
  • it would be nice to include that in the doc comment, that shouldn't be longer than 1 line
    Still it's a nit, so feel free to go with whatever you think works best

require.NoError(t, os.WriteFile(filePath, []byte("test"), ownerReadOnlyFileMode))
require.NoError(t, os.Chmod(nestedDir, ownerReadOnlyDirMode))

t.Log("Set directory structure as read-only")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: call DeleteReadOnlyRecursive

Copy link
Member Author

Choose a reason for hiding this comment

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

I call it in line 136. Is that what you were asking for?

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant that log comment should reflect the call

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I see. I added via DeleteReadOnlyRecursive in the latest push.

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Feb 3, 2025
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Feb 3, 2025
@oceanc80
Copy link
Contributor

oceanc80 commented Feb 3, 2025

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Feb 3, 2025
@joelanford joelanford enabled auto-merge February 3, 2025 16:59
Copy link
Member

@LalatenduMohanty LalatenduMohanty left a comment

Choose a reason for hiding this comment

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

/lgtm

@joelanford joelanford added this pull request to the merge queue Feb 3, 2025
@LalatenduMohanty
Copy link
Member

@joelanford mentioned this fix is required because If there are read-only files or directories in the cache dir when the process starts up (which can easily happen in catalogd), then we can't delete them and error out instead. This fix tries to set the files writable before deleting them.

@joelanford
Copy link
Member Author

Thanks for the update to the description @LalatenduMohanty

Merged via the queue into operator-framework:main with commit f77ebfa Feb 3, 2025
21 of 23 checks passed
@joelanford joelanford deleted the fix-cache-delete branch February 14, 2025 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants