diff --git a/internal/dao/buck_obj.go b/internal/dao/buck_obj.go index 36bb06f..ffe3dd0 100644 --- a/internal/dao/buck_obj.go +++ b/internal/dao/buck_obj.go @@ -29,12 +29,12 @@ func (bo *BObj) List(ctx context.Context) ([]Object, error) { bucketInfo := aws.GetInfoAboutBucket(*sess, bucketName, "/", fn) folderArrayInfo, fileArrayInfo := getBucLevelInfo(bucketInfo) var s3Objects []aws.S3Object - if len(folderArrayInfo) != 0 || len(fileArrayInfo) != 0 { - s3Objects = setFoldersAndFiles(bucketInfo.CommonPrefixes, bucketInfo.Contents) - } else { + if len(folderArrayInfo) == 0 && len(fileArrayInfo) == 0 { s3Objects = append(s3Objects, aws.S3Object{ Name: "No objects found", }) + } else { + s3Objects = setFoldersAndFiles(bucketInfo.CommonPrefixes, bucketInfo.Contents) } objs := make([]Object, len(s3Objects)) for i, obj := range s3Objects { @@ -62,33 +62,37 @@ func getBucLevelInfo(bucketInfo *s3.ListObjectsV2Output) ([]string, []string) { return folderArrayInfo, fileArrayInfo } -func setFoldersAndFiles(Folder []*s3.CommonPrefix, File []*s3.Object) []aws.S3Object { +func setFoldersAndFiles(folders []*s3.CommonPrefix, files []*s3.Object) []aws.S3Object { var s3Objects []aws.S3Object indx := 0 - for _, bi := range Folder { - keyA := strings.Split(*bi.Prefix, "/") - o := aws.S3Object{ - Name: keyA[len(keyA)-2], - ObjectType: "Folder", - LastModified: "-", - Size: "-", - StorageClass: "-", + if len(folders) != 0 { + for _, bi := range folders { + keyA := strings.Split(*bi.Prefix, "/") + o := aws.S3Object{ + Name: keyA[len(keyA)-2], + ObjectType: "Folder", + LastModified: "-", + Size: "-", + StorageClass: "-", + } + s3Objects = append(s3Objects, o) + indx++ } - s3Objects = append(s3Objects, o) - indx++ } - for _, fi := range File { - keyA := strings.Split(*fi.Key, "/") - o := aws.S3Object{ - Name: keyA[len(keyA)-1], - ObjectType: "File", - LastModified: fi.LastModified.String(), - Size: humanize.Bytes(uint64(*fi.Size)), - StorageClass: *fi.StorageClass, + if len(files) != 0 { + for _, fi := range files { + keyA := strings.Split(*fi.Key, "/") + o := aws.S3Object{ + Name: keyA[len(keyA)-1], + ObjectType: "File", + LastModified: fi.LastModified.String(), + Size: humanize.Bytes(uint64(*fi.Size)), + StorageClass: *fi.StorageClass, + } + s3Objects = append(s3Objects, o) + indx++ } - s3Objects = append(s3Objects, o) - indx++ } return s3Objects