Check if the file being edited has been modified by an external program

This commit is contained in:
Zachary Yedidia
2016-05-29 17:58:06 -04:00
parent ee9f2a3d9c
commit 19717dd3ae
5 changed files with 75 additions and 15 deletions

View File

@@ -1,9 +1,11 @@
package main
import (
"os"
"path/filepath"
"strconv"
"strings"
"time"
"unicode/utf8"
)
@@ -126,6 +128,16 @@ func EscapePath(path string) string {
return strings.Replace(path, "/", "%", -1)
}
// GetModTime returns the last modification time for a given file
// It also returns a boolean if there was a problem accessing the file
func GetModTime(path string) (time.Time, bool) {
info, err := os.Stat(path)
if err != nil {
return time.Now(), false
}
return info.ModTime(), true
}
func runePos(p int, str string) int {
return utf8.RuneCountInString(str[:p])
}