(basePath string, fileInformation *fileInformation, writtenFiles map[string]bool, stat os.FileInfo, tw *tar.Writer)
| 233 | } |
| 234 | |
| 235 | func tarFile(basePath string, fileInformation *fileInformation, writtenFiles map[string]bool, stat os.FileInfo, tw *tar.Writer) error { |
| 236 | var err error |
| 237 | filepath := path.Join(basePath, fileInformation.Name) |
| 238 | if stat.Mode()&os.ModeSymlink == os.ModeSymlink { |
| 239 | if filepath, err = os.Readlink(filepath); err != nil { |
| 240 | return nil |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | // Case regular file |
| 245 | f, err := os.Open(filepath) |
| 246 | if err != nil { |
| 247 | // We ignore this error here because it could happen that the file is suddenly not here anymore |
| 248 | return nil |
| 249 | } |
| 250 | defer f.Close() |
| 251 | |
| 252 | hdr, err := tar.FileInfoHeader(stat, filepath) |
| 253 | if err != nil { |
| 254 | return errors.Wrapf(err, "tar file info header %s", filepath) |
| 255 | } |
| 256 | |
| 257 | hdr.Name = fileInformation.Name |
| 258 | |
| 259 | // We have to cut of the nanoseconds otherwise this sometimes leads to issues on the client side |
| 260 | // because the unix value will be rounded up |
| 261 | hdr.ModTime = time.Unix(fileInformation.Mtime.Unix(), 0) |
| 262 | |
| 263 | if err := tw.WriteHeader(hdr); err != nil { |
| 264 | return errors.Wrapf(err, "tw write header %s", filepath) |
| 265 | } |
| 266 | |
| 267 | // nothing more to do for non-regular |
| 268 | if !stat.Mode().IsRegular() { |
| 269 | return nil |
| 270 | } |
| 271 | |
| 272 | if copied, err := io.CopyN(tw, f, stat.Size()); err != nil { |
| 273 | return errors.Wrapf(err, "io copy %s", filepath) |
| 274 | } else if copied != stat.Size() { |
| 275 | return errors.New("tar: file truncated during read") |
| 276 | } |
| 277 | |
| 278 | writtenFiles[fileInformation.Name] = true |
| 279 | return nil |
| 280 | } |
| 281 | |
| 282 | func getRelativeFromFullPath(fullpath string, prefix string) string { |
| 283 | return strings.TrimPrefix(strings.ReplaceAll(strings.ReplaceAll(fullpath[len(prefix):], "\\", "/"), "//", "/"), ".") |
no test coverage detected