From 60018d614897fb79a5221e5ae090911c767d76ab Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Sat, 17 Nov 2018 03:17:07 +0400 Subject: [PATCH] comment out until someone decides to tackle #2285 (#2760) current code results in panic and we certainly don't want that. https://github.com/tendermint/tendermint/pull/2286#issuecomment-418281846 --- libs/autofile/autofile.go | 15 +++++----- libs/autofile/autofile_test.go | 55 +++++++++++++++++----------------- libs/db/fsdb.go | 15 +++++----- libs/errors/errors.go | 37 ++++++++++------------- 4 files changed, 57 insertions(+), 65 deletions(-) diff --git a/libs/autofile/autofile.go b/libs/autofile/autofile.go index a1e2f49e6..e428e26c5 100644 --- a/libs/autofile/autofile.go +++ b/libs/autofile/autofile.go @@ -8,7 +8,6 @@ import ( "time" cmn "github.com/tendermint/tendermint/libs/common" - "github.com/tendermint/tendermint/libs/errors" ) /* AutoFile usage @@ -157,13 +156,13 @@ func (af *AutoFile) openFile() error { if err != nil { return err } - fileInfo, err := file.Stat() - if err != nil { - return err - } - if fileInfo.Mode() != autoFilePerms { - return errors.NewErrPermissionsChanged(file.Name(), fileInfo.Mode(), autoFilePerms) - } + // fileInfo, err := file.Stat() + // if err != nil { + // return err + // } + // if fileInfo.Mode() != autoFilePerms { + // return errors.NewErrPermissionsChanged(file.Name(), fileInfo.Mode(), autoFilePerms) + // } af.file = file return nil } diff --git a/libs/autofile/autofile_test.go b/libs/autofile/autofile_test.go index 0b3521c2a..9903f1e68 100644 --- a/libs/autofile/autofile_test.go +++ b/libs/autofile/autofile_test.go @@ -10,7 +10,6 @@ import ( "github.com/stretchr/testify/require" cmn "github.com/tendermint/tendermint/libs/common" - "github.com/tendermint/tendermint/libs/errors" ) func TestSIGHUP(t *testing.T) { @@ -58,32 +57,32 @@ func TestSIGHUP(t *testing.T) { } } -// Manually modify file permissions, close, and reopen using autofile: -// We expect the file permissions to be changed back to the intended perms. -func TestOpenAutoFilePerms(t *testing.T) { - file, err := ioutil.TempFile("", "permission_test") - require.NoError(t, err) - err = file.Close() - require.NoError(t, err) - name := file.Name() - - // open and change permissions - af, err := OpenAutoFile(name) - require.NoError(t, err) - err = af.file.Chmod(0755) - require.NoError(t, err) - err = af.Close() - require.NoError(t, err) - - // reopen and expect an ErrPermissionsChanged as Cause - af, err = OpenAutoFile(name) - require.Error(t, err) - if e, ok := err.(*errors.ErrPermissionsChanged); ok { - t.Logf("%v", e) - } else { - t.Errorf("unexpected error %v", e) - } -} +// // Manually modify file permissions, close, and reopen using autofile: +// // We expect the file permissions to be changed back to the intended perms. +// func TestOpenAutoFilePerms(t *testing.T) { +// file, err := ioutil.TempFile("", "permission_test") +// require.NoError(t, err) +// err = file.Close() +// require.NoError(t, err) +// name := file.Name() + +// // open and change permissions +// af, err := OpenAutoFile(name) +// require.NoError(t, err) +// err = af.file.Chmod(0755) +// require.NoError(t, err) +// err = af.Close() +// require.NoError(t, err) + +// // reopen and expect an ErrPermissionsChanged as Cause +// af, err = OpenAutoFile(name) +// require.Error(t, err) +// if e, ok := err.(*errors.ErrPermissionsChanged); ok { +// t.Logf("%v", e) +// } else { +// t.Errorf("unexpected error %v", e) +// } +// } func TestAutoFileSize(t *testing.T) { // First, create an AutoFile writing to a tempfile dir @@ -120,4 +119,4 @@ func TestAutoFileSize(t *testing.T) { // Cleanup _ = os.Remove(f.Name()) -} +} \ No newline at end of file diff --git a/libs/db/fsdb.go b/libs/db/fsdb.go index 92c059d42..b1d40c7b4 100644 --- a/libs/db/fsdb.go +++ b/libs/db/fsdb.go @@ -12,7 +12,6 @@ import ( "github.com/pkg/errors" cmn "github.com/tendermint/tendermint/libs/common" - tmerrors "github.com/tendermint/tendermint/libs/errors" ) const ( @@ -207,13 +206,13 @@ func write(path string, d []byte) error { return err } defer f.Close() - fInfo, err := f.Stat() - if err != nil { - return err - } - if fInfo.Mode() != keyPerm { - return tmerrors.NewErrPermissionsChanged(f.Name(), keyPerm, fInfo.Mode()) - } + // fInfo, err := f.Stat() + // if err != nil { + // return err + // } + // if fInfo.Mode() != keyPerm { + // return tmerrors.NewErrPermissionsChanged(f.Name(), keyPerm, fInfo.Mode()) + // } _, err = f.Write(d) if err != nil { return err diff --git a/libs/errors/errors.go b/libs/errors/errors.go index ae5d94392..a03382780 100644 --- a/libs/errors/errors.go +++ b/libs/errors/errors.go @@ -1,26 +1,21 @@ // Package errors contains errors that are thrown across packages. package errors -import ( - "fmt" - "os" -) +// // ErrPermissionsChanged occurs if the file permission have changed since the file was created. +// type ErrPermissionsChanged struct { +// name string +// got, want os.FileMode +// } -// ErrPermissionsChanged occurs if the file permission have changed since the file was created. -type ErrPermissionsChanged struct { - name string - got, want os.FileMode -} +// func NewErrPermissionsChanged(name string, got, want os.FileMode) *ErrPermissionsChanged { +// return &ErrPermissionsChanged{name: name, got: got, want: want} +// } -func NewErrPermissionsChanged(name string, got, want os.FileMode) *ErrPermissionsChanged { - return &ErrPermissionsChanged{name: name, got: got, want: want} -} - -func (e ErrPermissionsChanged) Error() string { - return fmt.Sprintf( - "file: [%v]\nexpected file permissions: %v, got: %v", - e.name, - e.want, - e.got, - ) -} +// func (e ErrPermissionsChanged) Error() string { +// return fmt.Sprintf( +// "file: [%v]\nexpected file permissions: %v, got: %v", +// e.name, +// e.want, +// e.got, +// ) +// }