| 1 | package host |
| 2 | |
| 3 | import ( |
| 4 | "path/filepath" |
| 5 | |
| 6 | "github.com/carlosframework/platform/internal/safefile" |
| 7 | ) |
| 8 | |
| 9 | // reapStagingWrites runs before a pass needs free space for its own writes. |
| 10 | // Production callers run as root, so service-owned scratch is never removed. |
| 11 | func reapStagingWrites(opt, data, etc string, logf func(string, ...any)) { |
| 12 | roots := []string{opt, data} |
| 13 | if opt != "" { |
| 14 | // Descendant traversal refuses mount crossings. Open known writer |
| 15 | // roots separately too, for boxes with a dedicated versions disk. |
| 16 | roots = append(roots, filepath.Join(opt, "versions"), filepath.Join(opt, "staging"), |
| 17 | filepath.Join(systemRootDir(opt), "staging")) |
| 18 | } |
| 19 | if etc != "" { |
| 20 | roots = append(roots, filepath.Join(etc, "carlos"), filepath.Join(etc, "systemd", "system"), |
| 21 | filepath.Join(etc, "systemd", "journald.conf.d"), filepath.Join(etc, "sysusers.d"), |
| 22 | filepath.Join(etc, "tmpfiles.d")) |
| 23 | } |
| 24 | for _, root := range roots { |
| 25 | if root == "" { |
| 26 | continue |
| 27 | } |
| 28 | if err := safefile.Reap(root); err != nil { |
| 29 | logf("staging cleanup: %s: %v", root, err) |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | |