-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In some cases, there are files that may be useful, but should not be part of artifact. The ability to add files and directories to the .packignore file has been added, which allows you to ignore these files and directories when packing. Closes: [812](#812)
- Loading branch information
Showing
8 changed files
with
95 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package pack | ||
|
||
import ( | ||
"bufio" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
// readPackIgnore reads the .packignore file and returns a slice of ignore patterns. | ||
func readPackIgnore(projectPath string) (map[string]struct{}, error) { | ||
ignoreFilePath := filepath.Join(projectPath, ".packignore") | ||
file, err := os.Open(ignoreFilePath) | ||
if err != nil { | ||
if os.IsNotExist(err) { | ||
return map[string]struct{}{}, nil | ||
} | ||
return nil, err | ||
} | ||
defer file.Close() | ||
|
||
patterns := make(map[string]struct{}) | ||
scanner := bufio.NewScanner(file) | ||
for scanner.Scan() { | ||
line := scanner.Text() | ||
line = strings.TrimSpace(line) | ||
if line == "" || strings.HasPrefix(line, "#") { | ||
continue | ||
} | ||
patterns[line] = struct{}{} | ||
} | ||
|
||
if err := scanner.Err(); err != nil { | ||
return nil, err | ||
} | ||
return patterns, nil | ||
} | ||
|
||
// shouldIgnore checks if the given file path matches any of the ignore patterns. | ||
func shouldIgnore(path string, patterns map[string]struct{}) (bool, error) { | ||
for pattern := range patterns { | ||
pattern = filepath.ToSlash(pattern) | ||
filePath := filepath.ToSlash(path) | ||
|
||
if strings.HasSuffix(pattern, "/") { | ||
if strings.HasPrefix(filePath, pattern) { | ||
return true, nil | ||
} | ||
continue | ||
} | ||
|
||
match, err := filepath.Match(pattern, filePath) | ||
if err != nil { | ||
return false, err | ||
} | ||
if match { | ||
return true, nil | ||
} | ||
} | ||
return false, nil | ||
} |
3 changes: 3 additions & 0 deletions
3
test/integration/pack/test_bundles/bundle_with_packignore/.packignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
app.lua | ||
instances_enabled/app1.lua | ||
instances_enabled/app1 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../bundle1/app2 |
1 change: 1 addition & 0 deletions
1
test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../bundle1/instances_enabled |
1 change: 1 addition & 0 deletions
1
test/integration/pack/test_bundles/bundle_with_packignore/modules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../bundle1/modules |
1 change: 1 addition & 0 deletions
1
test/integration/pack/test_bundles/bundle_with_packignore/tt.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../bundle1/tt.yaml |