(basePath string, fileInformation *fileInformation, writtenFiles map[string]bool, stat os.FileInfo, tw *tar.Writer, skipContents bool)
| 193 | } |
| 194 | |
| 195 | func tarFolder(basePath string, fileInformation *fileInformation, writtenFiles map[string]bool, stat os.FileInfo, tw *tar.Writer, skipContents bool) error { |
| 196 | filepath := path.Join(basePath, fileInformation.Name) |
| 197 | files, err := os.ReadDir(filepath) |
| 198 | if err != nil { |
| 199 | // Ignore this error because it could happen the file is suddenly not there anymore |
| 200 | return nil |
| 201 | } |
| 202 | |
| 203 | if skipContents || (len(files) == 0 && fileInformation.Name != "") { |
| 204 | // Case empty directory |
| 205 | hdr, _ := tar.FileInfoHeader(stat, filepath) |
| 206 | hdr.Name = fileInformation.Name |
| 207 | hdr.ModTime = fileInformation.Mtime |
| 208 | if err := tw.WriteHeader(hdr); err != nil { |
| 209 | return errors.Wrapf(err, "tw write header %s", filepath) |
| 210 | } |
| 211 | |
| 212 | writtenFiles[fileInformation.Name] = true |
| 213 | } |
| 214 | |
| 215 | if !skipContents { |
| 216 | for _, dirEntry := range files { |
| 217 | f, err := dirEntry.Info() |
| 218 | if err != nil { |
| 219 | continue |
| 220 | } |
| 221 | |
| 222 | if fsutil.IsRecursiveSymlink(f, path.Join(fileInformation.Name, f.Name())) { |
| 223 | continue |
| 224 | } |
| 225 | |
| 226 | if err := recursiveTar(basePath, path.Join(fileInformation.Name, f.Name()), writtenFiles, tw, skipContents); err != nil { |
| 227 | return errors.Wrap(err, "recursive tar") |
| 228 | } |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | return nil |
| 233 | } |
| 234 | |
| 235 | func tarFile(basePath string, fileInformation *fileInformation, writtenFiles map[string]bool, stat os.FileInfo, tw *tar.Writer) error { |
| 236 | var err error |
no test coverage detected