MCPcopy
hub / github.com/kopia/kopia / removeEmptyDirs

Method removeEmptyDirs

cli/command_blob_shards_modify.go:186–225  ·  view source on GitHub ↗
(ctx context.Context, dir string, numRemoved *int)

Source from the content-addressed store, hash-verified

184}
185
186func (c *commandBlobShardsModify) removeEmptyDirs(ctx context.Context, dir string, numRemoved *int) (bool, error) {
187 entries, err := os.ReadDir(dir)
188 if err != nil {
189 return false, errors.Wrap(err, "error reading directory")
190 }
191
192 isEmpty := true
193
194 for _, ent := range entries {
195 //nolint:nestif
196 if ent.IsDir() {
197 childPath := path.Join(dir, ent.Name())
198
199 subDirEmpty, err := c.removeEmptyDirs(ctx, childPath, numRemoved)
200 if err != nil {
201 return false, err
202 }
203
204 if !subDirEmpty {
205 isEmpty = false
206 } else {
207 c.out.printStdout("rmdir %v\n", childPath)
208
209 *numRemoved++
210
211 if !c.dryRun {
212 if err := os.Remove(childPath); err != nil {
213 log(ctx).Errorf("Unable to remove directory %v", childPath)
214
215 isEmpty = false
216 }
217 }
218 }
219 } else {
220 isEmpty = false
221 }
222 }
223
224 return isEmpty, nil
225}
226
227func (c *commandBlobShardsModify) renameBlobs(ctx context.Context, dir, prefix string, params *sharded.Parameters, numMoved, numUnchanged *int) error {
228 entries, err := os.ReadDir(dir)

Callers 1

runMethod · 0.95

Calls 6

printStdoutMethod · 0.80
ErrorfMethod · 0.80
ReadDirMethod · 0.65
NameMethod · 0.65
RemoveMethod · 0.65
IsDirMethod · 0.45

Tested by

no test coverage detected