MCPcopy
hub / github.com/wal-g/wal-g / GetPartitionedBackupFileNames

Function GetPartitionedBackupFileNames

internal/stream_fetch_helper.go:153–195  ·  view source on GitHub ↗
(backup Backup, decompressor compression.Decompressor)

Source from the content-addressed store, hash-verified

151}
152
153func GetPartitionedBackupFileNames(backup Backup, decompressor compression.Decompressor) ([][]string, error) {
154 // list all files in backup folder:
155 files, _, err := backup.Folder.GetSubFolder(backup.Name).ListFolder()
156 if err != nil {
157 return nil, fmt.Errorf("cannot list files in backup folder '%s' due to: %w", backup.Folder.GetPath(), err)
158 }
159
160 // prepare lookup table:
161 fileNames := make(map[string]bool)
162 for _, file := range files {
163 filePath := path.Join(backup.Name, file.GetName())
164 fileNames[filePath] = true
165 }
166
167 result := make([][]string, 0)
168 partIdx := 0
169 for {
170 nextPartitionFirstFile := GetPartitionedSteamMultipartName(backup.Name, decompressor.FileExtension(), partIdx, 0)
171 nextPartitionWholeFile := GetPartitionedStreamName(backup.Name, decompressor.FileExtension(), partIdx)
172 if fileNames[nextPartitionFirstFile] {
173 result = append(result, make([]string, 1))
174 result[partIdx][0] = nextPartitionFirstFile
175 fileIdx := 1
176 for {
177 nextPartitionFile := GetPartitionedSteamMultipartName(backup.Name, decompressor.FileExtension(), partIdx, fileIdx)
178 if fileNames[nextPartitionFile] {
179 result[partIdx] = append(result[partIdx], nextPartitionFile)
180 fileIdx++
181 } else {
182 break
183 }
184 }
185 } else if fileNames[nextPartitionWholeFile] {
186 result = append(result, make([]string, 1))
187 result[partIdx][0] = nextPartitionWholeFile
188 } else {
189 break
190 }
191 partIdx++
192 }
193
194 return result, nil
195}

Callers 1

Calls 9

GetPartitionedStreamNameFunction · 0.85
ErrorfMethod · 0.80
JoinMethod · 0.80
ListFolderMethod · 0.65
GetSubFolderMethod · 0.65
GetPathMethod · 0.65
GetNameMethod · 0.65
FileExtensionMethod · 0.65

Tested by

no test coverage detected