Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move around tests a bit, split pwr.StateConsumer into its own package…
…, display total coverage via gocovmerge
- Loading branch information
1 parent
53c74d8
commit a6b8ae4
Showing
31 changed files
with
568 additions
and
469 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
*.coverprofile | ||
coverage.txt | ||
/src | ||
/pkg | ||
/bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package containerarchiver | ||
|
||
import ( | ||
"archive/zip" | ||
"io" | ||
"os" | ||
"time" | ||
|
||
"github.com/go-errors/errors" | ||
"github.com/itchio/wharf/archiver" | ||
"github.com/itchio/wharf/counter" | ||
"github.com/itchio/wharf/state" | ||
"github.com/itchio/wharf/tlc" | ||
"github.com/itchio/wharf/wsync" | ||
) | ||
|
||
func CompressZip(archiveWriter io.Writer, container *tlc.Container, pool wsync.Pool, consumer *state.Consumer) (*archiver.CompressResult, error) { | ||
var err error | ||
var uncompressedSize int64 | ||
var compressedSize int64 | ||
|
||
archiveCounter := counter.NewWriter(archiveWriter) | ||
|
||
zipWriter := zip.NewWriter(archiveCounter) | ||
defer zipWriter.Close() | ||
defer func() { | ||
if zipWriter != nil { | ||
if zErr := zipWriter.Close(); err == nil && zErr != nil { | ||
err = errors.Wrap(zErr, 1) | ||
} | ||
} | ||
}() | ||
|
||
for _, dir := range container.Dirs { | ||
fh := zip.FileHeader{ | ||
Name: dir.Path + "/", | ||
} | ||
fh.SetMode(os.FileMode(dir.Mode)) | ||
fh.SetModTime(time.Now()) | ||
|
||
_, hErr := zipWriter.CreateHeader(&fh) | ||
if hErr != nil { | ||
return nil, errors.Wrap(hErr, 1) | ||
} | ||
} | ||
|
||
for fileIndex, file := range container.Files { | ||
fh := zip.FileHeader{ | ||
Name: file.Path, | ||
UncompressedSize64: uint64(file.Size), | ||
Method: zip.Deflate, | ||
} | ||
fh.SetMode(os.FileMode(file.Mode)) | ||
fh.SetModTime(time.Now()) | ||
|
||
entryWriter, eErr := zipWriter.CreateHeader(&fh) | ||
if eErr != nil { | ||
return nil, errors.Wrap(eErr, 1) | ||
} | ||
|
||
entryReader, eErr := pool.GetReader(int64(fileIndex)) | ||
if eErr != nil { | ||
return nil, errors.Wrap(eErr, 1) | ||
} | ||
|
||
copiedBytes, eErr := io.Copy(entryWriter, entryReader) | ||
if eErr != nil { | ||
return nil, errors.Wrap(eErr, 1) | ||
} | ||
|
||
uncompressedSize += copiedBytes | ||
} | ||
|
||
for _, symlink := range container.Symlinks { | ||
fh := zip.FileHeader{ | ||
Name: symlink.Path, | ||
} | ||
fh.SetMode(os.FileMode(symlink.Mode)) | ||
|
||
entryWriter, eErr := zipWriter.CreateHeader(&fh) | ||
if eErr != nil { | ||
return nil, errors.Wrap(eErr, 1) | ||
} | ||
|
||
entryWriter.Write([]byte(symlink.Dest)) | ||
} | ||
|
||
err = zipWriter.Close() | ||
if err != nil { | ||
return nil, errors.Wrap(err, 1) | ||
} | ||
zipWriter = nil | ||
|
||
compressedSize = archiveCounter.Count() | ||
|
||
return &archiver.CompressResult{ | ||
UncompressedSize: uncompressedSize, | ||
CompressedSize: compressedSize, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.