mirror of
https://github.com/syncthing/syncthing.git
synced 2024-11-16 02:18:44 -07:00
db03562d43
It turns out that ZFS doesn't do any normalization when storing files, but does do normalization "as part of any comparison process". In practice, this seems to mean that if you LStat a normalized filename, ZFS will return the FileInfo for the un-normalized version of that filename. This meant that our test to see whether a separate file with a normalized version of the filename already exists was failing, as we were detecting the same file. The fix is to use os.SameFile, to see whether we're getting the same FileInfo from the normalized and un-normalized versions of the same filename. One complication is that ZFS also seems to apply its magic to os.Rename, meaning that we can't use it to rename an un-normalized file to its normalized filename. Instead we have to move via a temporary object. If the move to the temporary object fails, that's OK, we can skip it and move on. If the move from the temporary object fails however, I'm not sure of the best approach: the current one is to leave the temporary file name as-is, and get Syncthing to syncronize it, so at least we don't lose the file. I'm not sure if there are any implications of this however. As part of reworking normalizePath, I spotted that it appeared to be returning the wrong thing: the doc and the surrounding code expecting it to return the normalized filename, but it was returning the un-normalized one. I fixed this, but it seems suspicious that, if the previous behaviour was incorrect, noone ever ran afoul of it. Maybe all filesystems will do some searching and give you a normalized filename if you request an unnormalized one. As part of this, I found that TestNormalization was broken: it was passing, when in fact one of the files it should have verified was present was missing. Maybe this was related to the above issue with normalizePath's return value, I'm not sure. Fixed en route. Kindly tested by @khinsen on the forum, and it appears to work. GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4646
49 lines
3.3 KiB
Go
49 lines
3.3 KiB
Go
// Copyright (C) 2016 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 fs
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
type errorFilesystem struct {
|
|
err error
|
|
fsType FilesystemType
|
|
uri string
|
|
}
|
|
|
|
func (fs *errorFilesystem) Chmod(name string, mode FileMode) error { return fs.err }
|
|
func (fs *errorFilesystem) Chtimes(name string, atime time.Time, mtime time.Time) error { return fs.err }
|
|
func (fs *errorFilesystem) Create(name string) (File, error) { return nil, fs.err }
|
|
func (fs *errorFilesystem) CreateSymlink(name, target string) error { return fs.err }
|
|
func (fs *errorFilesystem) DirNames(name string) ([]string, error) { return nil, fs.err }
|
|
func (fs *errorFilesystem) Lstat(name string) (FileInfo, error) { return nil, fs.err }
|
|
func (fs *errorFilesystem) Mkdir(name string, perm FileMode) error { return fs.err }
|
|
func (fs *errorFilesystem) MkdirAll(name string, perm FileMode) error { return fs.err }
|
|
func (fs *errorFilesystem) Open(name string) (File, error) { return nil, fs.err }
|
|
func (fs *errorFilesystem) OpenFile(string, int, FileMode) (File, error) { return nil, fs.err }
|
|
func (fs *errorFilesystem) ReadSymlink(name string) (string, error) { return "", fs.err }
|
|
func (fs *errorFilesystem) Remove(name string) error { return fs.err }
|
|
func (fs *errorFilesystem) RemoveAll(name string) error { return fs.err }
|
|
func (fs *errorFilesystem) Rename(oldname, newname string) error { return fs.err }
|
|
func (fs *errorFilesystem) Stat(name string) (FileInfo, error) { return nil, fs.err }
|
|
func (fs *errorFilesystem) SymlinksSupported() bool { return false }
|
|
func (fs *errorFilesystem) Walk(root string, walkFn WalkFunc) error { return fs.err }
|
|
func (fs *errorFilesystem) Unhide(name string) error { return fs.err }
|
|
func (fs *errorFilesystem) Hide(name string) error { return fs.err }
|
|
func (fs *errorFilesystem) Glob(pattern string) ([]string, error) { return nil, fs.err }
|
|
func (fs *errorFilesystem) SyncDir(name string) error { return fs.err }
|
|
func (fs *errorFilesystem) Roots() ([]string, error) { return nil, fs.err }
|
|
func (fs *errorFilesystem) Usage(name string) (Usage, error) { return Usage{}, fs.err }
|
|
func (fs *errorFilesystem) Type() FilesystemType { return fs.fsType }
|
|
func (fs *errorFilesystem) URI() string { return fs.uri }
|
|
func (fs *errorFilesystem) SameFile(fi1, fi2 FileInfo) bool { return false }
|
|
func (fs *errorFilesystem) Watch(path string, ignore Matcher, ctx context.Context, ignorePerms bool) (<-chan Event, error) {
|
|
return nil, fs.err
|
|
}
|