mirror of
https://github.com/syncthing/syncthing.git
synced 2024-11-17 19:08:46 -07:00
932d8c69de
With this change we emulate a case sensitive filesystem on top of insensitive filesystems. This means we correctly pick up case-only renames and throw a case conflict error when there would be multiple files differing only in case. This safety check has a small performance hit (about 20% more filesystem operations when scanning for changes). The new advanced folder option `caseSensitiveFS` can be used to disable the safety checks, retaining the previous behavior on systems known to be fully case sensitive. Co-authored-by: Jakob Borg <jakob@kastelo.net>
92 lines
1.7 KiB
Go
92 lines
1.7 KiB
Go
// Copyright (C) 2019 The Syncthing Authors.
|
|
//
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
package model
|
|
|
|
import (
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/syncthing/syncthing/lib/fs"
|
|
)
|
|
|
|
// fatal is the required common interface between *testing.B and *testing.T
|
|
type fatal interface {
|
|
Fatal(...interface{})
|
|
Helper()
|
|
}
|
|
|
|
type fatalOs struct {
|
|
fatal
|
|
}
|
|
|
|
func must(f fatal, err error) {
|
|
f.Helper()
|
|
if err != nil {
|
|
f.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func mustRemove(f fatal, err error) {
|
|
f.Helper()
|
|
if err != nil && !fs.IsNotExist(err) {
|
|
f.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func (f *fatalOs) Chmod(name string, mode os.FileMode) {
|
|
f.Helper()
|
|
must(f, os.Chmod(name, mode))
|
|
}
|
|
|
|
func (f *fatalOs) Chtimes(name string, atime time.Time, mtime time.Time) {
|
|
f.Helper()
|
|
must(f, os.Chtimes(name, atime, mtime))
|
|
}
|
|
|
|
func (f *fatalOs) Create(name string) *os.File {
|
|
f.Helper()
|
|
file, err := os.Create(name)
|
|
must(f, err)
|
|
return file
|
|
}
|
|
|
|
func (f *fatalOs) Mkdir(name string, perm os.FileMode) {
|
|
f.Helper()
|
|
must(f, os.Mkdir(name, perm))
|
|
}
|
|
|
|
func (f *fatalOs) MkdirAll(name string, perm os.FileMode) {
|
|
f.Helper()
|
|
must(f, os.MkdirAll(name, perm))
|
|
}
|
|
|
|
func (f *fatalOs) Remove(name string) {
|
|
f.Helper()
|
|
if err := os.Remove(name); err != nil && !os.IsNotExist(err) {
|
|
f.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func (f *fatalOs) RemoveAll(name string) {
|
|
f.Helper()
|
|
if err := os.RemoveAll(name); err != nil && !os.IsNotExist(err) {
|
|
f.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func (f *fatalOs) Rename(oldname, newname string) {
|
|
f.Helper()
|
|
must(f, os.Rename(oldname, newname))
|
|
}
|
|
|
|
func (f *fatalOs) Stat(name string) os.FileInfo {
|
|
f.Helper()
|
|
info, err := os.Stat(name)
|
|
must(f, err)
|
|
return info
|
|
}
|