github.com/haraldrudell/parl@v0.4.176/pfs/add-dir-entry.go (about)

     1  /*
     2  © 2023–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/)
     3  ISC License
     4  */
     5  
     6  package pfs
     7  
     8  import (
     9  	"io/fs"
    10  	"os"
    11  
    12  	"github.com/haraldrudell/parl/perrors"
    13  )
    14  
    15  var _ fs.FileInfo
    16  var _ fs.FileMode
    17  var _ = fs.FileMode.IsDir
    18  var _ = fs.FileMode.Type
    19  
    20  // AddDirEntry returns an [fs.DirEntry] with [fs.FileInfo] available
    21  //   - error if [os.Lstat] fails
    22  func AddDirEntry(abs string) (dirEntry fs.DirEntry, err error) {
    23  	var fileInfo fs.FileInfo
    24  	if fileInfo, err = os.Lstat(abs); perrors.IsPF(&err, "os.Lstat %w", err) {
    25  		return
    26  	}
    27  	dirEntry = fs.FileInfoToDirEntry(fileInfo)
    28  
    29  	return
    30  }
    31  
    32  // AddDirEntry returns an [fs.DirEntry] for the target of a symbolic link
    33  func AddStatDirEntry(abs string) (dirEntry fs.DirEntry, err error) {
    34  	var fileInfo fs.FileInfo
    35  	if fileInfo, err = os.Stat(abs); perrors.IsPF(&err, "os.Stat %w", err) {
    36  		return
    37  	}
    38  	dirEntry = fs.FileInfoToDirEntry(fileInfo)
    39  
    40  	return
    41  }