-
Notifications
You must be signed in to change notification settings - Fork 381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for zos/s390x #582
Merged
Merged
Changes from 3 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package sftp | ||
|
||
import ( | ||
"os" | ||
"syscall" | ||
) | ||
|
||
var EBADF = syscall.NewError("fd out of range or not open") | ||
|
||
func wrapPathError(filepath string, err error) error { | ||
if errno, ok := err.(syscall.ErrorString); ok { | ||
return &os.PathError{Path: filepath, Err: errno} | ||
} | ||
return err | ||
} | ||
|
||
// translateErrno translates a syscall error number to a SFTP error code. | ||
func translateErrno(errno syscall.ErrorString) uint32 { | ||
switch errno { | ||
case "": | ||
return sshFxOk | ||
case syscall.ENOENT: | ||
return sshFxNoSuchFile | ||
case syscall.EPERM: | ||
return sshFxPermissionDenied | ||
} | ||
|
||
return sshFxFailure | ||
} | ||
|
||
func translateSyscallError(err error) (uint32, bool) { | ||
switch e := err.(type) { | ||
case syscall.ErrorString: | ||
return translateErrno(e), true | ||
case *os.PathError: | ||
debug("statusFromError,pathError: error is %T %#v", e.Err, e.Err) | ||
if errno, ok := e.Err.(syscall.ErrorString); ok { | ||
return translateErrno(errno), true | ||
} | ||
} | ||
return 0, false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//go:build !plan9 | ||
// +build !plan9 | ||
|
||
package sftp | ||
|
||
import ( | ||
"os" | ||
"syscall" | ||
) | ||
|
||
const EBADF = syscall.EBADF | ||
|
||
func wrapPathError(filepath string, err error) error { | ||
if errno, ok := err.(syscall.Errno); ok { | ||
return &os.PathError{Path: filepath, Err: errno} | ||
} | ||
return err | ||
} | ||
|
||
// translateErrno translates a syscall error number to a SFTP error code. | ||
func translateErrno(errno syscall.Errno) uint32 { | ||
switch errno { | ||
case 0: | ||
return sshFxOk | ||
case syscall.ENOENT: | ||
return sshFxNoSuchFile | ||
case syscall.EACCES, syscall.EPERM: | ||
return sshFxPermissionDenied | ||
} | ||
|
||
return sshFxFailure | ||
} | ||
|
||
func translateSyscallError(err error) (uint32, bool) { | ||
switch e := err.(type) { | ||
case syscall.Errno: | ||
return translateErrno(e), true | ||
case *os.PathError: | ||
debug("statusFromError,pathError: error is %T %#v", e.Err, e.Err) | ||
if errno, ok := e.Err.(syscall.Errno); ok { | ||
return translateErrno(errno), true | ||
} | ||
} | ||
return 0, false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package sftp | ||
|
||
import ( | ||
"os" | ||
|
||
sshfx "github.com/pkg/sftp/internal/encoding/ssh/filexfer" | ||
) | ||
|
||
// isRegular returns true if the mode describes a regular file. | ||
func isRegular(mode uint32) bool { | ||
return sshfx.FileMode(mode)&sshfx.ModeType == sshfx.ModeRegular | ||
} | ||
|
||
// toFileMode converts sftp filemode bits to the os.FileMode specification | ||
func toFileMode(mode uint32) os.FileMode { | ||
var fm = os.FileMode(mode & 0777) | ||
|
||
switch sshfx.FileMode(mode) & sshfx.ModeType { | ||
case sshfx.ModeDevice: | ||
fm |= os.ModeDevice | ||
case sshfx.ModeCharDevice: | ||
fm |= os.ModeDevice | os.ModeCharDevice | ||
case sshfx.ModeDir: | ||
fm |= os.ModeDir | ||
case sshfx.ModeNamedPipe: | ||
fm |= os.ModeNamedPipe | ||
case sshfx.ModeSymlink: | ||
fm |= os.ModeSymlink | ||
case sshfx.ModeRegular: | ||
// nothing to do | ||
case sshfx.ModeSocket: | ||
fm |= os.ModeSocket | ||
} | ||
|
||
if sshfx.FileMode(mode)&sshfx.ModeSetUID != 0 { | ||
fm |= os.ModeSetuid | ||
} | ||
if sshfx.FileMode(mode)&sshfx.ModeSetGID != 0 { | ||
fm |= os.ModeSetgid | ||
} | ||
if sshfx.FileMode(mode)&sshfx.ModeSticky != 0 { | ||
fm |= os.ModeSticky | ||
} | ||
|
||
return fm | ||
} | ||
|
||
// fromFileMode converts from the os.FileMode specification to sftp filemode bits | ||
func fromFileMode(mode os.FileMode) uint32 { | ||
ret := sshfx.FileMode(mode & os.ModePerm) | ||
|
||
switch mode & os.ModeType { | ||
case os.ModeDevice | os.ModeCharDevice: | ||
ret |= sshfx.ModeCharDevice | ||
case os.ModeDevice: | ||
ret |= sshfx.ModeDevice | ||
case os.ModeDir: | ||
ret |= sshfx.ModeDir | ||
case os.ModeNamedPipe: | ||
ret |= sshfx.ModeNamedPipe | ||
case os.ModeSymlink: | ||
ret |= sshfx.ModeSymlink | ||
case 0: | ||
ret |= sshfx.ModeRegular | ||
case os.ModeSocket: | ||
ret |= sshfx.ModeSocket | ||
} | ||
|
||
if mode&os.ModeSetuid != 0 { | ||
ret |= sshfx.ModeSetUID | ||
} | ||
if mode&os.ModeSetgid != 0 { | ||
ret |= sshfx.ModeSetGID | ||
} | ||
if mode&os.ModeSticky != 0 { | ||
ret |= sshfx.ModeSticky | ||
} | ||
|
||
return uint32(ret) | ||
} | ||
|
||
const ( | ||
s_ISUID = uint32(sshfx.ModeSetUID) | ||
s_ISGID = uint32(sshfx.ModeSetGID) | ||
s_ISVTX = uint32(sshfx.ModeSticky) | ||
) | ||
|
||
// Legacy export: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [golint] godoc should start with (I know the comments on the pre-existing code wasn’t ideal, and you’re just moving it around.) |
||
// | ||
// Go defines S_IFMT on windows, plan9 and js/wasm as 0x1f000 instead of | ||
// 0xf000. None of the the other S_IFxyz values include the "1" (in 0x1f000) | ||
// which prevents them from matching the bitmask. | ||
const S_IFMT = uint32(sshfx.ModeType) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider that POSIX standard requires the assertion:
O_RDONLY | O_WRONLY == O_RDWR
[1]However, due to constant folding, I think we’re still fine here regardless.
1: https://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html