From d41c7d48fe1254d5dea884365444a16ee42bdb1c Mon Sep 17 00:00:00 2001 From: Zeph / Liz Loss-Cutler-Hull Date: Tue, 31 Oct 2023 20:24:39 -0700 Subject: [PATCH] Export ToFileMode and FromFileMode. For the sake of sanity, we really should be offering _some_ way for users of memfile to get the file mode right. These two are what we use internally, so they make perfect sense to expose. --- attrs.go | 4 ++-- client.go | 2 +- ls_formatting.go | 2 +- stat_posix.go | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/attrs.go b/attrs.go index 758cd4ff..97c42a9c 100644 --- a/attrs.go +++ b/attrs.go @@ -32,7 +32,7 @@ func (fi *fileInfo) Name() string { return fi.name } func (fi *fileInfo) Size() int64 { return int64(fi.stat.Size) } // Mode returns file mode bits. -func (fi *fileInfo) Mode() os.FileMode { return toFileMode(fi.stat.Mode) } +func (fi *fileInfo) Mode() os.FileMode { return ToFileMode(fi.stat.Mode) } // ModTime returns the last modification time of the file. func (fi *fileInfo) ModTime() time.Time { return time.Unix(int64(fi.stat.Mtime), 0) } @@ -92,7 +92,7 @@ func fileStatFromInfo(fi os.FileInfo) (uint32, *FileStat) { fileStat := &FileStat{ Size: uint64(fi.Size()), - Mode: fromFileMode(fi.Mode()), + Mode: FromFileMode(fi.Mode()), Mtime: uint32(mtime), Atime: uint32(atime), } diff --git a/client.go b/client.go index e10518b2..af4aa6b0 100644 --- a/client.go +++ b/client.go @@ -2009,7 +2009,7 @@ func flags(f int) uint32 { // toChmodPerm converts Go permission bits to POSIX permission bits. // -// This differs from fromFileMode in that we preserve the POSIX versions of +// This differs from FromFileMode in that we preserve the POSIX versions of // setuid, setgid and sticky in m, because we've historically supported those // bits, and we mask off any non-permission bits. func toChmodPerm(m os.FileMode) (perm uint32) { diff --git a/ls_formatting.go b/ls_formatting.go index 19271ad7..e0c069fa 100644 --- a/ls_formatting.go +++ b/ls_formatting.go @@ -47,7 +47,7 @@ func runLs(idLookup NameLookupFileLister, dirent os.FileInfo) string { // format: // {directory / char device / etc}{rwxrwxrwx} {number of links} owner group size month day [time (this year) | year (otherwise)] name - symPerms := sshfx.FileMode(fromFileMode(dirent.Mode())).String() + symPerms := sshfx.FileMode(FromFileMode(dirent.Mode())).String() var numLinks uint64 = 1 uid, gid := "0", "0" diff --git a/stat_posix.go b/stat_posix.go index 5b870e23..bc5160c3 100644 --- a/stat_posix.go +++ b/stat_posix.go @@ -49,8 +49,8 @@ func isRegular(mode uint32) bool { return mode&S_IFMT == syscall.S_IFREG } -// toFileMode converts sftp filemode bits to the os.FileMode specification -func toFileMode(mode uint32) os.FileMode { +// ToFileMode converts sftp filemode bits to the os.FileMode specification +func ToFileMode(mode uint32) os.FileMode { var fm = os.FileMode(mode & 0777) switch mode & S_IFMT { @@ -83,8 +83,8 @@ func toFileMode(mode uint32) os.FileMode { return fm } -// fromFileMode converts from the os.FileMode specification to sftp filemode bits -func fromFileMode(mode os.FileMode) uint32 { +// FromFileMode converts from the os.FileMode specification to sftp filemode bits +func FromFileMode(mode os.FileMode) uint32 { ret := uint32(mode & os.ModePerm) switch mode & os.ModeType {