From db2581e8b1b2f9bc78f00f27eed796cbd66e3019 Mon Sep 17 00:00:00 2001 From: Reece Williams Date: Wed, 30 Oct 2024 01:18:48 -0500 Subject: [PATCH] fix: new file permissions on generation --- cmd/spawn/module.go | 3 ++- spawn/cfg.go | 2 +- spawn/file_content.go | 5 +++-- spawn/metadata.go | 2 +- spawn/proto_parser.go | 2 +- spawn/types/chain_registry.go | 2 +- spawn/types/chain_registry_assets_list.go | 2 +- spawn/version_check.go | 4 ++-- 8 files changed, 12 insertions(+), 10 deletions(-) diff --git a/cmd/spawn/module.go b/cmd/spawn/module.go index afab81c2..d359ffea 100644 --- a/cmd/spawn/module.go +++ b/cmd/spawn/module.go @@ -433,7 +433,8 @@ func AddModuleToAppGo(logger *slog.Logger, extName string, feats *features) erro logger.Debug("initParamsKeeper register", "extName", extName, "start", start, "end", end) appGoLines = append(appGoLines[:end-3], append([]string{fmt.Sprintf(` paramsKeeper.Subspace(%stypes.ModuleName)`, extName)}, appGoLines[end-3:]...)...) - return os.WriteFile(appGoPath, []byte(strings.Join(appGoLines, "\n")), 0644) + // 777 is used as some users have weird setup / group environments w/ MacOS. 766 is more ideal but .sh files need to be executed. + return os.WriteFile(appGoPath, []byte(strings.Join(appGoLines, "\n")), 0777) } // appendNewImportsToSource appends new imports to the source file at the end of the import block (before the closing `)` ). diff --git a/spawn/cfg.go b/spawn/cfg.go index f3e401b3..38f58c0b 100644 --- a/spawn/cfg.go +++ b/spawn/cfg.go @@ -458,7 +458,7 @@ func debugErrorFile(logger *slog.Logger, newDirname string) string { } fullPath := path.Join(debugDir, fname) - if err := os.WriteFile(fullPath, []byte(errFileText), 0644); err != nil { + if err := os.WriteFile(fullPath, []byte(errFileText), 0766); err != nil { logger.Error("Error saving debug file", "err", err) } diff --git a/spawn/file_content.go b/spawn/file_content.go index 2a625024..5afc298d 100644 --- a/spawn/file_content.go +++ b/spawn/file_content.go @@ -254,9 +254,10 @@ func (fc *FileContent) Save() error { return nil } - if err := os.MkdirAll(path.Dir(fc.NewPath), 0755); err != nil { + // 777 is used as some users have weird setup / group environments w/ MacOS. 766 is more ideal but .sh files need to be executed. + if err := os.MkdirAll(path.Dir(fc.NewPath), 0777); err != nil { return err } - return os.WriteFile(fc.NewPath, []byte(fc.Contents), 0644) + return os.WriteFile(fc.NewPath, []byte(fc.Contents), 0777) } diff --git a/spawn/metadata.go b/spawn/metadata.go index 6752be1f..3d113a96 100644 --- a/spawn/metadata.go +++ b/spawn/metadata.go @@ -68,5 +68,5 @@ func (mf MetadataFile) SaveJSON(loc string) error { return err } - return os.WriteFile(loc, bz, 0644) + return os.WriteFile(loc, bz, 0666) } diff --git a/spawn/proto_parser.go b/spawn/proto_parser.go index 0753bdf4..6cdc2a14 100644 --- a/spawn/proto_parser.go +++ b/spawn/proto_parser.go @@ -405,7 +405,7 @@ func ApplyMissingRPCMethodsToGoSourceFiles(logger *slog.Logger, missingRPCMethod // append to the file content after a new line at the end content = append(content, []byte("\n"+code)...) - if err := os.WriteFile(fileLoc, content, 0644); err != nil { + if err := os.WriteFile(fileLoc, content, 0666); err != nil { logger.Error("error", "err", err) return err } diff --git a/spawn/types/chain_registry.go b/spawn/types/chain_registry.go index f2ffbe77..7ef5a87e 100644 --- a/spawn/types/chain_registry.go +++ b/spawn/types/chain_registry.go @@ -137,5 +137,5 @@ func (v ChainRegistryFormat) SaveJSON(loc string) error { return err } - return os.WriteFile(loc, bz, 0644) + return os.WriteFile(loc, bz, 0666) } diff --git a/spawn/types/chain_registry_assets_list.go b/spawn/types/chain_registry_assets_list.go index 318bafd2..2cc2661f 100644 --- a/spawn/types/chain_registry_assets_list.go +++ b/spawn/types/chain_registry_assets_list.go @@ -49,5 +49,5 @@ func (v ChainRegistryAssetsList) SaveJSON(loc string) error { return err } - return os.WriteFile(loc, bz, 0644) + return os.WriteFile(loc, bz, 0666) } diff --git a/spawn/version_check.go b/spawn/version_check.go index ff2eb7e0..c013ef48 100644 --- a/spawn/version_check.go +++ b/spawn/version_check.go @@ -209,7 +209,7 @@ func DoOutdatedNotificationRunCheck(logger *slog.Logger) bool { } func WriteLastTimeToFile(logger *slog.Logger, lastCheckFile string, t time.Time) error { - return os.WriteFile(lastCheckFile, []byte(t.Format(time.RFC3339)), 0644) + return os.WriteFile(lastCheckFile, []byte(t.Format(time.RFC3339)), 0666) } // GetLatestVersionCheckFile grabs the check file used to determine when to run the version check. @@ -236,7 +236,7 @@ func GetLatestVersionCheckFile(logger *slog.Logger) (string, error) { } epoch := time.Unix(0, 0) - if err := os.WriteFile(lastCheckFile, []byte(epoch.Format(time.RFC3339)), 0644); err != nil { + if err := os.WriteFile(lastCheckFile, []byte(epoch.Format(time.RFC3339)), 0666); err != nil { logger.Error("Error writing last check file", "err", err) return "", err }