+ var bytesDeleted, bytesInTrash int64
+ var blocksDeleted, blocksInTrash int
+ params := storage.ListBlobsParameters{Include: "metadata"}
+
+ for {
+ resp, err := v.bsClient.ListBlobs(v.ContainerName, params)
+ if err != nil {
+ log.Printf("EmptyTrash: ListBlobs: %v", err)
+ break
+ }
+ for _, b := range resp.Blobs {
+ // Check if the block is expired
+ if b.Metadata["expires_at"] == "" {
+ continue
+ }
+
+ blocksInTrash++
+ bytesInTrash += b.Properties.ContentLength
+
+ expiresAt, err := strconv.ParseInt(b.Metadata["expires_at"], 10, 64)
+ if err != nil {
+ log.Printf("EmptyTrash: ParseInt(%v): %v", b.Metadata["expires_at"], err)
+ continue
+ }
+
+ if expiresAt > time.Now().Unix() {
+ continue
+ }
+
+ err = v.bsClient.DeleteBlob(v.ContainerName, b.Name, map[string]string{
+ "If-Match": b.Properties.Etag,
+ })
+ if err != nil {
+ log.Printf("EmptyTrash: DeleteBlob(%v): %v", b.Name, err)
+ continue
+ }
+ blocksDeleted++
+ bytesDeleted += b.Properties.ContentLength
+ }
+ if resp.NextMarker == "" {
+ break
+ }
+ params.Marker = resp.NextMarker
+ }
+
+ log.Printf("EmptyTrash stats for %v: Deleted %v bytes in %v blocks. Remaining in trash: %v bytes in %v blocks.", v.String(), bytesDeleted, blocksDeleted, bytesInTrash-bytesDeleted, blocksInTrash-blocksDeleted)