-
Notifications
You must be signed in to change notification settings - Fork 67
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
Fix the package not loading if it has an accidental file left in the package root directory. #673
Conversation
…root. Fix the package not loading if it has an accidental file in the package root directory. Log the error and load the remaining sibling directories.
💚 Build Succeeded
Expand to view the summary
Build stats
Test stats 🧪
|
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.
Can you add a changelog entry?
util/packages.go
Outdated
// Fixes an annoying problem when the .DS_Store file is left behind and the package | ||
// is not loading without any error information | ||
log.Printf("error: unexpected file: %s", path) | ||
return nil |
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.
I wonder if we should return an error instead. This is at first inconvenient for the developer working with the package because he has to fix it but it assures no "invalid" files are inside the package.
@mtojek @ycombinator Do we have any validation in place in elastic-package check
that would detect these files?
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.
I'm wondering how did @aleksmaus run into this issue? Have you been using the elastic-package to boot up the stack? Did you interact with OSX file browser?
@ruflin This directory is not part of a package (look at the path). It's a bug in package-registry. Speaking about validation, there is such one in place, but there are places in which it's not a bug but a feature, like e.g. a package root. It's hard to detect these files as the end-user may include additional READMEs, license notes, etc.
For reference: https://github.com/elastic/package-spec/blob/master/versions/1/spec.yml#L8
@aleksmaus I don't think we need to fail the entire application in case of noticing strange files. It will be more convenient to the end-user to skip this files. Could you try this piece of code?
if info.IsDir() {
log.Printf("%-20s\t%10s\t%s", dirs[0], dirs[1], path)
foundPaths = append(foundPaths, path)
return filepath.SkipDir
}
return nil
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.
Mac OS finder creates these pesky .DS_Store files for Finder app.
This change doesn't fail the whole app, it keeps loading the package versions.
Before the change, stumbling on such file (not dir code path) was returning filepath.SkipDir which skips all the siblings directories.
In my case the directory layout was
.DS_Store
0.1.0
0.1.2
And the existing code was stumbling upon .DS_Store file first and since it was not directory the default code path was always returning filepath.SkipDir
From documentation of filepath.Walk:
If the function returns SkipDir when invoked on a non-directory file, Walk skips the remaining files in the containing directory.
Sure can update the code the sample you provided, it's pretty much the same what my code does.
Would still like to keep the log statement pointing at the error during load.
@@ -74,8 +74,13 @@ func getPackagePaths(allPaths []string) ([]string, error) { | |||
if info.IsDir() { |
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.
I would take this opportunity to make this check a bit stronger.
If the execution reaches this line, we know that we should be looking at a directory whose name is a version. So how about we not only check if info.IsDir()
but also check that dirs[1]
is a semver? That way we handle not only the unexpected file case but also the unexpected folder case as well.
util/packages.go
Outdated
// Not expected file, return nil in order to continue processing sibling directories | ||
// Fixes an annoying problem when the .DS_Store file is left behind and the package | ||
// is not loading without any error information | ||
log.Printf("error: unexpected file: %s", path) |
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.
Nit: consider changing this to a warning
instead of an error
and also mention that we're simply ignoring the unexpected file. That way the person looking at these logs knows this is not a severe problem to worry about.
580d5c7
to
8f1f28a
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.
LGTM. Thanks for finding and fixing this!
@aleksmaus Apologies for not catching this earlier, but would you mind making a follow up PR to add a CHANGELOG entry for the change in this PR? Thank you. https://github.com/elastic/package-registry/blob/master/CHANGELOG.md |
Fix the package not loading if it has an accidental file in the package root directory.
Log the error and load the remaining sibling directories.
Addresses #672