2017-12-29 14:23:06 -07: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/.
|
|
|
|
|
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2018-09-16 07:09:56 -07:00
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
2017-12-29 14:23:06 -07:00
|
|
|
)
|
|
|
|
|
2018-09-16 07:09:56 -07:00
|
|
|
var execExts map[string]bool
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
// PATHEXT contains a list of executable file extensions, on Windows
|
|
|
|
pathext := filepath.SplitList(os.Getenv("PATHEXT"))
|
|
|
|
// We want the extensions in execExts to be lower case
|
|
|
|
execExts = make(map[string]bool, len(pathext))
|
|
|
|
for _, ext := range pathext {
|
|
|
|
execExts[strings.ToLower(ext)] = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// isWindowsExecutable returns true if the given path has an extension that is
|
|
|
|
// in the list of executable extensions.
|
|
|
|
func isWindowsExecutable(path string) bool {
|
|
|
|
return execExts[strings.ToLower(filepath.Ext(path))]
|
|
|
|
}
|
|
|
|
|
2019-02-24 10:02:02 -07:00
|
|
|
func (e basicFileInfo) Mode() FileMode {
|
2017-12-29 14:23:06 -07:00
|
|
|
m := e.FileInfo.Mode()
|
|
|
|
if m&os.ModeSymlink != 0 && e.Size() > 0 {
|
|
|
|
// "Symlinks" with nonzero size are in fact "hard" links, such as
|
|
|
|
// NTFS deduped files. Remove the symlink bit.
|
|
|
|
m &^= os.ModeSymlink
|
|
|
|
}
|
2018-09-16 07:09:56 -07:00
|
|
|
// Set executable bits on files with executable extenions (.exe, .bat, etc).
|
|
|
|
if isWindowsExecutable(e.Name()) {
|
|
|
|
m |= 0111
|
|
|
|
}
|
|
|
|
// There is no user/group/others in Windows' read-only attribute, and
|
|
|
|
// all "w" bits are set if the file is not read-only. Do not send these
|
|
|
|
// group/others-writable bits to other devices in order to avoid
|
|
|
|
// unexpected world-writable files on other platforms.
|
|
|
|
m &^= 0022
|
2017-12-29 14:23:06 -07:00
|
|
|
return FileMode(m)
|
|
|
|
}
|
2019-02-24 10:02:02 -07:00
|
|
|
|
|
|
|
func (e basicFileInfo) Owner() int {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e basicFileInfo) Group() int {
|
|
|
|
return -1
|
|
|
|
}
|