Skip to content

Commit

Permalink
fix: fix a bug that file extensions aren't added when packages are in…
Browse files Browse the repository at this point in the history
…stalled on Windows (#2098)

* fix: fix a bug that file extensions aren't added when packages are installed on Windows

* test: test renaming files on windows
  • Loading branch information
suzuki-shunsuke authored Jul 17, 2023
1 parent f8bf5a5 commit 0cd21af
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
19 changes: 12 additions & 7 deletions pkg/config/windows_ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,27 @@ import (
)

func (cpkg *Package) RenameFile(logE *logrus.Entry, fs afero.Fs, pkgPath string, file *registry.File, rt *runtime.Runtime) (string, error) {
s, err := cpkg.getFileSrc(file, rt)
s, err := cpkg.getFileSrcWithoutWindowsExt(file, rt)
if err != nil {
return "", err
}
if !(isWindows(rt.GOOS) && util.Ext(s, cpkg.Package.Version) == "") {
if !isWindows(rt.GOOS) {
return s, nil
}
newName := s + cpkg.windowsExt()
newPath := filepath.Join(pkgPath, newName)
if s == newName {
return newName, nil
if util.Ext(s, cpkg.Package.Version) != "" {
return s, nil
}

return cpkg.renameFile(logE, fs, pkgPath, s)
}

func (cpkg *Package) renameFile(logE *logrus.Entry, fs afero.Fs, pkgPath, oldName string) (string, error) {
newName := oldName + cpkg.windowsExt()
newPath := filepath.Join(pkgPath, newName)
if _, err := fs.Stat(newPath); err == nil {
return newName, nil
}
old := filepath.Join(pkgPath, s)
old := filepath.Join(pkgPath, oldName)
if _, err := fs.Stat(old); err != nil {
return "", &FileNotFoundError{
Err: err,
Expand Down
2 changes: 2 additions & 0 deletions tests/main/aqua.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ packages:
version: v0.20.0 # renovate: depName=kubernetes-sigs/kind
- null
- name: cycloidio/[email protected] # update-checksum -deep
- name: dlvhdr/gh-dash
version: v3.8.0 # rename files on Windows

0 comments on commit 0cd21af

Please sign in to comment.