1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2025-01-21 06:48:35 +00:00
restic/internal/fs/meta_fd.go
Michael Eischer 2a5bbf170d fs: implement and use filehandle based readlink
The implementations are 90% copy&paste from the go standard library as
the existing code does not offer any way to read the symlink target
based on a filehandle.

Fall back to a standard readlink on platforms other than Linux and
Windows as those either don't even provide the necessary syscall or in
case of macOS are not yet available in Go.
2024-11-30 19:17:25 +01:00

35 lines
619 B
Go

//go:build darwin || linux || windows
package fs
import "os"
type fdMetadataHandle struct {
name string
f *os.File
}
var _ metadataHandle = &fdMetadataHandle{}
func newFdMetadataHandle(name string, f *os.File) *fdMetadataHandle {
return &fdMetadataHandle{
name: name,
f: f,
}
}
func (p *fdMetadataHandle) Name() string {
return p.name
}
func (p *fdMetadataHandle) Stat() (*ExtendedFileInfo, error) {
fi, err := p.f.Stat()
if err != nil {
return nil, err
}
return extendedStat(fi), nil
}
func (p *fdMetadataHandle) Readlink() (string, error) {
return Freadlink(p.f.Fd(), fixpath(p.name))
}