|
@@ -7,88 +7,88 @@ import (
|
|
|
"testing"
|
|
|
)
|
|
|
|
|
|
-
|
|
|
-func TestDeleteExceptCallback(t *testing.T) {
|
|
|
-
|
|
|
- endpoint := "http://pji-bucket1.oss.icvdc.com"
|
|
|
- accessKeyID := "n8glvFGS25MrLY7j"
|
|
|
- accessKeySecret := "xZ2Fozoarpfw0z28FUhtg8cu0yDc5d"
|
|
|
- bucketName := "pji-bucket1"
|
|
|
-
|
|
|
-
|
|
|
- client, err := oss.New(endpoint, accessKeyID, accessKeySecret, oss.UseCname(true))
|
|
|
- if err != nil {
|
|
|
- fmt.Printf("Failed to create OSS client: %v\n", err)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- bucket, err := client.Bucket(bucketName)
|
|
|
- if err != nil {
|
|
|
- fmt.Printf("Failed to get bucket: %v\n", err)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- directories := []string{
|
|
|
- "pjibot_patrol/pjibot-P1YVXJ1M231M00022/data_parse",
|
|
|
- "pjibot_patrol/pjibot-P1YVXJ1M231M00023/data_parse",
|
|
|
- }
|
|
|
-
|
|
|
- for _, dir := range directories {
|
|
|
-
|
|
|
- marker := ""
|
|
|
- for {
|
|
|
- lsRes, err := bucket.ListObjects(oss.Prefix(dir), oss.Marker(marker))
|
|
|
- if err != nil {
|
|
|
- fmt.Printf("Failed to list objects in directory %s: %v\n", dir, err)
|
|
|
- break
|
|
|
- }
|
|
|
-
|
|
|
- for _, object := range lsRes.Objects {
|
|
|
- objectKey := object.Key
|
|
|
-
|
|
|
-
|
|
|
- if !strings.Contains(objectKey, "callback") {
|
|
|
- err := bucket.DeleteObject(objectKey)
|
|
|
- if err != nil {
|
|
|
- fmt.Printf("Failed to delete object %s: %v\n", objectKey, err)
|
|
|
- } else {
|
|
|
- fmt.Printf("Deleted object: %s\n", objectKey)
|
|
|
- }
|
|
|
- continue
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if strings.Contains(objectKey, "callback_done") {
|
|
|
- newKey := strings.Replace(objectKey, "callback_done", "callback", 1)
|
|
|
- err, _ = bucket.CopyObject(objectKey, newKey)
|
|
|
- if err != nil {
|
|
|
- fmt.Printf("Failed to copy object %s to %s: %v\n", objectKey, newKey, err)
|
|
|
- err = bucket.DeleteObject(objectKey)
|
|
|
- } else {
|
|
|
- err = bucket.DeleteObject(objectKey)
|
|
|
- if err != nil {
|
|
|
- fmt.Printf("Failed to delete original object %s after renaming: %v\n", objectKey, err)
|
|
|
- } else {
|
|
|
- fmt.Printf("Renamed object: %s to %s\n", objectKey, newKey)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if !lsRes.IsTruncated {
|
|
|
- break
|
|
|
- }
|
|
|
- marker = lsRes.NextMarker
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
func TestDeleteAllTrajectoryPjiCsv(t *testing.T) {
|