Skip to content

Commit

Permalink
Merge pull request #8171 from tanjunchen/staticcheck001
Browse files Browse the repository at this point in the history
util/pkg/vfs/:staticcheck
  • Loading branch information
k8s-ci-robot authored Dec 27, 2019
2 parents adf6593 + 3f9400a commit 2376814
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
14 changes: 7 additions & 7 deletions util/pkg/vfs/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,22 @@ func (c *VFSContext) ReadFile(location string, options ...VFSOption) ([]byte, er
httpURL := "http://169.254.169.254/computeMetadata/v1/instance/attributes/" + u.Path
httpHeaders := make(map[string]string)
httpHeaders["Metadata-Flavor"] = "Google"
return c.readHttpLocation(httpURL, httpHeaders, opts)
return c.readHTTPLocation(httpURL, httpHeaders, opts)
case "aws":
httpURL := "http://169.254.169.254/latest/" + u.Path
return c.readHttpLocation(httpURL, nil, opts)
return c.readHTTPLocation(httpURL, nil, opts)
case "digitalocean":
httpURL := "http://169.254.169.254/metadata/v1" + u.Path
return c.readHttpLocation(httpURL, nil, opts)
return c.readHTTPLocation(httpURL, nil, opts)
case "alicloud":
httpURL := "http://100.100.100.200/latest/meta-data/" + u.Path
return c.readHttpLocation(httpURL, nil, opts)
return c.readHTTPLocation(httpURL, nil, opts)
default:
return nil, fmt.Errorf("unknown metadata type: %q in %q", u.Host, location)
}

case "http", "https":
return c.readHttpLocation(location, nil, opts)
return c.readHTTPLocation(location, nil, opts)
}
}

Expand Down Expand Up @@ -169,10 +169,10 @@ func (c *VFSContext) BuildVfsPath(p string) (Path, error) {
return nil, fmt.Errorf("unknown / unhandled path type: %q", p)
}

// readHttpLocation reads an http (or https) url.
// readHTTPLocation reads an http (or https) url.
// It returns the contents, or an error on any non-200 response. On a 404, it will return os.ErrNotExist
// It will retry a few times on a 500 class error
func (c *VFSContext) readHttpLocation(httpURL string, httpHeaders map[string]string, opts vfsOptions) ([]byte, error) {
func (c *VFSContext) readHTTPLocation(httpURL string, httpHeaders map[string]string, opts vfsOptions) ([]byte, error) {
var body []byte

done, err := RetryWithBackoff(opts.backoff, func() (bool, error) {
Expand Down
4 changes: 2 additions & 2 deletions util/pkg/vfs/gsfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ func (p *GSPath) WriteFile(data io.ReadSeeker, acl ACL) error {
}

if acl != nil {
gsAcl, ok := acl.(*GSAcl)
gsACL, ok := acl.(*GSAcl)
if !ok {
return true, fmt.Errorf("write to %s with ACL of unexpected type %T", p, acl)
}
obj.Acl = gsAcl.Acl
obj.Acl = gsACL.Acl
}

if _, err := data.Seek(0, 0); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions util/pkg/vfs/sshfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ func (p *SSHPath) WriteFile(data io.ReadSeeker, acl ACL) error {

if err == nil {
if acl != nil {
sshAcl, ok := acl.(*SSHAcl)
sshACL, ok := acl.(*SSHAcl)
if !ok {
err = fmt.Errorf("unexpected acl type %T", acl)
} else {
err = sftpClient.Chmod(tempfile, sshAcl.Mode)
err = sftpClient.Chmod(tempfile, sshACL.Mode)
if err != nil {
err = fmt.Errorf("error during chmod of %q: %v", tempfile, err)
}
Expand Down
20 changes: 10 additions & 10 deletions util/pkg/vfs/vfssync.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ func NewVFSScan(base Path) *VFSScan {
type ChangeType string

const (
ChangeType_Added ChangeType = "ADDED"
ChangeType_Removed ChangeType = "REMOVED"
ChangeType_Modified ChangeType = "MODIFIED"
ChangeTypeAdded ChangeType = "ADDED"
ChangeTypeRemoved ChangeType = "REMOVED"
ChangeTypeModified ChangeType = "MODIFIED"
)

type Change struct {
Expand All @@ -49,7 +49,7 @@ type Change struct {
Hash *hashing.Hash
}

// Scans for changes files. On the first call will return all files as ChangeType_Added.
// Scans for changes files. On the first call will return all files as ChangeTypeAdded.
// On subsequent calls will return any changed files (using their hashes)
func (v *VFSScan) Scan() ([]Change, error) {
allFiles, err := v.Base.ReadTree()
Expand Down Expand Up @@ -79,7 +79,7 @@ func (v *VFSScan) Scan() ([]Change, error) {
var changes []Change
for k, f := range files {
hash := hashes[k]
changes = append(changes, Change{ChangeType: ChangeType_Added, Path: f, Hash: hash})
changes = append(changes, Change{ChangeType: ChangeTypeAdded, Path: f, Hash: hash})
}
return changes, nil
}
Expand All @@ -90,17 +90,17 @@ func (v *VFSScan) Scan() ([]Change, error) {
newHash := hashes[k]

if oldHash == nil {
changes = append(changes, Change{ChangeType: ChangeType_Added, Path: f, Hash: newHash})
changes = append(changes, Change{ChangeType: ChangeTypeAdded, Path: f, Hash: newHash})
} else if !oldHash.Equal(newHash) {
changes = append(changes, Change{ChangeType: ChangeType_Modified, Path: f, Hash: newHash})
changes = append(changes, Change{ChangeType: ChangeTypeModified, Path: f, Hash: newHash})
}
}

for k := range v.hashes {
newHash := hashes[k]
f := files[k]
if newHash == nil {
changes = append(changes, Change{ChangeType: ChangeType_Removed, Path: f, Hash: newHash})
changes = append(changes, Change{ChangeType: ChangeTypeRemoved, Path: f, Hash: newHash})
}
}

Expand All @@ -125,7 +125,7 @@ func SyncDir(src *VFSScan, destBase Path) error {
destFile := destBase.Join(relativePath)

switch change.ChangeType {
case ChangeType_Removed:
case ChangeTypeRemoved:
err := destFile.Remove()
if err != nil {
if !os.IsNotExist(err) {
Expand All @@ -134,7 +134,7 @@ func SyncDir(src *VFSScan, destBase Path) error {
}
continue

case ChangeType_Modified, ChangeType_Added:
case ChangeTypeModified, ChangeTypeAdded:
hashMatch, err := hashesMatch(f, destFile)
if err != nil {
return err
Expand Down

0 comments on commit 2376814

Please sign in to comment.