Remove: permission denied is now os.ErrPermission

fix TestClientRemoveDir test case on macOS
This commit is contained in:
Nicola Murino 2020-12-08 14:43:19 +01:00
parent f5fd2fb058
commit c811ca3a25
1 changed files with 7 additions and 3 deletions

View File

@ -655,14 +655,18 @@ func (c *Client) Join(elem ...string) string { return path.Join(elem...) }
// is not empty.
func (c *Client) Remove(path string) error {
err := c.removeFile(path)
// some servers, *cough* osx *cough*, return EPERM, not ENODIR.
// serv-u returns ssh_FX_FILE_IS_A_DIRECTORY
// EPERM is converted to os.ErrPermission so it is not a StatusError
if err, ok := err.(*StatusError); ok {
switch err.Code {
// some servers, *cough* osx *cough*, return EPERM, not ENODIR.
// serv-u returns ssh_FX_FILE_IS_A_DIRECTORY
case sshFxPermissionDenied, sshFxFailure, sshFxFileIsADirectory:
case sshFxFailure, sshFxFileIsADirectory:
return c.RemoveDirectory(path)
}
}
if os.IsPermission(err) {
return c.RemoveDirectory(path)
}
return err
}