forked from chen-keinan/go-archive-extractor
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
badd9da
commit 8d73466
Showing
113 changed files
with
460 additions
and
20,102 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
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 |
---|---|---|
@@ -1,15 +1,25 @@ | ||
package archiver_errors | ||
|
||
import "fmt" | ||
import ( | ||
"fmt" | ||
) | ||
|
||
type ArchiverExtractorError struct { | ||
archiverError error | ||
message string | ||
} | ||
|
||
func New(e error) ArchiverExtractorError { | ||
return ArchiverExtractorError{archiverError: e} | ||
} | ||
|
||
func NewWithMessage(msg string, e error) ArchiverExtractorError { | ||
return ArchiverExtractorError{archiverError: e, message: msg} | ||
} | ||
|
||
func (aee ArchiverExtractorError) Error() string { | ||
if aee.message != "" { | ||
return fmt.Sprintf("Archive extractor error, message:%s, err:%s", aee.message, aee.archiverError.Error()) | ||
} | ||
return fmt.Sprintf("Archive extractor error, %s", aee.archiverError.Error()) | ||
} |
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,8 @@ | ||
package archiver_errors | ||
|
||
import "fmt" | ||
|
||
var ( | ||
RarDecodeError = fmt.Errorf("rardecode: RAR signature not found") | ||
SevenZipDecodeError = fmt.Errorf("sevenzip: not a valid 7-zip file") | ||
) |
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,20 @@ | ||
package archiver_errors | ||
|
||
import "fmt" | ||
|
||
type OpenError struct { | ||
msg string | ||
err error | ||
} | ||
|
||
func NewOpenError(msg string, err error) *OpenError { | ||
return &OpenError{err: err, msg: msg} | ||
} | ||
|
||
func (op *OpenError) Error() string { | ||
return fmt.Sprintf("Failed to open file, file:%s, err:%s", op.msg, op.err.Error()) | ||
} | ||
|
||
func (op *OpenError) Unwrap() error { | ||
return op.err | ||
} |
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,43 @@ | ||
package archive_extractor | ||
|
||
import ( | ||
"context" | ||
"github.com/jfrog/go-archive-extractor/archive_extractor/archiver_errors" | ||
"github.com/jfrog/go-archive-extractor/utils" | ||
"github.com/mholt/archives" | ||
"io" | ||
) | ||
|
||
type processingArchiveFunc func(*ArchiveHeader, map[string]interface{}) error | ||
|
||
func extract(ctx context.Context, ex archives.Extractor, arcReader io.Reader, MaxNumberOfEntries int, provider LimitAggregatingReadCloserProvider, processingFunc processingArchiveFunc, params map[string]any) error { | ||
entriesCount := 0 | ||
var multiErrors *archiver_errors.MultiError | ||
err := ex.Extract(ctx, arcReader, func(ctx context.Context, fileInfo archives.FileInfo) error { | ||
if MaxNumberOfEntries != 0 && entriesCount >= MaxNumberOfEntries { | ||
return ErrTooManyEntries | ||
} | ||
entriesCount++ | ||
file, err := fileInfo.Open() | ||
defer func() { | ||
if file != nil { | ||
_ = file.Close() | ||
} | ||
}() | ||
if err != nil { | ||
multiErrors = archiver_errors.Append(multiErrors, archiver_errors.NewWithMessage(fileInfo.NameInArchive, err)) | ||
} else if !fileInfo.IsDir() && !utils.PlaceHolderFolder(fileInfo.Name()) { | ||
countingReadCloser := provider.CreateLimitAggregatingReadCloser(file) | ||
archiveHeader := NewArchiveHeader(countingReadCloser, fileInfo.NameInArchive, fileInfo.ModTime().Unix(), fileInfo.Size()) | ||
processingError := processingFunc(archiveHeader, params) | ||
if processingError != nil { | ||
return processingError | ||
} | ||
} | ||
return nil | ||
}) | ||
if err == nil && multiErrors != nil { | ||
return multiErrors | ||
} | ||
return err | ||
} |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
//go:build tests_group_all | ||
|
||
package archive_extractor | ||
|
||
import ( | ||
|
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
//go:build tests_group_all | ||
|
||
package archive_extractor | ||
|
||
import ( | ||
|
Oops, something went wrong.