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