Skip to content

Commit 1ce2202

Browse files
committed
util: Convert suffix added with AppendBackupSuffix() to simple constant
1 parent 78d2c61 commit 1ce2202

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

‎cmd/micro/micro.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ func LoadInput(args []string) []*buffer.Buffer {
250250

251251
func checkBackup(name string) error {
252252
target := filepath.Join(config.ConfigDir, name)
253-
backup := util.AppendBackupSuffix(target)
253+
backup := target + util.BackupSuffix
254254
if info, err := os.Stat(backup); err == nil {
255255
input, err := os.ReadFile(backup)
256256
if err == nil {

‎internal/buffer/backup.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (b *SharedBuffer) writeBackup(path string) (string, error) {
104104
}
105105

106106
name := util.DetermineEscapePath(backupdir, path)
107-
tmp := util.AppendBackupSuffix(name)
107+
tmp := name + util.BackupSuffix
108108

109109
_, err := b.overwriteFile(tmp)
110110
if err != nil {

‎internal/util/util.go‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ var (
5454
// To be used for file writes before umask is applied
5555
const FileMode os.FileMode = 0666
5656

57+
const BackupSuffix = ".micro-backup"
58+
5759
const OverwriteFailMsg = `An error occurred while writing to the file:
5860
5961
%s
@@ -447,10 +449,6 @@ func GetModTime(path string) (time.Time, error) {
447449
return info.ModTime(), nil
448450
}
449451

450-
func AppendBackupSuffix(path string) string {
451-
return path + ".micro-backup"
452-
}
453-
454452
func HashStringMd5(str string) string {
455453
return fmt.Sprintf("%x", md5.Sum([]byte(str)))
456454
}
@@ -487,7 +485,7 @@ func DetermineEscapePath(dir string, path string) string {
487485
return legacy
488486
}
489487

490-
if len(url)+len(".micro-backup") > 255 {
488+
if len(url)+len(BackupSuffix) > 255 {
491489
return filepath.Join(dir, HashStringMd5(path))
492490
}
493491

@@ -708,7 +706,7 @@ func SafeWrite(path string, bytes []byte, rename bool) error {
708706
defer file.Close()
709707
}
710708

711-
tmp := AppendBackupSuffix(path)
709+
tmp := path + BackupSuffix
712710
err = os.WriteFile(tmp, bytes, FileMode)
713711
if err != nil {
714712
os.Remove(tmp)

0 commit comments

Comments
 (0)