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 wrapping errors #196

Merged
merged 2 commits into from Mar 25, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions context.go
Expand Up @@ -390,7 +390,7 @@ func (c *context) checkoutFile(fp string, rf RegularFile) error {
}
}
if err != nil {
return fmt.Errorf("file content could not be provided: %v", err)
return fmt.Errorf("file content could not be provided: %w", err)
}
defer r.Close()

Expand Down Expand Up @@ -422,7 +422,7 @@ func (c *context) Apply(resource Resource) error {
case RegularFile:
if fi == nil {
if err := c.checkoutFile(fp, r); err != nil {
return fmt.Errorf("error checking out file %q: %v", resource.Path(), err)
return fmt.Errorf("error checking out file %q: %w", resource.Path(), err)
}
chmod = false
} else {
Expand All @@ -431,26 +431,26 @@ func (c *context) Apply(resource Resource) error {
}
if fi.Size() != r.Size() {
if err := c.checkoutFile(fp, r); err != nil {
return fmt.Errorf("error checking out file %q: %v", resource.Path(), err)
return fmt.Errorf("error checking out file %q: %w", resource.Path(), err)
}
} else {
for _, dgst := range r.Digests() {
f, err := os.Open(fp)
if err != nil {
return fmt.Errorf("failure opening file for read %q: %v", resource.Path(), err)
return fmt.Errorf("failure opening file for read %q: %w", resource.Path(), err)
}
compared, err := dgst.Algorithm().FromReader(f)
if err == nil && dgst != compared {
if err := c.checkoutFile(fp, r); err != nil {
return fmt.Errorf("error checking out file %q: %v", resource.Path(), err)
return fmt.Errorf("error checking out file %q: %w", resource.Path(), err)
}
break
}
if err1 := f.Close(); err == nil {
err = err1
}
if err != nil {
return fmt.Errorf("error checking digest for %q: %v", resource.Path(), err)
return fmt.Errorf("error checking digest for %q: %w", resource.Path(), err)
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions driver/driver_unix.go
Expand Up @@ -54,7 +54,7 @@ func (d *driver) Mkfifo(path string, mode os.FileMode) error {
func (d *driver) Getxattr(p string) (map[string][]byte, error) {
xattrs, err := sysx.Listxattr(p)
if err != nil {
return nil, fmt.Errorf("listing %s xattrs: %v", p, err)
return nil, fmt.Errorf("listing %s xattrs: %w", p, err)
}

sort.Strings(xattrs)
Expand All @@ -63,7 +63,7 @@ func (d *driver) Getxattr(p string) (map[string][]byte, error) {
for _, attr := range xattrs {
value, err := sysx.Getxattr(p, attr)
if err != nil {
return nil, fmt.Errorf("getting %q xattr on %s: %v", attr, p, err)
return nil, fmt.Errorf("getting %q xattr on %s: %w", attr, p, err)
}

// NOTE(stevvooe): This append/copy tricky relies on unique
Expand All @@ -82,7 +82,7 @@ func (d *driver) Getxattr(p string) (map[string][]byte, error) {
func (d *driver) Setxattr(path string, attrMap map[string][]byte) error {
for attr, value := range attrMap {
if err := sysx.Setxattr(path, attr, value, 0); err != nil {
return fmt.Errorf("error setting xattr %q on %s: %v", attr, path, err)
return fmt.Errorf("error setting xattr %q on %s: %w", attr, path, err)
}
}

Expand All @@ -94,7 +94,7 @@ func (d *driver) Setxattr(path string, attrMap map[string][]byte) error {
func (d *driver) LGetxattr(p string) (map[string][]byte, error) {
xattrs, err := sysx.LListxattr(p)
if err != nil {
return nil, fmt.Errorf("listing %s xattrs: %v", p, err)
return nil, fmt.Errorf("listing %s xattrs: %w", p, err)
}

sort.Strings(xattrs)
Expand All @@ -103,7 +103,7 @@ func (d *driver) LGetxattr(p string) (map[string][]byte, error) {
for _, attr := range xattrs {
value, err := sysx.LGetxattr(p, attr)
if err != nil {
return nil, fmt.Errorf("getting %q xattr on %s: %v", attr, p, err)
return nil, fmt.Errorf("getting %q xattr on %s: %w", attr, p, err)
}

// NOTE(stevvooe): This append/copy tricky relies on unique
Expand All @@ -122,7 +122,7 @@ func (d *driver) LGetxattr(p string) (map[string][]byte, error) {
func (d *driver) LSetxattr(path string, attrMap map[string][]byte) error {
for attr, value := range attrMap {
if err := sysx.LSetxattr(path, attr, value, 0); err != nil {
return fmt.Errorf("error setting xattr %q on %s: %v", attr, path, err)
return fmt.Errorf("error setting xattr %q on %s: %w", attr, path, err)
}
}

Expand Down
4 changes: 3 additions & 1 deletion fs/copy.go
Expand Up @@ -158,7 +158,9 @@ func copyDirectory(dst, src string, inodes map[uint64]string, o *copyDirOpts) er
}
default:
// TODO: Support pipes and sockets
return fmt.Errorf("unsupported mode %s: %w", fi.Mode(), err)
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how this can ever be non-nil.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦 my bad

return fmt.Errorf("unsupported mode %s: %w", fi.Mode(), err)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not fix #185 (comment) . It will just skip over this condition until it reaches copyFileInfo and errors there because the path does not exist.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

if err := copyFileInfo(fi, source, target); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion hardlinks.go
Expand Up @@ -63,7 +63,7 @@ func (hlm *hardlinkManager) Merge() ([]Resource, error) {

merged, err := Merge(linked...)
if err != nil {
return nil, fmt.Errorf("error merging hardlink: %v", err)
return nil, fmt.Errorf("error merging hardlink: %w", err)
}

resources = append(resources, merged)
Expand Down
4 changes: 2 additions & 2 deletions manifest.go
Expand Up @@ -78,7 +78,7 @@ func BuildManifest(ctx Context) (*Manifest, error) {

if err := ctx.Walk(func(p string, fi os.FileInfo, err error) error {
if err != nil {
return fmt.Errorf("error walking %s: %v", p, err)
return fmt.Errorf("error walking %s: %w", p, err)
}

if p == string(os.PathSeparator) {
Expand All @@ -101,7 +101,7 @@ func BuildManifest(ctx Context) (*Manifest, error) {
return nil
} else if err != errNotAHardLink {
// handle any other case where we have a proper error.
return fmt.Errorf("adding hardlink %s: %v", p, err)
return fmt.Errorf("adding hardlink %s: %w", p, err)
}

resourcesByPath[p] = resource
Expand Down