Run go fmt and go vet

This commit is contained in:
Jakob Unterwurzacher 2015-11-14 17:16:17 +01:00
parent f9c21e91aa
commit 61aacb5c1b
9 changed files with 49 additions and 47 deletions

View File

@ -79,8 +79,8 @@ func LoadConfFile(filename string, password string) ([]byte, *ConfFile, error) {
} }
// Verify that we know all feature flags // Verify that we know all feature flags
for _, flag := range(cf.FeatureFlags) { for _, flag := range cf.FeatureFlags {
switch(flag) { switch flag {
case FlagPlaintextNames: case FlagPlaintextNames:
continue continue
default: default:
@ -151,7 +151,7 @@ func (cf *ConfFile) WriteFile() error {
// isFeatureFlagSet - is the feature flag "flagWant" enabled? // isFeatureFlagSet - is the feature flag "flagWant" enabled?
func (cf *ConfFile) isFeatureFlagSet(flagWant string) bool { func (cf *ConfFile) isFeatureFlagSet(flagWant string) bool {
for _, flag := range(cf.FeatureFlags) { for _, flag := range cf.FeatureFlags {
if flag == flagWant { if flag == flagWant {
return true return true
} }

View File

@ -57,7 +57,7 @@ func TestCiphertextRange(t *testing.T) {
skipBytes := blocks[0].Skip skipBytes := blocks[0].Skip
if alignedLength < r.length { if alignedLength < r.length {
t.Errorf("alignedLength=%s is smaller than length=%d", alignedLength, r.length) t.Errorf("alignedLength=%d is smaller than length=%d", alignedLength, r.length)
} }
if (alignedOffset-HEADER_LEN)%f.cipherBS != 0 { if (alignedOffset-HEADER_LEN)%f.cipherBS != 0 {
t.Errorf("alignedOffset=%d is not aligned", alignedOffset) t.Errorf("alignedOffset=%d is not aligned", alignedOffset)

View File

@ -47,7 +47,9 @@ func (l *logChannel) Md5sum(buf []byte) string {
// Debug messages // Debug messages
var Debug = logChannel{false} var Debug = logChannel{false}
// Informational message e.g. startup information // Informational message e.g. startup information
var Info = logChannel{true} var Info = logChannel{true}
// A warning, meaning nothing serious by itself but might indicate problems // A warning, meaning nothing serious by itself but might indicate problems
var Warn = logChannel{true} var Warn = logChannel{true}

View File

@ -1,17 +1,19 @@
package integration_tests package integration_tests
import ( import (
"os"
"os/exec"
"fmt"
"io/ioutil"
"crypto/md5" "crypto/md5"
"encoding/hex" "encoding/hex"
"fmt"
"io/ioutil"
"os"
"os/exec"
"testing" "testing"
) )
const tmpDir = "/tmp/gocryptfs_main_test/" const tmpDir = "/tmp/gocryptfs_main_test/"
// Mountpoint // Mountpoint
// Note: the code assumes that both have a trailing slash!
const plainDir = tmpDir + "plain/" const plainDir = tmpDir + "plain/"
const cipherDir = tmpDir + "cipher/" const cipherDir = tmpDir + "cipher/"

View File

@ -1,10 +1,10 @@
package integration_tests package integration_tests
import ( import (
"flag"
"bytes" "bytes"
"crypto/md5" "crypto/md5"
"encoding/hex" "encoding/hex"
"flag"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
@ -33,7 +33,6 @@ func TestMain(m *testing.M) {
os.Exit(r) os.Exit(r)
} }
if testing.Verbose() { if testing.Verbose() {
fmt.Printf("***** Testing with native Go crypto\n") fmt.Printf("***** Testing with native Go crypto\n")
} }
@ -278,7 +277,7 @@ func TestFiltered(t *testing.T) {
filteredFile := plainDir + "gocryptfs.conf" filteredFile := plainDir + "gocryptfs.conf"
file, err := os.Create(filteredFile) file, err := os.Create(filteredFile)
if plaintextNames == true && err == nil { if plaintextNames == true && err == nil {
fmt.Errorf("should have failed but didn't") t.Errorf("should have failed but didn't")
} else if plaintextNames == false && err != nil { } else if plaintextNames == false && err != nil {
t.Error(err) t.Error(err)
} }
@ -286,7 +285,7 @@ func TestFiltered(t *testing.T) {
err = os.Remove(filteredFile) err = os.Remove(filteredFile)
if plaintextNames == true && err == nil { if plaintextNames == true && err == nil {
fmt.Errorf("should have failed but didn't") t.Errorf("should have failed but didn't")
} else if plaintextNames == false && err != nil { } else if plaintextNames == false && err != nil {
t.Error(err) t.Error(err)
} }

View File

@ -1,10 +1,10 @@
package integration_tests package integration_tests
import ( import (
"io/ioutil"
"os"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os"
"testing" "testing"
) )

19
main.go
View File

@ -66,8 +66,7 @@ func usageText() {
type argContainer struct { type argContainer struct {
debug, init, zerokey, fusedebug, openssl, passwd, foreground, version, debug, init, zerokey, fusedebug, openssl, passwd, foreground, version,
plaintextnames, quiet bool plaintextnames, quiet bool
masterkey, mountpoint, cipherdir string masterkey, mountpoint, cipherdir, cpuprofile string
cpuprofile *string
notifypid int notifypid int
} }
@ -88,13 +87,13 @@ func main() {
flagSet.BoolVar(&args.passwd, "passwd", false, "Change password") flagSet.BoolVar(&args.passwd, "passwd", false, "Change password")
flagSet.BoolVar(&args.foreground, "f", false, "Stay in the foreground") flagSet.BoolVar(&args.foreground, "f", false, "Stay in the foreground")
flagSet.BoolVar(&args.version, "version", false, "Print version and exit") flagSet.BoolVar(&args.version, "version", false, "Print version and exit")
flagSet.BoolVar(&args.plaintextnames, "plaintextnames", false, flagSet.BoolVar(&args.plaintextnames, "plaintextnames", false, "Do not encrypt "+
"Do not encrypt file names - can only be used together with -init") "file names - can only be used together with -init")
flagSet.BoolVar(&args.quiet, "q", false, "Quiet - silence informational messages") flagSet.BoolVar(&args.quiet, "q", false, "Quiet - silence informational messages")
flagSet.StringVar(&args.masterkey, "masterkey", "", "Mount with explicit master key") flagSet.StringVar(&args.masterkey, "masterkey", "", "Mount with explicit master key")
args.cpuprofile = flagSet.String("cpuprofile", "", "Write cpu profile to specified file") flagSet.StringVar(&args.cpuprofile, "cpuprofile", "", "Write cpu profile to specified file")
flagSet.IntVar(&args.notifypid, "notifypid", 0, flagSet.IntVar(&args.notifypid, "notifypid", 0, "Send USR1 to the specified process after "+
"Send USR1 to the specified process after successful mount - used internally for daemonization") "successful mount - used internally for daemonization")
flagSet.Parse(os.Args[1:]) flagSet.Parse(os.Args[1:])
if args.version { if args.version {
fmt.Printf("%s %s; on-disk format %d\n", PROGRAM_NAME, GitVersion, cryptfs.HEADER_CURRENT_VERSION) fmt.Printf("%s %s; on-disk format %d\n", PROGRAM_NAME, GitVersion, cryptfs.HEADER_CURRENT_VERSION)
@ -106,13 +105,13 @@ func main() {
if !args.foreground { if !args.foreground {
daemonize() // does not return daemonize() // does not return
} }
if *args.cpuprofile != "" { if args.cpuprofile != "" {
f, err := os.Create(*args.cpuprofile) f, err := os.Create(args.cpuprofile)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
os.Exit(ERREXIT_INIT) os.Exit(ERREXIT_INIT)
} }
cryptfs.Info.Printf("Writing CPU profile to %s\n", *args.cpuprofile) cryptfs.Info.Printf("Writing CPU profile to %s\n", args.cpuprofile)
pprof.StartCPUProfile(f) pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile() defer pprof.StopCPUProfile()
} }