diff options
author | Jakob Unterwurzacher | 2020-09-06 11:35:25 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2020-09-06 11:35:25 +0200 |
commit | 993b19c19c26eac480d88cc67bfe7455e67faada (patch) | |
tree | d453b62170f25ed64c1adc73fc7c56cd35e1f2dd | |
parent | 598e5f385e4b6cc135a78e708112ade96edbb35c (diff) |
gocryptfs -init: fix wrong exit code on non-empty dir
Fixes https://github.com/rfjakob/gocryptfs/pull/503
-rw-r--r-- | init_dir.go | 2 | ||||
-rw-r--r-- | tests/cli/cli_test.go | 20 |
2 files changed, 21 insertions, 1 deletions
diff --git a/init_dir.go b/init_dir.go index 5939598..19fabcf 100644 --- a/init_dir.go +++ b/init_dir.go @@ -63,7 +63,7 @@ func initDir(args *argContainer) { err = isEmptyDir(args.cipherdir) if err != nil { tlog.Fatal.Printf("Invalid cipherdir: %v", err) - os.Exit(exitcodes.Init) + os.Exit(exitcodes.CipherDir) } } // Choose password for config file diff --git a/tests/cli/cli_test.go b/tests/cli/cli_test.go index bb1558c..6aa2feb 100644 --- a/tests/cli/cli_test.go +++ b/tests/cli/cli_test.go @@ -800,3 +800,23 @@ func TestPassfileX2(t *testing.T) { test_helpers.MountOrFatal(t, dir, mnt, "-passfile="+passfile1, "-passfile="+passfile2) defer test_helpers.UnmountPanic(mnt) } + +// TestInitNotEmpty checks that `gocryptfs -init` returns the right error code +// if CIPHERDIR is not empty. See https://github.com/rfjakob/gocryptfs/pull/503 +func TestInitNotEmpty(t *testing.T) { + dir := test_helpers.TmpDir + "/" + t.Name() + if err := os.Mkdir(dir, 0700); err != nil { + t.Fatal(err) + } + if err := ioutil.WriteFile(dir+"/foo", nil, 0700); err != nil { + t.Fatal(err) + } + cmd := exec.Command(test_helpers.GocryptfsBinary, "-init", "-extpass", "echo test", dir) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + err := cmd.Run() + exitCode := test_helpers.ExtractCmdExitCode(err) + if exitCode != exitcodes.CipherDir { + t.Fatalf("wrong exit code: have=%d, want=%d", exitCode, exitcodes.CipherDir) + } +} |