(tasks []*model.Task, absScanDir string)
| 222 | } |
| 223 | |
| 224 | func executeArchive(tasks []*model.Task, absScanDir string) error { |
| 225 | r := getRenderer() |
| 226 | archiveDir := filepath.Join(absScanDir, "archive") |
| 227 | |
| 228 | for _, task := range tasks { |
| 229 | relPath, err := filepath.Rel(absScanDir, task.FilePath) |
| 230 | if err != nil { |
| 231 | return fmt.Errorf("failed to compute relative path for %s: %w", task.FilePath, err) |
| 232 | } |
| 233 | |
| 234 | destPath := filepath.Join(archiveDir, relPath) |
| 235 | |
| 236 | if err := os.MkdirAll(filepath.Dir(destPath), 0755); err != nil { |
| 237 | return fmt.Errorf("failed to create archive directory: %w", err) |
| 238 | } |
| 239 | |
| 240 | if _, err := os.Stat(destPath); err == nil { |
| 241 | return fmt.Errorf("archive destination already exists: %s", destPath) |
| 242 | } |
| 243 | |
| 244 | if err := os.Rename(task.FilePath, destPath); err != nil { |
| 245 | return fmt.Errorf("failed to move %s: %w", task.FilePath, err) |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | fmt.Println(formatSuccess(fmt.Sprintf("Archived %d task(s).", len(tasks)), r)) |
| 250 | return nil |
| 251 | } |
no test coverage detected