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

fix(cli): PEBBLE_COPY_ONCE on missing dir. #392

Merged
merged 2 commits into from
Mar 21, 2024
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: 7 additions & 0 deletions internals/cli/cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,13 @@ func maybeCopyPebbleDir(destDir, srcDir string) error {
if srcDir == "" {
return nil
}
_, err := os.Stat(srcDir)
if errors.Is(err, os.ErrNotExist) {
// Skip missing source directory.
return nil
} else if err != nil {
return err
}
entries, err := os.ReadDir(destDir)
if err != nil && !errors.Is(err, os.ErrNotExist) {
return err
Expand Down
22 changes: 22 additions & 0 deletions internals/cli/cmd_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,25 @@ func (s *PebbleSuite) TestMaybeCopyPebbleDirNoCopy(c *C) {
"a.yaml": true,
})
}

func (s *PebbleSuite) TestMaybeCopyPebbleDirSourceNotExist(c *C) {
tmpDir := c.MkDir()
dst := path.Join(tmpDir, "dst")
err := os.Mkdir(dst, 0o700)
c.Assert(err, IsNil)
src := path.Join(tmpDir, "not-exist")
err = cli.MaybeCopyPebbleDir(dst, src)
c.Assert(err, IsNil)
}

func (s *PebbleSuite) TestMaybeCopyPebbleDirSourceNotADirectory(c *C) {
tmpDir := c.MkDir()
dst := path.Join(tmpDir, "dst")
err := os.Mkdir(dst, 0o700)
c.Assert(err, IsNil)
src := path.Join(tmpDir, "file")
err = os.WriteFile(src, nil, 0o666)
c.Assert(err, IsNil)
err = cli.MaybeCopyPebbleDir(dst, src)
c.Assert(err, ErrorMatches, ".*not a directory.*")
}
Loading