Skip to content

Commit

Permalink
fix: change permission mode to 0777
Browse files Browse the repository at this point in the history
  • Loading branch information
aooohan committed Apr 18, 2024
1 parent dd04e16 commit 46e716e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
5 changes: 3 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ func NewConfigWithPath(p string) (*Config, error) {
if !util.FileExists(p) {
content, err := yaml.Marshal(defaultConfig)
if err == nil {
_ = os.WriteFile(p, content, 0644)
_ = os.WriteFile(p, content, os.ModePerm)
return defaultConfig, nil
}
}
_ = util.ChangeModeIfNot(p, os.ModePerm)
content, err := os.ReadFile(p)
if err != nil {
return nil, err
Expand Down Expand Up @@ -85,5 +86,5 @@ func (c *Config) SaveConfig(path string) error {
if err != nil {
return err
}
return os.WriteFile(p, content, 0644)
return os.WriteFile(p, content, os.ModePerm)
}
5 changes: 4 additions & 1 deletion internal/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ func (m *Manager) LookupSdk(name string) (*Sdk, error) {
return nil, fmt.Errorf("failed to migrate an old plug-in: %w", err)
}
}
sdk, _ := NewSdk(m, pluginPath)
sdk, err := NewSdk(m, pluginPath)
if err != nil {
return nil, err
}
m.openSdks[strings.ToLower(name)] = sdk
return sdk, nil
}
Expand Down
15 changes: 15 additions & 0 deletions internal/util/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,18 @@ func MoveFiles(src, targetDir string) error {
}
return nil
}

// ChangeModeIfNot Change the permission mode of a file if it is not the same as the specified mode
func ChangeModeIfNot(src string, mode os.FileMode) error {
info, err := os.Stat(src)
if err != nil {
return err
}
if info.Mode() != mode {
err = os.Chmod(src, mode)
if err != nil {
return err
}
}
return nil
}

0 comments on commit 46e716e

Please sign in to comment.