Ejemplo n.º 1
0
Archivo: b2.go Proyecto: ncw/rclone
// readMetaData gets the metadata if it hasn't already been fetched
//
// Sets
//  o.id
//  o.modTime
//  o.size
//  o.sha1
func (o *Object) readMetaData() (err error) {
	if o.id != "" {
		return nil
	}
	maxSearched := 1
	var timestamp api.Timestamp
	baseRemote := o.remote
	if *b2Versions {
		timestamp, baseRemote = api.RemoveVersion(baseRemote)
		maxSearched = maxVersions
	}
	var info *api.File
	err = o.fs.list("", fs.MaxLevel, baseRemote, maxSearched, *b2Versions, func(remote string, object *api.File, isDirectory bool) error {
		if isDirectory {
			return nil
		}
		if remote == baseRemote {
			if !timestamp.IsZero() && !timestamp.Equal(object.UploadTimestamp) {
				return nil
			}
			info = object
		}
		return errEndList // read only 1 item
	})
	if err != nil {
		if err == fs.ErrorDirNotFound {
			return fs.ErrorObjectNotFound
		}
		return err
	}
	if info == nil {
		return fs.ErrorObjectNotFound
	}
	return o.decodeMetaData(info)
}
Ejemplo n.º 2
0
func TestTimestampRemoveVersion(t *testing.T) {
	for _, test := range []struct {
		in             string
		expectedT      api.Timestamp
		expectedRemote string
	}{
		{"potato.txt", emptyT, "potato.txt"},
		{"potato-v1970-01-01-010101-123.txt", t0r, "potato.txt"},
		{"potato-v2001-02-03-040506-123", t1, "potato"},
		{"-v2001-02-03-040506-123", t1, ""},
		{"potato-v2A01-02-03-040506-123", emptyT, "potato-v2A01-02-03-040506-123"},
		{"potato-v2001-02-03-040506=123", emptyT, "potato-v2001-02-03-040506=123"},
	} {
		actualT, actualRemote := api.RemoveVersion(test.in)
		assert.Equal(t, test.expectedT, actualT, test.in)
		assert.Equal(t, test.expectedRemote, actualRemote, test.in)
	}
}