Skip to content

Commit

Permalink
Export ToFileMode and FromFileMode.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Zeph / Liz Loss-Cutler-Hull committed Nov 1, 2023
1 parent f215740 commit d41c7d4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions attrs.go
Expand Up @@ -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) }
Expand Down Expand Up @@ -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),
}
Expand Down
2 changes: 1 addition & 1 deletion client.go
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion ls_formatting.go
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions stat_posix.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit d41c7d4

Please sign in to comment.