Handle symlinks, Staggered versioner (fixes #1071)

This commit is contained in:
Jakob Borg 2014-12-03 11:49:53 +01:00
parent d38c81fcff
commit 94ab06e92f

View File

@ -45,16 +45,6 @@ type Staggered struct {
mutex *sync.Mutex
}
// Check if file or dir
func isFile(path string) bool {
fileInfo, err := os.Stat(path)
if err != nil {
l.Infoln("versioner isFile:", err)
return false
}
return fileInfo.Mode().IsRegular()
}
// Rename versions with old version format
func (v Staggered) renameOld() {
err := filepath.Walk(v.versionsPath, func(path string, f os.FileInfo, err error) error {
@ -167,14 +157,16 @@ func (v Staggered) clean() {
if err != nil {
return err
}
switch mode := f.Mode(); {
case mode.IsDir():
if f.Mode().IsDir() && f.Mode()&os.ModeSymlink == 0 {
filesPerDir[path] = 0
if path != v.versionsPath {
dir := filepath.Dir(path)
filesPerDir[dir]++
}
case mode.IsRegular():
} else {
// Regular file, or possibly a symlink.
extension := filenameTag(path)
dir := filepath.Dir(path)
name := path[:len(path)-len(extension)-1]
@ -227,7 +219,17 @@ func (v Staggered) expire(versions []string) {
var prevAge int64
firstFile := true
for _, file := range versions {
if isFile(file) {
fi, err := os.Stat(file)
if err != nil {
l.Warnln("versioner:", err)
continue
}
if fi.IsDir() {
l.Infof("non-file %q is named like a file version", file)
continue
}
versionTime, err := time.Parse(TimeFormat, filenameTag(file))
if err != nil {
l.Infof("Versioner: file name %q is invalid: %v", file, err)
@ -274,9 +276,6 @@ func (v Staggered) expire(versions []string) {
}
prevAge = age
} else {
l.Infof("non-file %q is named like a file version", file)
}
}
}
@ -289,7 +288,7 @@ func (v Staggered) Archive(filePath string) error {
v.mutex.Lock()
defer v.mutex.Unlock()
if _, err := os.Stat(filePath); err != nil {
if _, err := os.Lstat(filePath); err != nil {
if os.IsNotExist(err) {
if debug {
l.Debugln("not archiving nonexistent file", filePath)