mirror of
https://github.com/zyedidia/micro.git
synced 2026-02-04 14:10:23 +09:00
util: Generalize the file mode of 0666 with util.FileMode
This commit is contained in:
@@ -18,7 +18,7 @@ func (NullWriter) Write(data []byte) (n int, err error) {
|
||||
// InitLog sets up the debug log system for micro if it has been enabled by compile-time variables
|
||||
func InitLog() {
|
||||
if util.Debug == "ON" {
|
||||
f, err := os.OpenFile("log.txt", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
|
||||
f, err := os.OpenFile("log.txt", os.O_RDWR|os.O_CREATE|os.O_TRUNC, util.FileMode)
|
||||
if err != nil {
|
||||
log.Fatalf("error opening file: %v", err)
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/micro-editor/json5"
|
||||
"github.com/zyedidia/micro/v2/internal/config"
|
||||
"github.com/zyedidia/micro/v2/internal/screen"
|
||||
"github.com/zyedidia/micro/v2/internal/util"
|
||||
"github.com/micro-editor/tcell/v2"
|
||||
)
|
||||
|
||||
@@ -26,7 +27,7 @@ var Binder = map[string]func(e Event, action string){
|
||||
|
||||
func createBindingsIfNotExist(fname string) {
|
||||
if _, e := os.Stat(fname); errors.Is(e, fs.ErrNotExist) {
|
||||
ioutil.WriteFile(fname, []byte("{}"), 0644)
|
||||
ioutil.WriteFile(fname, []byte("{}"), util.FileMode)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,7 +306,7 @@ func TryBindKey(k, v string, overwrite bool) (bool, error) {
|
||||
BindKey(k, v, Binder["buffer"])
|
||||
|
||||
txt, _ := json.MarshalIndent(parsed, "", " ")
|
||||
return true, ioutil.WriteFile(filename, append(txt, '\n'), 0644)
|
||||
return true, ioutil.WriteFile(filename, append(txt, '\n'), util.FileMode)
|
||||
}
|
||||
return false, e
|
||||
}
|
||||
@@ -355,7 +356,7 @@ func UnbindKey(k string) error {
|
||||
}
|
||||
|
||||
txt, _ := json.MarshalIndent(parsed, "", " ")
|
||||
return ioutil.WriteFile(filename, append(txt, '\n'), 0644)
|
||||
return ioutil.WriteFile(filename, append(txt, '\n'), util.FileMode)
|
||||
}
|
||||
return e
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ func overwriteFile(name string, enc encoding.Encoding, fn func(io.Writer) error,
|
||||
|
||||
return
|
||||
}
|
||||
} else if writeCloser, err = os.OpenFile(name, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666); err != nil {
|
||||
} else if writeCloser, err = os.OpenFile(name, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, util.FileMode); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -356,7 +356,7 @@ func WriteSettings(filename string) error {
|
||||
}
|
||||
|
||||
txt, _ := json.MarshalIndent(parsedSettings, "", " ")
|
||||
err = ioutil.WriteFile(filename, append(txt, '\n'), 0644)
|
||||
err = ioutil.WriteFile(filename, append(txt, '\n'), util.FileMode)
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -378,7 +378,7 @@ func OverwriteSettings(filename string) error {
|
||||
}
|
||||
|
||||
txt, _ := json.MarshalIndent(settings, "", " ")
|
||||
err = ioutil.WriteFile(filename, append(txt, '\n'), 0644)
|
||||
err = ioutil.WriteFile(filename, append(txt, '\n'), util.FileMode)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -46,6 +46,9 @@ var (
|
||||
Sigterm chan os.Signal
|
||||
)
|
||||
|
||||
// To be used for file writes before umask is applied
|
||||
const FileMode os.FileMode = 0666
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
SemVersion, err = semver.Make(Version)
|
||||
|
||||
@@ -37,7 +37,7 @@ func main() {
|
||||
</plist>
|
||||
`
|
||||
|
||||
err := os.WriteFile("/tmp/micro-info.plist", []byte(rawInfoPlist), 0644)
|
||||
err := os.WriteFile("/tmp/micro-info.plist", []byte(rawInfoPlist), 0666)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user