Skip to content

Commit

Permalink
Merge pull request #11 from stevenh/fix/exclude-output-file
Browse files Browse the repository at this point in the history
fix: exclude output from archive
  • Loading branch information
ybirader authored Dec 10, 2023
2 parents 5a544de + 00d6d9f commit 366a78c
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions archiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ var bufferPool = sync.Pool{
}

type archiver struct {
dest *os.File
concurrency int
w *zip.Writer
fileProcessPool pool.WorkerPool[pool.File]
fileWriterPool pool.WorkerPool[pool.File]
chroot string
dest *os.File
concurrency int
w *zip.Writer
fileProcessPool pool.WorkerPool[pool.File]
fileWriterPool pool.WorkerPool[pool.File]
chroot string
absoluteArchivePath string
}

// NewArchiver returns a new pzip archiver. The archiver can be configured by passing in a number of options.
Expand All @@ -50,6 +51,12 @@ func NewArchiver(archive *os.File, options ...archiverOption) (*archiver, error)
concurrency: runtime.GOMAXPROCS(0),
}

var err error
a.absoluteArchivePath, err = filepath.Abs(archive.Name())
if err != nil {
return nil, fmt.Errorf("absolute archive path %q: %w", archive.Name(), err)
}

fileProcessExecutor := func(file *pool.File) error {
err := a.compress(file)
if err != nil {
Expand Down Expand Up @@ -151,7 +158,14 @@ func (a *archiver) archiveDir(root string) error {
return nil
}

// archiveFile enqueues file for archiving if it doesn't match
// our output file.
func (a *archiver) archiveFile(file *pool.File) {
if file.Path == a.absoluteArchivePath {
// Don't archive the output file.
return
}

a.fileProcessPool.Enqueue(file)
}

Expand Down

0 comments on commit 366a78c

Please sign in to comment.