コード例 #1
0
ファイル: delete.go プロジェクト: satyamkotakonda/rack
func (command *commandDelete) Execute(resource *handler.Resource) {
	params := resource.Params.(*paramsDelete)
	containerName := params.container
	objectName := params.object

	listOpts := osObjects.ListOpts{
		Prefix: objectName,
	}
	allPages, err := osObjects.List(command.Ctx.ServiceClient, containerName, listOpts).AllPages()
	if err != nil {
		resource.Err = err
		return
	}

	objectNames, err := osObjects.ExtractNames(allPages)
	if err != nil {
		resource.Err = err
		return
	}

	for _, thisName := range objectNames {
		rawResponse := osObjects.Delete(command.Ctx.ServiceClient, containerName, thisName, osObjects.DeleteOpts{})
		if rawResponse.Err != nil {
			resource.Err = rawResponse.Err
			return
		}
	}

	resource.Result = fmt.Sprintf("Deleted object [%s] from container [%s]", objectName, containerName)
}
コード例 #2
0
ファイル: common.go プロジェクト: satyamkotakonda/rack
func handleEmpty(command handler.Commander, resource *handler.Resource, params *handleEmptyParams) {
	var totalFiles int64
	var wg sync.WaitGroup

	// bump thread count to number of available CPUs
	runtime.GOMAXPROCS(runtime.NumCPU())

	// get the names of all the objects in the container
	allPages, err := objects.List(command.Context().ServiceClient, params.container, nil).AllPages()
	if err != nil {
		resource.Err = err
		return
	}
	names, err := objects.ExtractNames(allPages)
	if err != nil {
		resource.Err = err
		return
	}

	// send the object names into the `jobs` channel
	jobs := make(chan string, len(names))
	for i := 0; i < len(names); i++ {
		wg.Add(1)
		jobs <- names[i]
	}
	close(jobs)

	// default the number of goroutines to spawn if the `concurrency` flag
	// wasn't provided
	if params.concurrency == 0 {
		params.concurrency = 100
	}

	start := time.Now()

	for i := 0; i < params.concurrency; i++ {
		go func(totalFiles *int64) {
			for objectName := range jobs {
				ticker := backoff.NewTicker(backoff.NewExponentialBackOff())
				for _ = range ticker.C {
					rawResponse := objects.Delete(command.Context().ServiceClient, params.container, objectName, nil)
					if rawResponse.Err != nil {
						continue
					}
					ticker.Stop()
					break
				}

				*totalFiles++

				if !params.quiet {
					re := &handler.Resource{
						Result: fmt.Sprintf("Successfully deleted object [%s] from container [%s]\n", objectName, params.container),
					}
					command.Context().Results <- re
				}
				wg.Done()
			}
		}(&totalFiles)
	}

	wg.Wait()

	resource.Result = fmt.Sprintf("Finished! Deleted %s %s in %s", humanize.Comma(totalFiles), util.Pluralize("object", totalFiles), humanize.RelTime(start, time.Now(), "", ""))
}
コード例 #3
0
ファイル: delegate.go プロジェクト: satyamkotakonda/rack
// List is a function that retrieves objects in the container as
// well as container metadata. It returns a pager which can be iterated with the
// EachPage function.
func List(c *gophercloud.ServiceClient, containerName string, opts os.ListOptsBuilder) pagination.Pager {
	return os.List(c, containerName, opts)
}