AddToArchive adds a new path to the archive
(relativePath string)
| 213 | |
| 214 | // AddToArchive adds a new path to the archive |
| 215 | func (a *Archiver) AddToArchive(relativePath string) error { |
| 216 | absFilepath := path.Join(a.basePath, relativePath) |
| 217 | if a.writtenFiles[relativePath] != nil { |
| 218 | return nil |
| 219 | } |
| 220 | |
| 221 | // We skip files that are suddenly not there anymore |
| 222 | stat, err := os.Stat(absFilepath) |
| 223 | if err != nil { |
| 224 | // config.Logf("[Upstream] Couldn't stat file %s: %s\n", absFilepath, err.Error()) |
| 225 | return nil |
| 226 | } |
| 227 | |
| 228 | // Exclude files on the exclude list if it does not have a negate pattern, otherwise we will check below |
| 229 | if a.ignoreMatcher != nil && !a.ignoreMatcher.RequireFullScan() && a.ignoreMatcher.Matches(relativePath, stat.IsDir()) { |
| 230 | return nil |
| 231 | } |
| 232 | |
| 233 | fileInformation := createFileInformationFromStat(relativePath, stat) |
| 234 | if stat.IsDir() { |
| 235 | // Recursively tar folder |
| 236 | return a.tarFolder(fileInformation, stat) |
| 237 | } |
| 238 | |
| 239 | // exclude file? |
| 240 | if a.ignoreMatcher == nil || !a.ignoreMatcher.RequireFullScan() || !a.ignoreMatcher.Matches(relativePath, false) { |
| 241 | return a.tarFile(fileInformation, stat) |
| 242 | } |
| 243 | |
| 244 | return nil |
| 245 | } |
| 246 | |
| 247 | func (a *Archiver) tarFolder(target *FileInformation, targetStat os.FileInfo) error { |
| 248 | filePath := path.Join(a.basePath, target.Name) |
no test coverage detected