posix: ReadAll should handle the case when parent is not a dir. (#2163)

It can happen so that a read request can come for a file which
already has a parent i.e a file.

This fix handles this scenario - fixes #2047
master
Harshavardhana 8 years ago committed by Anand Babu (AB) Periasamy
parent d676e660c9
commit de468f92ec
  1. 7
      posix.go
  2. 11
      posix_test.go
  3. 1
      xl-v1-metadata.go

@ -424,12 +424,15 @@ func (s *posix) ReadAll(volume, path string) (buf []byte, err error) {
} else if os.IsPermission(err) { } else if os.IsPermission(err) {
return nil, errFileAccessDenied return nil, errFileAccessDenied
} else if pathErr, ok := err.(*os.PathError); ok { } else if pathErr, ok := err.(*os.PathError); ok {
if pathErr.Err == syscall.EISDIR { switch pathErr.Err {
case syscall.ENOTDIR, syscall.EISDIR:
return nil, errFileNotFound return nil, errFileNotFound
} else if strings.Contains(pathErr.Err.Error(), "The handle is invalid") { default:
if strings.Contains(pathErr.Err.Error(), "The handle is invalid") {
// This case is special and needs to be handled for windows. // This case is special and needs to be handled for windows.
return nil, errFileNotFound return nil, errFileNotFound
} }
}
return nil, pathErr return nil, pathErr
} }
return nil, err return nil, err

@ -73,6 +73,9 @@ func TestReadAll(t *testing.T) {
if err = posix.AppendFile("exists", "as-file", []byte("Hello, World")); err != nil { if err = posix.AppendFile("exists", "as-file", []byte("Hello, World")); err != nil {
t.Fatalf("Unable to create a file \"as-file\", %s", err) t.Fatalf("Unable to create a file \"as-file\", %s", err)
} }
if err = posix.AppendFile("exists", "as-file-parent", []byte("Hello, World")); err != nil {
t.Fatalf("Unable to create a file \"as-file-parent\", %s", err)
}
// Testcases to validate different conditions for ReadAll API. // Testcases to validate different conditions for ReadAll API.
testCases := []struct { testCases := []struct {
@ -99,8 +102,12 @@ func TestReadAll(t *testing.T) {
"as-directory", "as-directory",
errFileNotFound, errFileNotFound,
}, },
// Validate the good condition file exists and we are able to {
// read it. "exists",
"as-file-parent/as-file",
errFileNotFound,
},
// Validate the good condition file exists and we are able to read it.
{ {
"exists", "exists",
"as-file", "as-file",

@ -203,6 +203,7 @@ var objMetadataOpIgnoredErrs = []error{
errDiskAccessDenied, errDiskAccessDenied,
errFaultyDisk, errFaultyDisk,
errVolumeNotFound, errVolumeNotFound,
errFileAccessDenied,
} }
// readXLMetadata - returns the object metadata `xl.json` content from // readXLMetadata - returns the object metadata `xl.json` content from

Loading…
Cancel
Save