Skip to content

Commit

Permalink
Switch from os.* to fs.* types
Browse files Browse the repository at this point in the history
  • Loading branch information
bodgit committed Aug 12, 2022
1 parent dd3fc5f commit 4b361ef
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
3 changes: 2 additions & 1 deletion reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"hash/crc32"
"io"
"io/fs"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -148,7 +149,7 @@ func OpenReaderWithPassword(name, password string) (*ReadCloser, error) {
for i := 2; true; i++ {
f, err := os.Open(fmt.Sprintf("%s.%03d", strings.TrimSuffix(name, ext), i))
if err != nil {
if os.IsNotExist(err) {
if errors.Is(err, fs.ErrNotExist) {
break
}

Expand Down
36 changes: 18 additions & 18 deletions struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"hash"
"hash/crc32"
"io"
"os"
"io/fs"
"path"
"time"

Expand Down Expand Up @@ -329,8 +329,8 @@ type FileHeader struct {
isEmptyFile bool
}

// FileInfo returns an os.FileInfo for the FileHeader.
func (h *FileHeader) FileInfo() os.FileInfo {
// FileInfo returns an fs.FileInfo for the FileHeader.
func (h *FileHeader) FileInfo() fs.FileInfo {
return headerFileInfo{h}
}

Expand All @@ -354,7 +354,7 @@ func (fi headerFileInfo) ModTime() time.Time {
return fi.fh.Modified.UTC()
}

func (fi headerFileInfo) Mode() os.FileMode {
func (fi headerFileInfo) Mode() fs.FileMode {
return fi.fh.Mode()
}

Expand Down Expand Up @@ -382,7 +382,7 @@ const (
)

// Mode returns the permission and mode bits for the FileHeader.
func (h *FileHeader) Mode() (mode os.FileMode) {
func (h *FileHeader) Mode() (mode fs.FileMode) {
// Prefer the POSIX attributes if they're present
if h.Attributes&0xf0000000 != 0 {
mode = unixModeToFileMode(h.Attributes >> 16)
Expand All @@ -393,9 +393,9 @@ func (h *FileHeader) Mode() (mode os.FileMode) {
return
}

func msdosModeToFileMode(m uint32) (mode os.FileMode) {
func msdosModeToFileMode(m uint32) (mode fs.FileMode) {
if m&msdosDir != 0 {
mode = os.ModeDir | 0o777
mode = fs.ModeDir | 0o777
} else {
mode = 0o666
}
Expand All @@ -408,36 +408,36 @@ func msdosModeToFileMode(m uint32) (mode os.FileMode) {
}

//nolint:cyclop
func unixModeToFileMode(m uint32) os.FileMode {
mode := os.FileMode(m & 0o777)
func unixModeToFileMode(m uint32) fs.FileMode {
mode := fs.FileMode(m & 0o777)

switch m & sIFMT {
case sIFBLK:
mode |= os.ModeDevice
mode |= fs.ModeDevice
case sIFCHR:
mode |= os.ModeDevice | os.ModeCharDevice
mode |= fs.ModeDevice | fs.ModeCharDevice
case sIFDIR:
mode |= os.ModeDir
mode |= fs.ModeDir
case sIFIFO:
mode |= os.ModeNamedPipe
mode |= fs.ModeNamedPipe
case sIFLNK:
mode |= os.ModeSymlink
mode |= fs.ModeSymlink
case sIFREG:
// nothing to do
case sIFSOCK:
mode |= os.ModeSocket
mode |= fs.ModeSocket
}

if m&sISGID != 0 {
mode |= os.ModeSetgid
mode |= fs.ModeSetgid
}

if m&sISUID != 0 {
mode |= os.ModeSetuid
mode |= fs.ModeSetuid
}

if m&sISVTX != 0 {
mode |= os.ModeSticky
mode |= fs.ModeSticky
}

return mode
Expand Down

0 comments on commit 4b361ef

Please sign in to comment.