From f6463dec1f89ad858431ab0c48770a8146cfe7a3 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Thu, 16 Apr 2015 17:31:05 -0700 Subject: [PATCH] Implement GetPartial() for fsClient, and renamed files `_unix.go` as we bring in windows specific support --- buildscripts/checkdeps.sh | 2 +- pkg/client/fs/{fs_put.go => fs_put_unix.go} | 0 pkg/client/fs/{fs.go => fs_unix.go} | 21 ++++++++++++++++++--- pkg/client/s3/{s3-verify.go => s3verify.go} | 0 4 files changed, 19 insertions(+), 4 deletions(-) rename pkg/client/fs/{fs_put.go => fs_put_unix.go} (100%) rename pkg/client/fs/{fs.go => fs_unix.go} (87%) rename pkg/client/s3/{s3-verify.go => s3verify.go} (100%) diff --git a/buildscripts/checkdeps.sh b/buildscripts/checkdeps.sh index 8ef178bb..ef59bda4 100755 --- a/buildscripts/checkdeps.sh +++ b/buildscripts/checkdeps.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # -# Minio Commander, (C) 2015 Minio, Inc. +# Modern Copy, (C) 2015 Minio, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/pkg/client/fs/fs_put.go b/pkg/client/fs/fs_put_unix.go similarity index 100% rename from pkg/client/fs/fs_put.go rename to pkg/client/fs/fs_put_unix.go diff --git a/pkg/client/fs/fs.go b/pkg/client/fs/fs_unix.go similarity index 87% rename from pkg/client/fs/fs.go rename to pkg/client/fs/fs_unix.go index ba4b73eb..24db05be 100644 --- a/pkg/client/fs/fs.go +++ b/pkg/client/fs/fs_unix.go @@ -79,11 +79,26 @@ func (f *fsClient) Get(bucket, object string) (body io.ReadCloser, size int64, m } // GetPartial - download a partial object from bucket -func (f *fsClient) GetPartial(bucket, key string, offset, length int64) (body io.ReadCloser, size int64, md5 string, err error) { +func (f *fsClient) GetPartial(bucket, object string, offset, length int64) (body io.ReadCloser, size int64, md5 string, err error) { if offset < 0 { return nil, 0, "", iodine.New(client.InvalidRange{Offset: offset}, nil) } - return nil, 0, "", iodine.New(client.APINotImplemented{API: "GetPartial"}, nil) + objectPath, st, err := isValidObject(bucket, object) + if err != nil { + return nil, 0, "", iodine.New(err, nil) + } + body, err = os.Open(objectPath) + if err != nil { + return nil, 0, "", iodine.New(err, nil) + } + if offset > st.Size() || (offset+length-1) > st.Size() { + return nil, 0, "", iodine.New(client.InvalidRange{Offset: offset}, nil) + } + _, err = io.CopyN(ioutil.Discard, body, offset) + if err != nil { + return nil, 0, "", iodine.New(err, nil) + } + return body, length, "", nil } // StatObject - @@ -99,7 +114,7 @@ func (f *fsClient) GetObjectMetadata(bucket, object string) (item *client.Item, item.Key = object item.Size = st.Size() item.LastModified = st.ModTime() - item.ETag = "" // TODO + item.ETag = "" // TODO, doesn't exist yet return item, nil } diff --git a/pkg/client/s3/s3-verify.go b/pkg/client/s3/s3verify.go similarity index 100% rename from pkg/client/s3/s3-verify.go rename to pkg/client/s3/s3verify.go