Skip to content
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

Refactor CheckPath util function. #168

Merged
merged 1 commit into from
Feb 20, 2025
Merged

Refactor CheckPath util function. #168

merged 1 commit into from
Feb 20, 2025

Conversation

vishal4071
Copy link
Contributor

@vishal4071 vishal4071 commented Feb 5, 2025

CheckPath function from utils/util.go gives a false sense of security, that the checked path exists, but this is susceptible to race conditions (where a path may already be gone as soon as this function returns). The functions using the CheckPath function after using it call things that may also return error, making the Check redundant.
Hence function, and the call is being removed.

Fixes: BUG1064014

@manith-arista
Copy link
Contributor

Adding @mkisielewski-arista to this review.

My understanding of the requirement is that we intend to get rid of the file checks altogether, since:

  1. A race condition might result in a false positive
  2. Subsequent functions which use the file would anyway fail with an error if file was not present, hence making this check redundant.

If that is the case, we don't want to replace util.CheckPath() with os.Stat() checks, instead we want to remove util.CheckPath() altogether, and ensure that the code is able to exit gracefully even without this check.

@manith-arista
Copy link
Contributor

manith-arista commented Feb 20, 2025

Code changes look good.
Few things to keep in mind regarding future reviews:

  1. Make the commit message descriptive, it makes it easy to understand the context later.
  2. Follow branch naming convention name.feature or name-feature for future
  3. Add FIXES: BUGxxx in the commit description to update Bugsby, not PR description

CheckPath function from utils/util.go gives a false sense of security, that the checked path exists, but this is susceptible to race conditions (where a path may already be gone as soon as this function returns). The functions using the CheckPath function after using it call things that may also return error, making the Check redundant.
Hence function, and the call is being removed.

Fixes: BUG1064014
@vishal4071
Copy link
Contributor Author

Done,Thanks! Manith, I will take care from now onwards as per your suggestion.

@vishal4071 vishal4071 merged commit 41b7321 into main Feb 20, 2025
2 checks passed
@vishal4071 vishal4071 deleted the ment1 branch February 20, 2025 17:54
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