| 20 | } |
| 21 | |
| 22 | func typeconv(thdr *tar.Header) int64 { |
| 23 | switch thdr.Typeflag { |
| 24 | case tar.TypeReg: |
| 25 | return cpio.TYPE_REG |
| 26 | // Currently hard links not supported very well :) |
| 27 | // Convert to relative symlink as absolute will not work in container |
| 28 | // cpio does support hardlinks but file contents still duplicated, so rely |
| 29 | // on compression to fix that which is fairly ugly. Symlink has not caused issues. |
| 30 | case tar.TypeLink: |
| 31 | dir := filepath.Dir(thdr.Name) |
| 32 | rel, err := filepath.Rel(dir, thdr.Linkname) |
| 33 | if err != nil { |
| 34 | // should never happen, but leave as full abs path |
| 35 | rel = "/" + thdr.Linkname |
| 36 | } |
| 37 | thdr.Linkname = rel |
| 38 | return cpio.TYPE_SYMLINK |
| 39 | case tar.TypeSymlink: |
| 40 | return cpio.TYPE_SYMLINK |
| 41 | case tar.TypeChar: |
| 42 | return cpio.TYPE_CHAR |
| 43 | case tar.TypeBlock: |
| 44 | return cpio.TYPE_BLK |
| 45 | case tar.TypeDir: |
| 46 | return cpio.TYPE_DIR |
| 47 | case tar.TypeFifo: |
| 48 | return cpio.TYPE_FIFO |
| 49 | default: |
| 50 | return -1 |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | func copyTarEntry(w *Writer, thdr *tar.Header, r io.Reader) (written int64, err error) { |
| 55 | tp := typeconv(thdr) |