Skip to content
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

Fix linter errors raised by staticcheck #236

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions local_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ func (f *fileSystemStore) Commit(consistentSnapshot bool, versions map[string]in
}
return nil
}
// Checks if target file should be deleted
needsRemoval := func(path string) bool {
if consistentSnapshot {
// strip out the hash
Expand All @@ -422,6 +423,19 @@ func (f *fileSystemStore) Commit(consistentSnapshot bool, versions map[string]in
_, ok := hashes[path]
return !ok
}
// Checks if folder is empty
folderNeedsRemoval := func(path string) bool {
f, err := os.Open(path)
if err != nil {
return false
}
defer f.Close()
_, err = f.Readdirnames(1)
if err == io.EOF {
return true
}
return false
}
removeFile := func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
Expand All @@ -431,11 +445,17 @@ func (f *fileSystemStore) Commit(consistentSnapshot bool, versions map[string]in
return err
}
if !info.IsDir() && isTarget(rel) && needsRemoval(rel) {
//lint:ignore SA9003 empty branch
// Delete the target file
if err := os.Remove(path); err != nil {
// TODO: log / handle error
return err
rdimitrov marked this conversation as resolved.
Show resolved Hide resolved
}
// Delete the target folder too if it's empty
targetFolder := filepath.Dir(path)
if folderNeedsRemoval(targetFolder) {
if err := os.Remove(targetFolder); err != nil {
return err
}
}
// TODO: remove empty directory
rdimitrov marked this conversation as resolved.
Show resolved Hide resolved
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion verify/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestDelegationsDB(t *testing.T) {
{
testName: "invalid keys",
delegations: &data.Delegations{Keys: map[string]*data.PublicKey{
"a": &data.PublicKey{Type: data.KeySchemeEd25519},
"a": {Type: data.KeySchemeEd25519},
}},
initErr: ErrWrongID{},
},
Expand Down