func get_objects(c swift.Connection, container string, prefix string) []string {
	opts := new(swift.ObjectsOpts)
	opts.Prefix = prefix
	names, err := c.ObjectNames(container, opts)
	if err != nil {
		panic(err)
	}
	return names
}
Example #2
0
func GetHistory(ren render.Render, r *http.Request, cf *swift.Connection) {
	opts := swift.ObjectsOpts{}
	opts.Prefix = "cfpaste-"
	opts.Limit = 10
	objects, err := cf.ObjectNames("go-cfpaste", &opts)
	pastes := make([]string, 10)
	for i := range objects {
		object, headers, err := cf.Object("go-cfpaste", objects[i])
		PanicIf(err)
		log.Println(object.Name)
		pastes = append(pastes, headers["X-Object-Meta-Pasteid"])
	}
	PanicIf(err)
	ren.HTML(200, "history", pastes)
	return
}
Example #3
0
// listContainerRoot lists the objects into the function supplied from
// the container and root supplied
//
// Level is the level of the recursion
func (f *Fs) listContainerRoot(container, root string, dir string, level int, fn listFn) error {
	prefix := root
	if dir != "" {
		prefix += dir + "/"
	}
	// Options for ObjectsWalk
	opts := swift.ObjectsOpts{
		Prefix: prefix,
		Limit:  256,
	}
	switch level {
	case 1:
		opts.Delimiter = '/'
	case fs.MaxLevel:
	default:
		return fs.ErrorLevelNotSupported
	}
	rootLength := len(root)
	return f.c.ObjectsWalk(container, &opts, func(opts *swift.ObjectsOpts) (interface{}, error) {
		objects, err := f.c.Objects(container, opts)
		if err == nil {
			for i := range objects {
				object := &objects[i]
				isDirectory := false
				if level == 1 {
					if strings.HasSuffix(object.Name, "/") {
						isDirectory = true
						object.Name = object.Name[:len(object.Name)-1]
					}
				}
				if !strings.HasPrefix(object.Name, root) {
					fs.Log(f, "Odd name received %q", object.Name)
					continue
				}
				remote := object.Name[rootLength:]
				err = fn(remote, object, isDirectory)
				if err != nil {
					break
				}
			}
		}
		return objects, err
	})
}
Example #4
0
// list the objects into the function supplied
//
// If directories is set it only sends directories
func (f *FsSwift) list(directories bool, fn func(string, *swift.Object)) {
	// Options for ObjectsWalk
	opts := swift.ObjectsOpts{
		Prefix: f.root,
		Limit:  256,
	}
	if directories {
		opts.Delimiter = '/'
	}
	rootLength := len(f.root)
	err := f.c.ObjectsWalk(f.container, &opts, func(opts *swift.ObjectsOpts) (interface{}, error) {
		objects, err := f.c.Objects(f.container, opts)
		if err == nil {
			for i := range objects {
				object := &objects[i]
				// FIXME if there are no directories, swift gives back the files for some reason!
				if directories {
					if !strings.HasSuffix(object.Name, "/") {
						continue
					}
					object.Name = object.Name[:len(object.Name)-1]
				}
				if !strings.HasPrefix(object.Name, f.root) {
					fs.Log(f, "Odd name received %q", object.Name)
					continue
				}
				remote := object.Name[rootLength:]
				fn(remote, object)
			}
		}
		return objects, err
	})
	if err != nil {
		fs.Stats.Error()
		fs.ErrorLog(f, "Couldn't read container %q: %s", f.container, err)
	}
}
Example #5
0
// listContainerRoot lists the objects into the function supplied from
// the container and root supplied
//
// If directories is set it only sends directories
func (f *Fs) listContainerRoot(container, root string, directories bool, fn listFn) error {
	// Options for ObjectsWalk
	opts := swift.ObjectsOpts{
		Prefix: root,
		Limit:  256,
	}
	if directories {
		opts.Delimiter = '/'
	}
	rootLength := len(root)
	return f.c.ObjectsWalk(container, &opts, func(opts *swift.ObjectsOpts) (interface{}, error) {
		objects, err := f.c.Objects(container, opts)
		if err == nil {
			for i := range objects {
				object := &objects[i]
				// FIXME if there are no directories, swift gives back the files for some reason!
				if directories {
					if !strings.HasSuffix(object.Name, "/") {
						continue
					}
					object.Name = object.Name[:len(object.Name)-1]
				}
				if !strings.HasPrefix(object.Name, root) {
					fs.Log(f, "Odd name received %q", object.Name)
					continue
				}
				remote := object.Name[rootLength:]
				err = fn(remote, object)
				if err != nil {
					break
				}
			}
		}
		return objects, err
	})
}