-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
All set to add rules for .kraftignore
Signed-off-by: Md Sahil <[email protected]>
- Loading branch information
1 parent
01c3c7f
commit 1603cdb
Showing
3 changed files
with
102 additions
and
2 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,63 @@ | ||
package initrd | ||
|
||
import ( | ||
"bufio" | ||
"errors" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
// kraftignore filename | ||
const KraftignoreFileName = ".kraftignore" | ||
|
||
func getKraftignoreItems(initrd *directory) ([]string, error) { | ||
if initrd.opts.kraftignorePath == "" { | ||
cwd, err := os.Getwd() | ||
if err != nil { | ||
return []string{}, err | ||
} | ||
initrd.opts.kraftignorePath = filepath.Join(cwd, KraftignoreFileName) | ||
} | ||
|
||
if _, err := os.Stat(initrd.opts.kraftignorePath); errors.Is(err, os.ErrNotExist) { | ||
return []string{}, nil | ||
} else if err != nil { | ||
return []string{}, err | ||
} | ||
|
||
kraftignoreFile, err := os.Open(initrd.opts.kraftignorePath) | ||
defer kraftignoreFile.Close() | ||
|
||
if err != nil { | ||
return []string{}, err | ||
} | ||
kraftignoreScanner := bufio.NewScanner(kraftignoreFile) | ||
kraftignoreScanner.Split(bufio.ScanLines) | ||
var kraftignoreFileLines, ignoringItems []string | ||
|
||
for kraftignoreScanner.Scan() { | ||
kraftignoreFileLines = append(kraftignoreFileLines, kraftignoreScanner.Text()) | ||
} | ||
|
||
for _, line := range kraftignoreFileLines { | ||
line = strings.TrimSpace(line) | ||
if line == "" || strings.HasPrefix(line, "#") { | ||
continue | ||
} | ||
items := strings.Split(line, " ") | ||
for _, item := range items { | ||
item = strings.TrimSpace(item) | ||
if item == "" { | ||
continue | ||
} | ||
ignoringItems = append(ignoringItems, item) | ||
} | ||
} | ||
return ignoringItems, nil | ||
} | ||
|
||
func isExistInKraftignoreFile(path string, kraftignoreItems []string) (string, error) { | ||
// Write code here | ||
return "", nil | ||
} |
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