aboutsummaryrefslogtreecommitdiff
path: root/object.go
diff options
context:
space:
mode:
Diffstat (limited to 'object.go')
-rw-r--r--object.go37
1 files changed, 27 insertions, 10 deletions
diff --git a/object.go b/object.go
index 55114d6..ee022e3 100644
--- a/object.go
+++ b/object.go
@@ -41,6 +41,11 @@ type Object struct {
symlinkHeaders *ObjectHeaders //from HEAD/GET with ?symlink=get
}
+//IsEqualTo returns true if both Object instances refer to the same object.
+func (o *Object) IsEqualTo(other *Object) bool {
+ return other.name == o.name && other.c.IsEqualTo(o.c)
+}
+
//Object returns a handle to the object with the given name within this
//container. This function does not issue any HTTP requests, and therefore cannot
//ensure that the object exists. Use the Exists() function to check for the
@@ -93,7 +98,7 @@ func (o *Object) Exists() (bool, error) {
//has not been cached yet, a HEAD request is issued on the object.
//
//For symlinks, this operation returns the metadata for the target object. Use
-//Object.InspectSymlink() to obtain the metadata for the symlink instead.
+//Object.SymlinkHeaders() to obtain the metadata for the symlink instead.
//
//This operation fails with http.StatusNotFound if the object does not exist.
func (o *Object) Headers() (ObjectHeaders, error) {
@@ -507,7 +512,7 @@ type SymlinkOptions struct {
func (o *Object) SymlinkTo(target *Object, opts *SymlinkOptions, ropts *RequestOptions) error {
ropts = cloneRequestOptions(ropts, nil)
ropts.Headers.Set("X-Symlink-Target", target.FullName())
- if !target.c.a.isEqualTo(o.c.a) {
+ if !target.c.a.IsEqualTo(o.c.a) {
ropts.Headers.Set("X-Symlink-Target-Account", target.c.a.Name())
}
if ropts.Headers.Get("Content-Type") == "" {
@@ -526,29 +531,41 @@ func (o *Object) SymlinkTo(target *Object, opts *SymlinkOptions, ropts *RequestO
return o.Upload(nil, uopts, ropts)
}
-//InspectSymlink returns the object that this symlink points to, and the
-//metadata of the symlink. ErrNotASymlink is returned if the object is not a
-//symlink.
+//SymlinkHeaders is similar to Headers, but if the object is a symlink, it
+//returns the metadata of the symlink rather than the metadata of the target.
+//It also returns a reference to the target object.
+//
+//If this object is not a symlink, Object.SymlinkHeaders() returns the same
+//ObjectHeaders as Object.Headers(), and a nil target object.
+//
+//In a nutshell, if Object.Headers() is like os.Stat(), then
+//Object.SymlinkHeaders() is like os.Lstat().
+//
+//If you do not know whether a given object is a symlink or not, it's a good
+//idea to call Object.SymlinkHeaders() first: If the object turns out not to be
+//a symlink, the cache for Object.Headers() has already been populated.
//
//This operation fails with http.StatusNotFound if the object does not exist.
-func (o *Object) InspectSymlink() (target *Object, headers ObjectHeaders, err error) {
+func (o *Object) SymlinkHeaders() (headers ObjectHeaders, target *Object, err error) {
if o.symlinkHeaders == nil {
o.symlinkHeaders, err = o.fetchHeaders(&RequestOptions{
Values: url.Values{"symlink": []string{"get"}},
})
if err != nil {
- return nil, ObjectHeaders{}, err
+ return ObjectHeaders{}, nil, err
}
}
//is this a symlink?
targetFullName := o.symlinkHeaders.Get("X-Symlink-Target")
if targetFullName == "" {
- return nil, ObjectHeaders{}, ErrNotASymlink
+ //not a symlink - the o.symlinkHeaders are just the regular headers
+ o.headers = o.symlinkHeaders
+ return *o.headers, nil, nil
}
fields := strings.SplitN(targetFullName, "/", 2)
if len(fields) < 2 {
- return nil, ObjectHeaders{}, MalformedHeaderError{
+ return ObjectHeaders{}, nil, MalformedHeaderError{
Key: "X-Symlink-Target",
ParseError: fmt.Errorf("expected \"container/object\", got \"%s\"", targetFullName),
}
@@ -561,7 +578,7 @@ func (o *Object) InspectSymlink() (target *Object, headers ObjectHeaders, err er
targetAccount = targetAccount.SwitchAccount(accountName)
}
target = targetAccount.Container(fields[0]).Object(fields[1])
- return target, *o.symlinkHeaders, nil
+ return *o.symlinkHeaders, target, nil
}
//URL returns the canonical url for the object in the objectstore