|
|
|
@@ -239,6 +239,39 @@ func ObsCopyFile(srcBucket string, srcKeyName string, destBucket string, destKey |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
func GetAllObsListObjectUnderDir(bucket string, prefix string) ([]FileInfo, error) { |
|
|
|
input := &obs.ListObjectsInput{} |
|
|
|
input.Bucket = bucket |
|
|
|
input.Prefix = prefix |
|
|
|
output, err := ObsCli.ListObjects(input) |
|
|
|
fileInfos := make([]FileInfo, 0) |
|
|
|
if err == nil { |
|
|
|
for _, val := range output.Contents { |
|
|
|
var isDir bool |
|
|
|
if strings.HasSuffix(val.Key, "/") { |
|
|
|
continue |
|
|
|
} else { |
|
|
|
isDir = false |
|
|
|
} |
|
|
|
fileInfo := FileInfo{ |
|
|
|
ModTime: val.LastModified.Format("2006-01-02 15:04:05"), |
|
|
|
FileName: val.Key[len(prefix):], |
|
|
|
Size: val.Size, |
|
|
|
IsDir: isDir, |
|
|
|
ParenDir: "", |
|
|
|
} |
|
|
|
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 |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func GetObsListObjectByBucketAndPrefix(bucket string, prefix string) ([]FileInfo, error) { |
|
|
|
input := &obs.ListObjectsInput{} |
|
|
|
input.Bucket = bucket |
|
|
|
@@ -246,17 +279,18 @@ func GetObsListObjectByBucketAndPrefix(bucket string, prefix string) ([]FileInfo |
|
|
|
output, err := ObsCli.ListObjects(input) |
|
|
|
fileInfos := make([]FileInfo, 0) |
|
|
|
if err == nil { |
|
|
|
var nextParentDir string |
|
|
|
for _, val := range output.Contents { |
|
|
|
str1 := strings.Split(val.Key, "/") |
|
|
|
var isDir bool |
|
|
|
var fileName, nextParentDir string |
|
|
|
var fileName string |
|
|
|
if strings.HasSuffix(val.Key, "/") { |
|
|
|
fileName = str1[len(str1)-2] |
|
|
|
isDir = true |
|
|
|
nextParentDir = fileName |
|
|
|
if (fileName + "/") == setting.OutPutPath { |
|
|
|
if prefix == val.Key { |
|
|
|
continue |
|
|
|
} |
|
|
|
fileName = str1[len(str1)-2] |
|
|
|
isDir = true |
|
|
|
nextParentDir = nextParentDir + fileName + "/" |
|
|
|
} else { |
|
|
|
fileName = str1[len(str1)-1] |
|
|
|
isDir = false |
|
|
|
@@ -292,12 +326,10 @@ func GetObsListObject(jobName, parentDir string) ([]FileInfo, error) { |
|
|
|
str1 := strings.Split(val.Key, "/") |
|
|
|
var isDir bool |
|
|
|
var fileName, nextParentDir string |
|
|
|
log.Info("val.Key=" + val.Key) |
|
|
|
if strings.HasSuffix(val.Key, "/") { |
|
|
|
fileName = str1[len(str1)-2] |
|
|
|
isDir = true |
|
|
|
nextParentDir = fileName |
|
|
|
log.Info("nextParentDir1=" + nextParentDir) |
|
|
|
if fileName == parentDir || (fileName+"/") == setting.OutPutPath { |
|
|
|
continue |
|
|
|
} |
|
|
|
@@ -305,7 +337,6 @@ func GetObsListObject(jobName, parentDir string) ([]FileInfo, error) { |
|
|
|
fileName = str1[len(str1)-1] |
|
|
|
isDir = false |
|
|
|
} |
|
|
|
log.Info("nextParentDir2=" + nextParentDir) |
|
|
|
fileInfo := FileInfo{ |
|
|
|
ModTime: val.LastModified.Format("2006-01-02 15:04:05"), |
|
|
|
FileName: fileName, |
|
|
|
|