| 184 | } |
| 185 | |
| 186 | func (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 | |
| 227 | func (c *commandBlobShardsModify) renameBlobs(ctx context.Context, dir, prefix string, params *sharded.Parameters, numMoved, numUnchanged *int) error { |
| 228 | entries, err := os.ReadDir(dir) |