Merge branch v2.10 into v3.0

This commit is contained in:
Fernandez Ludovic 2023-06-05 11:05:29 +02:00
commit 606281a4a5
20 changed files with 196 additions and 73 deletions

View file

@ -262,7 +262,7 @@ func (c *Client) unzipArchive(pName, pVersion string) error {
for _, f := range archive.File {
err = unzipFile(f, dest)
if err != nil {
return err
return fmt.Errorf("unable to unzip %s: %w", f.Name, err)
}
}
@ -281,12 +281,17 @@ func unzipFile(f *zipa.File, dest string) error {
p := filepath.Join(dest, pathParts[1])
if f.FileInfo().IsDir() {
return os.MkdirAll(p, f.Mode())
err = os.MkdirAll(p, f.Mode())
if err != nil {
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 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())
@ -345,7 +350,7 @@ func (c *Client) WriteState(plugins map[string]Descriptor) error {
mp, err := json.MarshalIndent(m, "", " ")
if err != nil {
return err
return fmt.Errorf("unable to marshal plugin state: %w", err)
}
return os.WriteFile(c.stateFile, mp, 0o600)
@ -359,10 +364,15 @@ func (c *Client) ResetAll() error {
err := resetDirectory(filepath.Join(c.goPath, ".."))
if err != nil {
return err
return fmt.Errorf("unable to reset plugins GoPath directory %s: %w", c.goPath, err)
}
return resetDirectory(c.archives)
err = resetDirectory(c.archives)
if err != nil {
return fmt.Errorf("unable to reset plugins archives directory: %w", err)
}
return nil
}
func (c *Client) buildArchivePath(pName, pVersion string) string {
@ -372,12 +382,12 @@ func (c *Client) buildArchivePath(pName, pVersion string) string {
func resetDirectory(dir string) error {
dirPath, err := filepath.Abs(dir)
if err != nil {
return err
return fmt.Errorf("unable to get absolute path of %s: %w", dir, err)
}
currentPath, err := os.Getwd()
if err != nil {
return err
return fmt.Errorf("unable to get the current directory: %w", err)
}
if strings.HasPrefix(currentPath, dirPath) {
@ -386,10 +396,15 @@ func resetDirectory(dir string) error {
err = os.RemoveAll(dir)
if err != nil {
return err
return fmt.Errorf("unable to remove directory %s: %w", dirPath, err)
}
return os.MkdirAll(dir, 0o755)
err = os.MkdirAll(dir, 0o755)
if err != nil {
return fmt.Errorf("unable to create directory %s: %w", dirPath, err)
}
return nil
}
func computeHash(filepath string) (string, error) {