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

filesystem: Bubble up errors rather than panicing #414

Merged
merged 2 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
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
7 changes: 3 additions & 4 deletions filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -70,18 +69,18 @@ func CopyTree(sourcetree, desttree string) error {
case 0:
err := CopyFile(p, target, info.Mode())
if err != nil {
log.Panicf("Failed to copy file %s: %v", p, err)
return fmt.Errorf("Failed to copy file %s: %w", p, err)
}
case os.ModeDir:
os.Mkdir(target, info.Mode())
case os.ModeSymlink:
link, err := os.Readlink(p)
if err != nil {
log.Panicf("Failed to read symlink %s: %v", suffix, err)
return fmt.Errorf("Failed to read symlink %s: %w", suffix, err)
}
os.Symlink(link, target)
default:
log.Panicf("Not handled /%s %v", suffix, info.Mode())
return fmt.Errorf("File %s with mode %v not handled", p, info.Mode())
}

return nil
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
architecture: amd64

actions:
# This overlay action is expected to error out here because the destination
# doesn't exist in the filesystem.
- action: overlay
description: Overlay file into a non-existent destination
source: overlay-non-existent-destination.yaml
destination: /this/path/does/not/exist/overlay-non-existent-destination.yaml

- action: run
description: Check if path exists
command: "[ -e /this/path/does/not/exist/overlay-non-existent-destination.yaml ] || exit 1"

- action: run
postprocess: true
command: echo Test