mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-19 15:27:20 +09:00
util: Generalize the file mode of 0666 with util.FileMode
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user