Пример #1
0
func (cache *cacheDriver) listObjects(keys []string, key string, r drivers.BucketResourcesMetadata) ([]string, drivers.BucketResourcesMetadata) {
	switch true {
	// Prefix absent, delimit object key based on delimiter
	case r.IsDelimiterSet():
		delim := delimiter(key, r.Delimiter)
		switch true {
		case delim == "" || delim == key:
			keys = appendUniq(keys, key)
		case delim != "":
			r.CommonPrefixes = appendUniq(r.CommonPrefixes, delim)
		}
	// Prefix present, delimit object key with prefix key based on delimiter
	case r.IsDelimiterPrefixSet():
		if strings.HasPrefix(key, r.Prefix) {
			trimmedName := strings.TrimPrefix(key, r.Prefix)
			delim := delimiter(trimmedName, r.Delimiter)
			keys, r = cache.filterDelimiterPrefix(keys, key, delim, r)
		}
	// Prefix present, nothing to delimit
	case r.IsPrefixSet():
		keys = appendUniq(keys, key)
	// Prefix and delimiter absent
	case r.IsDefault():
		keys = appendUniq(keys, key)
	}
	return keys, r
}
Пример #2
0
func (fs *fsDriver) filterObjects(bucket, name string, file os.FileInfo, resources drivers.BucketResourcesMetadata) (drivers.ObjectMetadata, drivers.BucketResourcesMetadata, error) {
	var err error
	var metadata drivers.ObjectMetadata

	switch true {
	// Both delimiter and Prefix is present
	case resources.IsDelimiterPrefixSet():
		if strings.HasPrefix(name, resources.Prefix) {
			trimmedName := strings.TrimPrefix(name, resources.Prefix)
			delimitedName := delimiter(trimmedName, resources.Delimiter)
			switch true {
			case name == resources.Prefix:
				// Use resources.Prefix to filter out delimited files
				metadata, err = fs.GetObjectMetadata(bucket, name)
				if err != nil {
					return drivers.ObjectMetadata{}, resources, iodine.New(err, nil)
				}
			case delimitedName == file.Name():
				// Use resources.Prefix to filter out delimited files
				metadata, err = fs.GetObjectMetadata(bucket, name)
				if err != nil {
					return drivers.ObjectMetadata{}, resources, iodine.New(err, nil)
				}
			case delimitedName != "":
				resources.CommonPrefixes = appendUniq(resources.CommonPrefixes, resources.Prefix+delimitedName)
			}
		}
	// Delimiter present and Prefix is absent
	case resources.IsDelimiterSet():
		delimitedName := delimiter(name, resources.Delimiter)
		switch true {
		case delimitedName == "":
			metadata, err = fs.GetObjectMetadata(bucket, name)
			if err != nil {
				return drivers.ObjectMetadata{}, resources, iodine.New(err, nil)
			}
		case delimitedName == file.Name():
			metadata, err = fs.GetObjectMetadata(bucket, name)
			if err != nil {
				return drivers.ObjectMetadata{}, resources, iodine.New(err, nil)
			}
		case delimitedName != "":
			resources.CommonPrefixes = appendUniq(resources.CommonPrefixes, delimitedName)
		}
	// Delimiter is absent and only Prefix is present
	case resources.IsPrefixSet():
		if strings.HasPrefix(name, resources.Prefix) {
			// Do not strip prefix object output
			metadata, err = fs.GetObjectMetadata(bucket, name)
			if err != nil {
				return drivers.ObjectMetadata{}, resources, iodine.New(err, nil)
			}
		}
	case resources.IsDefault():
		metadata, err = fs.GetObjectMetadata(bucket, name)
		if err != nil {
			return drivers.ObjectMetadata{}, resources, iodine.New(err, nil)
		}
	}

	return metadata, resources, nil
}