-
Notifications
You must be signed in to change notification settings - Fork 126
Skip .DS_Store folder and swp files (ViM) in the build command #2471
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
internal/files/copy.go
Outdated
regexesFiles := []*regexp.Regexp{} | ||
for _, regexFile := range skippedFiles { | ||
r, err := regexp.Compile(regexFile) | ||
if err != nil { | ||
return fmt.Errorf("failed to compile regex %q: %w", r, err) | ||
} | ||
regexesFiles = append(regexesFiles, r) | ||
} |
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.
Pre-compile all regexes before calling to the Walk()
function
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.
Maybe this function can directly receive compiled regexps. Or would it be enough to use glob patterns instead of regexes?
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.
Updated the code to use glob patterns instead of regexes: b91048e
As everything should be file names glob, patterns should be enough.
internal/files/copy.go
Outdated
} | ||
|
||
// CopyWithoutDev method copies files from the source to the destination, but skips _dev directories and empty folders. | ||
func CopyWithoutDev(sourcePath, destinationPath string) error { | ||
return CopyWithSkipped(sourcePath, destinationPath, []string{"_dev", "build", ".git"}) | ||
return CopyWithSkipped(sourcePath, destinationPath, []string{"_dev", "build", ".git"}, []string{"\\.DS_Store", "\\..*\\.swp"}) |
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.
Added support to skip files based on their file names if they match some of these regexes.
/test |
/test |
internal/files/copy.go
Outdated
} | ||
|
||
// CopyWithoutDev method copies files from the source to the destination, but skips _dev directories and empty folders. | ||
func CopyWithoutDev(sourcePath, destinationPath string) error { | ||
return CopyWithSkipped(sourcePath, destinationPath, []string{"_dev", "build", ".git"}) | ||
return CopyWithSkipped(sourcePath, destinationPath, []string{"_dev", "build", ".git"}, []string{"^\\.DS_Store$", "^\\..*\\.swp$"}) |
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. Move these lists of dirs and patterns to variables.
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.
Created const definitions here b91048e
internal/files/copy.go
Outdated
regexesFiles := []*regexp.Regexp{} | ||
for _, regexFile := range skippedFiles { | ||
r, err := regexp.Compile(regexFile) | ||
if err != nil { | ||
return fmt.Errorf("failed to compile regex %q: %w", r, err) | ||
} | ||
regexesFiles = append(regexesFiles, r) | ||
} |
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.
Maybe this function can directly receive compiled regexps. Or would it be enough to use glob patterns instead of regexes?
💚 Build Succeeded
History
cc @mrodm |
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.
Thanks 👍
Closes #2463
Add exceptions to skip some hidden files when running
elastic-package build
.This PR skips the copy to the build directory (and zip file) the following files (using glob patterns):
.DS_Store
files created in macOS.*.swp
files created by ViMHow to test this PR locally