Skip to content

Commit

Permalink
fix: exclude output from archive
Browse files Browse the repository at this point in the history
Exclude the target output file from the archiving process.

Fixes #10
  • Loading branch information
stevenh committed Nov 21, 2023
1 parent 2a1947c commit 8448e59
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 @@ -155,7 +162,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 8448e59

Please sign in to comment.