fix golint complaints

This commit is contained in:
Jakob Unterwurzacher 2017-04-29 14:50:58 +02:00
parent 7d38f80a78
commit edb3e19cb5
9 changed files with 31 additions and 22 deletions

View File

@ -3,4 +3,5 @@
golint ./... | \ golint ./... | \
grep -v "don't use an underscore in package name" | \ grep -v "don't use an underscore in package name" | \
grep -v "don't use ALL_CAPS in Go names; use CamelCase" | grep -v "don't use ALL_CAPS in Go names; use CamelCase" |
grep -v "struct field allow_other should be allowOther" grep -v "struct field allow_other should be allowOther" |
grep -v "struct field serialize_reads should be serializeReads"

View File

@ -15,7 +15,7 @@ import (
"github.com/rfjakob/gocryptfs/internal/stupidgcm" "github.com/rfjakob/gocryptfs/internal/stupidgcm"
) )
// BackendTypeEnum indicates the type of AEAD backend in use. // AEADTypeEnum indicates the type of AEAD backend in use.
type AEADTypeEnum int type AEADTypeEnum int
const ( const (

View File

@ -10,12 +10,13 @@ import (
const ( const (
// Other error - please inspect the message // Other error - please inspect the message
Other = 11 Other = 11
// The password was incorrect // PasswordIncorrect - the password was incorrect
PasswordIncorrect = 12 PasswordIncorrect = 12
// TODO several other exit codes are defined in main.go. These will be // TODO several other exit codes are defined in main.go. These will be
// ported over here. // ported over here.
) )
// Err wraps and error with an associated numeric exit code
type Err struct { type Err struct {
error error
code int code int
@ -29,6 +30,8 @@ func NewErr(msg string, code int) Err {
} }
} }
// Exit extracts the numeric exit code from "err" (if available) and exits the
// application.
func Exit(err error) { func Exit(err error) {
err2, ok := err.(Err) err2, ok := err.(Err)
if !ok { if !ok {

View File

@ -187,13 +187,13 @@ func (f *file) truncateGrowFile(oldPlainSz uint64, newPlainSz uint64) fuse.Statu
if oldPlainSz > 0 { if oldPlainSz > 0 {
n1 = f.contentEnc.PlainOffToBlockNo(oldPlainSz - 1) n1 = f.contentEnc.PlainOffToBlockNo(oldPlainSz - 1)
} }
newEofOffset := newPlainSz - 1 newEOFOffset := newPlainSz - 1
n2 := f.contentEnc.PlainOffToBlockNo(newEofOffset) n2 := f.contentEnc.PlainOffToBlockNo(newEOFOffset)
// The file is grown within one block, no need to pad anything. // The file is grown within one block, no need to pad anything.
// Write a single zero to the last byte and let doWrite figure out the RMW. // Write a single zero to the last byte and let doWrite figure out the RMW.
if n1 == n2 { if n1 == n2 {
buf := make([]byte, 1) buf := make([]byte, 1)
_, status := f.doWrite(buf, int64(newEofOffset)) _, status := f.doWrite(buf, int64(newEOFOffset))
return status return status
} }
// The truncate creates at least one new block. // The truncate creates at least one new block.
@ -224,6 +224,6 @@ func (f *file) truncateGrowFile(oldPlainSz uint64, newPlainSz uint64) fuse.Statu
// The new size is NOT aligned, so we need to write a partial block. // The new size is NOT aligned, so we need to write a partial block.
// Write a single zero to the last byte and let doWrite figure it out. // Write a single zero to the last byte and let doWrite figure it out.
buf := make([]byte, 1) buf := make([]byte, 1)
_, status := f.doWrite(buf, int64(newEofOffset)) _, status := f.doWrite(buf, int64(newEOFOffset))
return status return status
} }

View File

@ -45,7 +45,7 @@ func NewFS(args Args) *FS {
nameTransform := nametransform.New(cryptoCore.EMECipher, args.LongNames, args.Raw64) nameTransform := nametransform.New(cryptoCore.EMECipher, args.LongNames, args.Raw64)
if args.SerializeReads { if args.SerializeReads {
serialize_reads.Init() serialize_reads.InitSerializer()
} }
return &FS{ return &FS{

View File

@ -182,13 +182,13 @@ func (rfs *ReverseFS) GetAttr(relPath string, context *fuse.Context) (*fuse.Attr
// Access - FUSE call // Access - FUSE call
func (rfs *ReverseFS) Access(relPath string, mode uint32, context *fuse.Context) fuse.Status { func (rfs *ReverseFS) Access(relPath string, mode uint32, context *fuse.Context) fuse.Status {
if rfs.isTranslatedConfig(relPath) || rfs.isDirIV(relPath) || rfs.isNameFile(relPath) { if rfs.isTranslatedConfig(relPath) || rfs.isDirIV(relPath) || rfs.isNameFile(relPath) {
// access(2) R_OK flag for checking if the file is readable, always 4 as defined in POSIX.
ROK := uint32(0x4)
// Virtual files can always be read and never written // Virtual files can always be read and never written
var R_OK uint32 = 4 if mode == ROK || mode == 0 {
if mode == R_OK || mode == 0 {
return fuse.OK return fuse.OK
} else {
return fuse.EPERM
} }
return fuse.EPERM
} }
absPath, err := rfs.abs(rfs.decryptPath(relPath)) absPath, err := rfs.abs(rfs.decryptPath(relPath))
if err != nil { if err != nil {

View File

@ -8,7 +8,8 @@ import (
"github.com/rfjakob/gocryptfs/internal/tlog" "github.com/rfjakob/gocryptfs/internal/tlog"
) )
type SerializerStruct struct { // serializerState is used by the Wait and Done functions
type serializerState struct {
// we get submissions through the "input" channel // we get submissions through the "input" channel
input chan *submission input chan *submission
// q = Queue // q = Queue
@ -37,7 +38,7 @@ type submission struct {
size int size int
} }
func (sr *SerializerStruct) wait(offset int64, size int) { func (sr *serializerState) wait(offset int64, size int) {
ch := make(chan struct{}) ch := make(chan struct{})
sb := &submission{ sb := &submission{
ch: ch, ch: ch,
@ -52,7 +53,7 @@ func (sr *SerializerStruct) wait(offset int64, size int) {
// push returns true if the queue is full after the element has been stored. // push returns true if the queue is full after the element has been stored.
// It panics if it did not have space to store the element. // It panics if it did not have space to store the element.
func (sr *SerializerStruct) push(sb *submission) (full bool) { func (sr *serializerState) push(sb *submission) (full bool) {
free := 0 free := 0
stored := false stored := false
for i, v := range sr.q { for i, v := range sr.q {
@ -77,7 +78,7 @@ func (sr *SerializerStruct) push(sb *submission) (full bool) {
} }
// pop the submission with the lowest offset off the queue // pop the submission with the lowest offset off the queue
func (sr *SerializerStruct) pop() *submission { func (sr *serializerState) pop() *submission {
var winner *submission var winner *submission
var winnerIndex int var winnerIndex int
for i, v := range sr.q { for i, v := range sr.q {
@ -101,7 +102,7 @@ func (sr *SerializerStruct) pop() *submission {
return winner return winner
} }
func (sr *SerializerStruct) eventLoop() { func (sr *serializerState) eventLoop() {
sr.input = make(chan *submission) sr.input = make(chan *submission)
empty := true empty := true
for { for {
@ -128,7 +129,7 @@ func (sr *SerializerStruct) eventLoop() {
} }
// Unblock a submission and wait for completion // Unblock a submission and wait for completion
func (sr *SerializerStruct) unblockOne() (empty bool) { func (sr *serializerState) unblockOne() (empty bool) {
winner := sr.pop() winner := sr.pop()
if winner == nil { if winner == nil {
return true return true
@ -139,10 +140,11 @@ func (sr *SerializerStruct) unblockOne() (empty bool) {
return false return false
} }
var serializer SerializerStruct var serializer serializerState
// Called by fusefrontend.NewFS // InitSerializer sets up the internal serializer state and starts the event loop.
func Init() { // Called by fusefrontend.NewFS.
func InitSerializer() {
serializer.input = make(chan *submission) serializer.input = make(chan *submission)
serializer.q = make([]*submission, 10) serializer.q = make([]*submission, 10)
go serializer.eventLoop() go serializer.eventLoop()

View File

@ -16,13 +16,15 @@ type sivAead struct {
var _ cipher.AEAD = &sivAead{} var _ cipher.AEAD = &sivAead{}
const ( const (
// KeyLen is the required key length. The SIV algorithm supports other lengths,
// but we only support 64.
KeyLen = 64 KeyLen = 64
) )
// New returns a new cipher.AEAD implementation. // New returns a new cipher.AEAD implementation.
func New(key []byte) cipher.AEAD { func New(key []byte) cipher.AEAD {
if len(key) != KeyLen { if len(key) != KeyLen {
// SIV supports more 32, 48 or 64-byte keys, but in gocryptfs we // SIV supports 32, 48 or 64-byte keys, but in gocryptfs we
// exclusively use 64. // exclusively use 64.
log.Panicf("Key must be %d byte long (you passed %d)", KeyLen, len(key)) log.Panicf("Key must be %d byte long (you passed %d)", KeyLen, len(key))
} }

View File

@ -17,6 +17,7 @@ import (
"github.com/rfjakob/gocryptfs/internal/stupidgcm" "github.com/rfjakob/gocryptfs/internal/stupidgcm"
) )
// Run - run the speed the test and print the results.
func Run() { func Run() {
bTable := []struct { bTable := []struct {
name string name string