MCPcopy
hub / github.com/kserve/kserve / GetAllObjects

Method GetAllObjects

pkg/agent/storage/s3.go:97–156  ·  view source on GitHub ↗
(s3Svc s3iface.S3API)

Source from the content-addressed store, hash-verified

95}
96
97func (s *S3ObjectDownloader) GetAllObjects(s3Svc s3iface.S3API) ([]s3manager.BatchDownloadObject, error) {
98 resp, err := s3Svc.ListObjects(&s3.ListObjectsInput{
99 Bucket: aws.String(s.Bucket),
100 Prefix: aws.String(s.Prefix),
101 })
102 if err != nil {
103 return nil, err
104 }
105 results := make([]s3manager.BatchDownloadObject, 0)
106
107 if len(resp.Contents) == 0 {
108 return nil, fmt.Errorf("%s has no objects or does not exist", s.StorageUri)
109 }
110
111 foundObject := false
112
113 for _, object := range resp.Contents {
114 if strings.HasSuffix(*object.Key, "/") {
115 continue
116 }
117 subObjectKey := strings.TrimPrefix(*object.Key, s.Prefix)
118 fileName := filepath.Join(s.ModelDir, s.ModelName, subObjectKey)
119
120 if FileExists(fileName) {
121 // File got corrupted or is mid-download :(
122 // TODO: Figure out if we can maybe continue?
123 if err := os.Remove(fileName); err != nil {
124 return nil, fmt.Errorf("file is unable to be deleted: %w", err)
125 }
126 }
127 file, err := Create(fileName)
128 if err != nil {
129 return nil, fmt.Errorf("file is already created: %w", err)
130 }
131 object := s3manager.BatchDownloadObject{
132 Object: &s3.GetObjectInput{
133 Key: aws.String(*object.Key),
134 Bucket: aws.String(s.Bucket),
135 },
136 Writer: file,
137 After: func() error {
138 defer func(file *os.File) {
139 closeErr := file.Close()
140 if closeErr != nil {
141 log.Error(closeErr, "failed to close file")
142 }
143 }(file)
144 return nil
145 },
146 }
147 foundObject = true
148 results = append(results, object)
149 }
150
151 if !foundObject {
152 return nil, fmt.Errorf("%s has no objects or does not exist", s.StorageUri)
153 }
154

Callers 1

DownloadModelMethod · 0.95

Calls 6

FileExistsFunction · 0.85
ListObjectsMethod · 0.80
CloseMethod · 0.80
CreateFunction · 0.70
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected