2020-07-28 09:13:15 +00:00
|
|
|
// Copyright (C) 2017 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/.
|
|
|
|
|
2021-08-17 08:10:41 +00:00
|
|
|
//go:build !windows
|
2020-07-28 09:13:15 +00:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
)
|
|
|
|
|
|
|
|
// DebugSymlinkForTestsOnly is not and should not be used in Syncthing code,
|
|
|
|
// hence the cumbersome name to make it obvious if this ever leaks. Its
|
|
|
|
// reason for existence is the Windows version, which allows creating
|
|
|
|
// symlinks when non-elevated.
|
|
|
|
func DebugSymlinkForTestsOnly(oldFs, newFs Filesystem, oldname, newname string) error {
|
2021-05-03 10:28:25 +00:00
|
|
|
if fs, ok := unwrapFilesystem(newFs, filesystemWrapperTypeCase); ok {
|
|
|
|
caseFs := fs.(*caseFilesystem)
|
2020-07-28 09:13:15 +00:00
|
|
|
if err := caseFs.checkCase(newname); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
caseFs.dropCache()
|
|
|
|
}
|
|
|
|
if err := os.Symlink(filepath.Join(oldFs.URI(), oldname), filepath.Join(newFs.URI(), newname)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|