| @@ -360,6 +360,7 @@ func obsCopyFile(srcBucket string, srcKeyName string, destBucket string, destKey | |||
| return nil | |||
| } | |||
| /* | |||
| func GetOneLevelAllObjectUnderDir(bucket string, prefixRootPath string, relativePath string) ([]FileInfo, error) { | |||
| input := &obs.ListObjectsInput{} | |||
| input.Bucket = bucket | |||
| @@ -414,6 +415,71 @@ func GetOneLevelAllObjectUnderDir(bucket string, prefixRootPath string, relative | |||
| } | |||
| */ | |||
| func GetOneLevelAllObjectUnderDir(bucket string, prefixRootPath string, relativePath string) ([]FileInfo, error) { | |||
| input := &obs.ListObjectsInput{} | |||
| input.Bucket = bucket | |||
| input.Prefix = prefixRootPath + relativePath | |||
| if !strings.HasSuffix(input.Prefix, "/") { | |||
| input.Prefix += "/" | |||
| } | |||
| fileInfos := make([]FileInfo, 0) | |||
| prefixLen := len(input.Prefix) | |||
| fileMap := make(map[string]bool, 0) | |||
| index := 1 | |||
| for { | |||
| output, err := ObsCli.ListObjects(input) | |||
| if err == nil { | |||
| log.Info("Page:%d\n", index) | |||
| index++ | |||
| for _, val := range output.Contents { | |||
| log.Info("val key=" + val.Key) | |||
| var isDir bool | |||
| var fileName string | |||
| if val.Key == input.Prefix { | |||
| continue | |||
| } | |||
| fileName = val.Key[prefixLen:] | |||
| //log.Info("fileName =" + fileName) | |||
| files := strings.Split(fileName, "/") | |||
| if fileMap[files[0]] { | |||
| continue | |||
| } else { | |||
| fileMap[files[0]] = true | |||
| } | |||
| ParenDir := relativePath | |||
| fileName = files[0] | |||
| if len(files) > 1 { | |||
| isDir = true | |||
| ParenDir += fileName + "/" | |||
| } else { | |||
| isDir = false | |||
| } | |||
| fileInfo := FileInfo{ | |||
| ModTime: val.LastModified.Local().Format("2006-01-02 15:04:05"), | |||
| FileName: fileName, | |||
| Size: val.Size, | |||
| IsDir: isDir, | |||
| ParenDir: ParenDir, | |||
| } | |||
| fileInfos = append(fileInfos, fileInfo) | |||
| } | |||
| if output.IsTruncated { | |||
| input.Marker = output.NextMarker | |||
| } else { | |||
| break | |||
| } | |||
| } else { | |||
| if obsError, ok := err.(obs.ObsError); ok { | |||
| log.Error("Code:%s, Message:%s", obsError.Code, obsError.Message) | |||
| } | |||
| return nil, err | |||
| } | |||
| } | |||
| return fileInfos, nil | |||
| } | |||
| func GetAllObjectByBucketAndPrefix(bucket string, prefix string) ([]FileInfo, error) { | |||
| input := &obs.ListObjectsInput{} | |||
| input.Bucket = bucket | |||