ArchivePathsIfExist creates a tar archive of all local files in `paths`. It quietly skips any paths that don't exist.
(paths []PathMapping)
| 140 | |
| 141 | // ArchivePathsIfExist creates a tar archive of all local files in `paths`. It quietly skips any paths that don't exist. |
| 142 | func (a *ArchiveBuilder) ArchivePathsIfExist(paths []PathMapping) error { |
| 143 | // In order to handle overlapping syncs, we |
| 144 | // 1) collect all the entries, |
| 145 | // 2) de-dupe them, with last-one-wins semantics |
| 146 | // 3) write all the entries |
| 147 | // |
| 148 | // It's not obvious that this is the correct behavior. A better approach |
| 149 | // (that's more in-line with how syncs work) might ignore files in earlier |
| 150 | // path mappings when we know they're going to be "synced" over. |
| 151 | // There's a bunch of subtle product decisions about how overlapping path |
| 152 | // mappings work that we're not sure about. |
| 153 | var entries []archiveEntry |
| 154 | for _, p := range paths { |
| 155 | newEntries, err := a.entriesForPath(p.HostPath, p.ContainerPath) |
| 156 | if err != nil { |
| 157 | return fmt.Errorf("inspecting %q: %w", p.HostPath, err) |
| 158 | } |
| 159 | |
| 160 | entries = append(entries, newEntries...) |
| 161 | } |
| 162 | |
| 163 | entries = dedupeEntries(entries) |
| 164 | for _, entry := range entries { |
| 165 | err := a.writeEntry(entry) |
| 166 | if err != nil { |
| 167 | return fmt.Errorf("archiving %q: %w", entry.path, err) |
| 168 | } |
| 169 | } |
| 170 | return nil |
| 171 | } |
| 172 | |
| 173 | func (a *ArchiveBuilder) writeEntry(entry archiveEntry) error { |
| 174 | pathInTar := entry.path |
no test coverage detected