Skip to content
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

Use packit file exists function. #127

Merged
merged 1 commit into from
Mar 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions detect.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package pythonstart

import (
"errors"
"fmt"
"os"
"path/filepath"
"strconv"

"github.com/paketo-buildpacks/packit/v2"
"github.com/paketo-buildpacks/packit/v2/fs"
)

// BuildPlanMetadata is the buildpack specific data included in build plan
Expand All @@ -32,12 +32,12 @@ type BuildPlanMetadata struct {
// additionally require "watchexec" at launch-time
func Detect() packit.DetectFunc {
return func(context packit.DetectContext) (packit.DetectResult, error) {
envFile, err := fileExists(filepath.Join(context.WorkingDir, "environment.yml"))
envFile, err := fs.Exists(filepath.Join(context.WorkingDir, "environment.yml"))
if err != nil {
return packit.DetectResult{}, packit.Fail.WithMessage("failed trying to stat environment.yml: %w", err)
}

lockFile, err := fileExists(filepath.Join(context.WorkingDir, "package-list.txt"))
lockFile, err := fs.Exists(filepath.Join(context.WorkingDir, "package-list.txt"))
if err != nil {
return packit.DetectResult{}, packit.Fail.WithMessage("failed trying to stat package-list.txt: %w", err)
}
Expand Down Expand Up @@ -134,17 +134,6 @@ func Detect() packit.DetectFunc {
}
}

func fileExists(path string) (bool, error) {
_, err := os.Stat(path)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return false, nil
}
return false, err
}
return true, nil
}

func checkLiveReloadEnabled() (bool, error) {
if reload, ok := os.LookupEnv("BP_LIVE_RELOAD_ENABLED"); ok {
shouldEnableReload, err := strconv.ParseBool(reload)
Expand Down