Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Pollet <pollet.kevin@gmail.com>
  • Loading branch information
ldez and kevinpollet committed Jun 2, 2023
1 parent 0884a9a commit 5e89fc2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cmd/traefik/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ func initPlugins(staticCfg *static.Configuration) (*plugins.Client, map[string]p
var err error
client, err = plugins.NewClient(opts)
if err != nil {
return nil, nil, nil, fmt.Errorf("failed to create plugins client: %w", err)
return nil, nil, nil, fmt.Errorf("unable to create plugins client: %w", err)
}

err = plugins.SetupRemotePlugins(client, staticCfg.Experimental.Plugins)
if err != nil {
return nil, nil, nil, fmt.Errorf("failed to set up plugins environment: %w", err)
return nil, nil, nil, fmt.Errorf("unable to set up plugins environment: %w", err)
}

plgs = staticCfg.Experimental.Plugins
Expand Down
18 changes: 9 additions & 9 deletions pkg/plugins/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func (c *Client) unzipArchive(pName, pVersion string) error {
for _, f := range archive.File {
err = unzipFile(f, dest)
if err != nil {
return fmt.Errorf("failed to unzip %s: %w", f.Name, err)
return fmt.Errorf("unable to unzip %s: %w", f.Name, err)
}
}

Expand All @@ -285,15 +285,15 @@ func unzipFile(f *zipa.File, dest string) error {
if f.FileInfo().IsDir() {
err = os.MkdirAll(p, f.Mode())
if err != nil {
return fmt.Errorf("failed to create archive directory %s: %w", p, err)
return fmt.Errorf("unable to create archive directory %s: %w", p, err)
}

return nil
}

err = os.MkdirAll(filepath.Dir(p), 0o750)
if err != nil {
return fmt.Errorf("failed to create archive directory %s for the file %s: %w", filepath.Dir(p), p, err)
return fmt.Errorf("unable to create archive directory %s for file %s: %w", filepath.Dir(p), p, err)
}

elt, err := os.OpenFile(p, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
Expand Down Expand Up @@ -352,7 +352,7 @@ func (c *Client) WriteState(plugins map[string]Descriptor) error {

mp, err := json.MarshalIndent(m, "", " ")
if err != nil {
return fmt.Errorf("failed to marshal plugin state: %w", err)
return fmt.Errorf("unable to marshal plugin state: %w", err)
}

return os.WriteFile(c.stateFile, mp, 0o600)
Expand All @@ -366,12 +366,12 @@ func (c *Client) ResetAll() error {

err := resetDirectory(filepath.Join(c.goPath, ".."))
if err != nil {
return fmt.Errorf("failed to reset GoPath directory (%s) of the plugins: %w", c.goPath, err)
return fmt.Errorf("unable to reset plugins GoPath directory %s: %w", c.goPath, err)
}

err = resetDirectory(c.archives)
if err != nil {
return fmt.Errorf("failed to reset plugins archives directory: %w", err)
return fmt.Errorf("unable to reset plugins archives directory: %w", err)
}

return nil
Expand All @@ -384,7 +384,7 @@ func (c *Client) buildArchivePath(pName, pVersion string) string {
func resetDirectory(dir string) error {
dirPath, err := filepath.Abs(dir)
if err != nil {
return fmt.Errorf("failed to get absolute path of %s: %w", dir, err)
return fmt.Errorf("unable to get absolute path of %s: %w", dir, err)
}

currentPath, err := os.Getwd()
Expand All @@ -398,12 +398,12 @@ func resetDirectory(dir string) error {

err = os.RemoveAll(dir)
if err != nil {
return fmt.Errorf("failed to remove directory %s: %w", dirPath, err)
return fmt.Errorf("unable to remove directory %s: %w", dirPath, err)
}

err = os.MkdirAll(dir, 0o755)
if err != nil {
return fmt.Errorf("failed to create directory %s: %w", dirPath, err)
return fmt.Errorf("unable to create directory %s: %w", dirPath, err)
}

return nil
Expand Down

0 comments on commit 5e89fc2

Please sign in to comment.