mirror of
https://github.com/rclone/rclone.git
synced 2024-11-29 12:04:11 +08:00
Delete many files at once with purge
This commit is contained in:
parent
a5ecd66388
commit
720d44f8e9
26
swiftsync.go
26
swiftsync.go
|
@ -457,8 +457,6 @@ func rmdir(c *swift.Connection, args []string) {
|
||||||
|
|
||||||
// Removes a container and all of its contents
|
// Removes a container and all of its contents
|
||||||
//
|
//
|
||||||
// FIXME should delete many at once
|
|
||||||
//
|
|
||||||
// FIXME should make FsObjects and use debugging
|
// FIXME should make FsObjects and use debugging
|
||||||
func purge(c *swift.Connection, args []string) {
|
func purge(c *swift.Connection, args []string) {
|
||||||
container := args[0]
|
container := args[0]
|
||||||
|
@ -467,15 +465,33 @@ func purge(c *swift.Connection, args []string) {
|
||||||
log.Fatalf("Couldn't read container %q: %s", container, err)
|
log.Fatalf("Couldn't read container %q: %s", container, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range objects {
|
to_be_deleted := make(chan *swift.Object, *transfers)
|
||||||
object := &objects[i]
|
|
||||||
err = c.ObjectDelete(container, object.Name)
|
var wg sync.WaitGroup
|
||||||
|
wg.Add(*transfers)
|
||||||
|
for i := 0; i < *transfers; i++ {
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
for object := range to_be_deleted {
|
||||||
|
err := c.ObjectDelete(container, object.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s: Couldn't delete: %s\n", object.Name, err)
|
log.Printf("%s: Couldn't delete: %s\n", object.Name, err)
|
||||||
} else {
|
} else {
|
||||||
log.Printf("%s: Deleted\n", object.Name)
|
log.Printf("%s: Deleted\n", object.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := range objects {
|
||||||
|
to_be_deleted <- &objects[i]
|
||||||
|
}
|
||||||
|
close(to_be_deleted)
|
||||||
|
|
||||||
|
log.Printf("Waiting for deletions to finish")
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
|
log.Printf("Deleting container")
|
||||||
rmdir(c, args)
|
rmdir(c, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user