Merge pull request #330 from harshavardhana/pr_out_return_error_during_joinfiles_back_to_the_caller_for_inspection
This commit is contained in:
commit
d92a179cbc
2 changed files with 12 additions and 6 deletions
|
@ -103,11 +103,12 @@ func splitStreamGoRoutine(reader io.Reader, chunkSize uint64, ch chan Message) {
|
|||
// fmt.Println(buf)
|
||||
// }
|
||||
//
|
||||
func JoinFiles(dirname string, inputPrefix string) io.Reader {
|
||||
func JoinFiles(dirname string, inputPrefix string) (io.Reader, error) {
|
||||
reader, writer := io.Pipe()
|
||||
fileInfos, readError := ioutil.ReadDir(dirname)
|
||||
if readError != nil {
|
||||
writer.CloseWithError(readError)
|
||||
return nil, readError
|
||||
}
|
||||
|
||||
var newfileInfos []os.FileInfo
|
||||
|
@ -118,11 +119,13 @@ func JoinFiles(dirname string, inputPrefix string) io.Reader {
|
|||
}
|
||||
|
||||
if len(newfileInfos) == 0 {
|
||||
writer.CloseWithError(errors.New("no files found for given prefix"))
|
||||
nofilesError := errors.New("no files found for given prefix " + inputPrefix)
|
||||
writer.CloseWithError(nofilesError)
|
||||
return nil, nofilesError
|
||||
}
|
||||
|
||||
go joinFilesGoRoutine(newfileInfos, writer)
|
||||
return reader
|
||||
return reader, nil
|
||||
}
|
||||
|
||||
func joinFilesGoRoutine(fileInfos []os.FileInfo, writer *io.PipeWriter) {
|
||||
|
|
|
@ -60,10 +60,13 @@ func (s *MySuite) TestFileSplitJoin(c *C) {
|
|||
|
||||
devnull, err := os.OpenFile(os.DevNull, 2, os.ModeAppend)
|
||||
defer devnull.Close()
|
||||
reader := split.JoinFiles(".", "ERROR")
|
||||
_, err = io.Copy(devnull, reader)
|
||||
|
||||
var reader io.Reader
|
||||
reader, err = split.JoinFiles(".", "ERROR")
|
||||
c.Assert(err, Not(IsNil))
|
||||
reader = split.JoinFiles(".", "TESTPREFIX")
|
||||
|
||||
reader, err = split.JoinFiles(".", "TESTPREFIX")
|
||||
c.Assert(err, IsNil)
|
||||
_, err = io.Copy(devnull, reader)
|
||||
c.Assert(err, IsNil)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue