2014-12-04 14:24:49 -07:00
|
|
|
// Copyright (C) 2014 The Syncthing Authors.
|
|
|
|
//
|
2015-03-07 13:36:35 -07:00
|
|
|
// 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 http://mozilla.org/MPL/2.0/.
|
2014-12-04 14:24:49 -07:00
|
|
|
|
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package symlinks
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
2015-08-06 02:29:25 -07:00
|
|
|
"github.com/syncthing/syncthing/lib/osutil"
|
2014-12-04 14:24:49 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
Supported = true
|
|
|
|
)
|
|
|
|
|
2015-09-04 03:54:01 -07:00
|
|
|
func Read(path string) (string, TargetType, error) {
|
|
|
|
tt := TargetUnknown
|
|
|
|
if stat, err := os.Stat(path); err == nil {
|
|
|
|
if stat.IsDir() {
|
|
|
|
tt = TargetDirectory
|
|
|
|
} else {
|
|
|
|
tt = TargetFile
|
|
|
|
}
|
2014-12-04 14:24:49 -07:00
|
|
|
}
|
2015-09-04 03:54:01 -07:00
|
|
|
path, err := os.Readlink(path)
|
2014-12-04 14:24:49 -07:00
|
|
|
|
2015-09-04 03:54:01 -07:00
|
|
|
return osutil.NormalizedFilename(path), tt, err
|
2014-12-04 14:24:49 -07:00
|
|
|
}
|
|
|
|
|
2015-09-04 03:54:01 -07:00
|
|
|
func Create(source, target string, tt TargetType) error {
|
2014-12-04 14:24:49 -07:00
|
|
|
return os.Symlink(osutil.NativeFilename(target), source)
|
|
|
|
}
|
|
|
|
|
2015-09-04 03:54:01 -07:00
|
|
|
func ChangeType(path string, tt TargetType) error {
|
2014-12-04 14:24:49 -07:00
|
|
|
return nil
|
|
|
|
}
|