Skip to content

Commit

Permalink
fix repo on create, move warning up a function
Browse files Browse the repository at this point in the history
Signed-off-by: David Fridrich <[email protected]>
  • Loading branch information
gauron99 committed Sep 6, 2024
1 parent 32088dd commit 6f37e0c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
5 changes: 5 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ Learn more about Knative at: https://knative.dev`, cfg.Name),
viper.SetEnvPrefix("func") // ensure that all have the prefix
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))

// check if permissions for FUNC HOME are sufficient; warn if otherwise
cp := config.File()
if _, err := os.ReadFile(cp); os.IsPermission(err) {
fmt.Fprintf(os.Stderr, "Warning: Insufficient permissions to read config file at '%s' - continuing without it\n", cp)
}
// Client
// Use the provided ClientFactory or default to NewClient
newClient := cfg.NewClient
Expand Down
9 changes: 3 additions & 6 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,10 @@ func NewDefault() (cfg Global, err error) {
bb, err := os.ReadFile(cp)
if err != nil {
// config file is not required
if os.IsNotExist(err) {
// permissions warning printed in cmd/root.go as to not spam here
// TODO: gauron99 - review the whole process for simplification
if os.IsNotExist(err) || os.IsPermission(err) {
err = nil
} else if os.IsPermission(err) {
err = nil // insufficient perms for config file -> warning
// TODO: gauron99 - this gets printed out for lot of commands so its a bit
// spammy, perhaps dont print here?
fmt.Fprintf(os.Stderr, "Warning: Insufficient permissions to read config file at '%s' - continuing without it\n", cp)
}
return
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/functions/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ func (r *Repositories) All() (repos []Repository, err error) {
if r.path == "" {
return
}

// Return empty if path does not exist
if _, err = os.Stat(r.path); os.IsNotExist(err) {
fmt.Printf("repos: %v\n\n", repos)
// Return empty if path does not exist or insufficient permissions
if _, err = os.Stat(r.path); os.IsNotExist(err) || os.IsPermission(err) {
return repos, nil
}

Expand Down

0 comments on commit 6f37e0c

Please sign in to comment.