mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-09 14:50:56 +00: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>
59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
// Copyright (C) 2020 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/.
|
|
|
|
// +build windows
|
|
|
|
package fs
|
|
|
|
import (
|
|
"path/filepath"
|
|
"strings"
|
|
"syscall"
|
|
)
|
|
|
|
type basicRealCaserWindows struct {
|
|
uri string
|
|
}
|
|
|
|
func newBasicRealCaser(fs Filesystem) realCaser {
|
|
return &basicRealCaserWindows{fs.URI()}
|
|
}
|
|
|
|
// RealCase returns the correct case for the given name, which is a relative
|
|
// path below root, as it exists on disk.
|
|
func (r *basicRealCaserWindows) realCase(name string) (string, error) {
|
|
if name == "." {
|
|
return ".", nil
|
|
}
|
|
path := r.uri
|
|
comps := strings.Split(name, string(PathSeparator))
|
|
var err error
|
|
for i, comp := range comps {
|
|
path = filepath.Join(path, comp)
|
|
comps[i], err = r.realCaseBase(path)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
}
|
|
return filepath.Join(comps...), nil
|
|
}
|
|
|
|
func (*basicRealCaserWindows) realCaseBase(path string) (string, error) {
|
|
p, err := syscall.UTF16PtrFromString(fixLongPath(path))
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
var fd syscall.Win32finddata
|
|
h, err := syscall.FindFirstFile(p, &fd)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
syscall.FindClose(h)
|
|
return syscall.UTF16ToString(fd.FileName[:]), nil
|
|
}
|
|
|
|
func (r *basicRealCaserWindows) dropCache() {}
|