The recent change to disallow following symlinks by default conflicts with the expected behavior of .stignore. This adds a new flag which may be passed to OpenFile to skip default symlink-forbidding open flag. --------- Signed-off-by: Jakob Borg <jakob@kastelo.net>
This commit is contained in:
+11
-1
@@ -240,16 +240,24 @@ func (f *BasicFilesystem) DirNames(name string) ([]string, error) {
|
||||
return names, nil
|
||||
}
|
||||
|
||||
// Open opens the file for reading, while not following symlinks
|
||||
func (f *BasicFilesystem) Open(name string) (File, error) {
|
||||
return f.OpenFile(name, os.O_RDONLY, 0)
|
||||
}
|
||||
|
||||
// OpenFile is the generalised file open call, using the flags to determine
|
||||
// the open semantics. We always add O_NOFOLLOW, disallowing opening files
|
||||
// by following symlinks, unless OptFollow is set.
|
||||
func (f *BasicFilesystem) OpenFile(name string, flags int, mode FileMode) (File, error) {
|
||||
rootedName, err := f.rooted(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
flags |= alwaysOpenFlags // enforce extra bits in flags
|
||||
if flags&OptFollow != 0 {
|
||||
flags &^= OptFollow // unset the synthetic OptFollow bit
|
||||
} else {
|
||||
flags |= optNoFollow
|
||||
}
|
||||
fd, err := os.OpenFile(rootedName, flags, os.FileMode(mode))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -257,6 +265,8 @@ func (f *BasicFilesystem) OpenFile(name string, flags int, mode FileMode) (File,
|
||||
return basicFile{fd, name}, err
|
||||
}
|
||||
|
||||
// Create opens a file for writing, creating it as required. The Create will
|
||||
// fail if the destination is a symlink.
|
||||
func (f *BasicFilesystem) Create(name string) (File, error) {
|
||||
return f.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o666)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user