Allow copy for virtual files

This commit is contained in:
Harshavardhana
2015-07-18 16:30:36 -07:00
parent 41c4f932f3
commit 38149f5ba1
5 changed files with 22 additions and 9 deletions
+5 -2
View File
@@ -91,12 +91,15 @@ func doCatCmd(sourceURL string) (string, error) {
if err != nil {
return "Unable to create client: " + sourceURL, NewIodine(iodine.New(err, nil))
}
reader, size, err := sourceClnt.GetObject(0, 0)
// ignore size, since os.Stat() would not return proper size all the time for local filesystem
// for example /proc files.
reader, _, err := sourceClnt.GetObject(0, 0)
if err != nil {
return "Unable to retrieve file: " + sourceURL, NewIodine(iodine.New(err, nil))
}
defer reader.Close()
_, err = io.CopyN(os.Stdout, reader, int64(size))
// read till EOF
_, err = io.Copy(os.Stdout, reader)
if err != nil {
switch e := iodine.ToError(err).(type) {
case *os.PathError:
+1 -1
View File
@@ -28,8 +28,8 @@ import (
"net/http/httptest"
. "gopkg.in/check.v1"
"github.com/minio/mc/pkg/quick"
. "gopkg.in/check.v1"
)
var customConfigDir string
+2 -2
View File
@@ -79,11 +79,11 @@ func doList(clnt client.Client, recursive bool) error {
switch err := iodine.ToError(contentCh.Err).(type) {
// handle this specifically for filesystem
case client.ISBrokenSymlink:
console.Errorf(err.Error())
console.Errorln(NewIodine(iodine.New(err, nil)).Error())
continue
}
if os.IsNotExist(iodine.ToError(contentCh.Err)) || os.IsPermission(iodine.ToError(contentCh.Err)) {
console.Errorf(contentCh.Err.Error())
console.Errorln(NewIodine(iodine.New(contentCh.Err, nil)).Error())
continue
}
err = contentCh.Err
+13 -3
View File
@@ -94,9 +94,19 @@ func (f *fsClient) PutObject(size int64, data io.Reader) error {
}
defer fs.Close()
_, err = io.CopyN(fs, data, int64(size))
if err != nil {
return iodine.New(err, nil)
// even if size is zero try to read from source
if size > 0 {
_, err = io.CopyN(fs, data, int64(size))
if err != nil {
return iodine.New(err, nil)
}
} else {
// size could be 0 for virtual files on certain filesystems
// for example /proc, so read till EOF for such files
_, err = io.Copy(fs, data)
if err != nil {
return iodine.New(err, nil)
}
}
return nil
}
+1 -1
View File
@@ -24,8 +24,8 @@ import (
"path/filepath"
"testing"
. "gopkg.in/check.v1"
"github.com/minio/mc/pkg/client"
. "gopkg.in/check.v1"
)
func Test(t *testing.T) { TestingT(t) }