Skip to content

Commit b332fea

Browse files
authored
refactor(handlers): move timeout to archive file (#3918)
1 parent 0d53a55 commit b332fea

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

pkg/handlers/archive.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ const (
2323
var (
2424
// NOTE: This is a temporary workaround for |openArchive| incrementing depth twice per archive.
2525
// See: https://github.com/trufflesecurity/trufflehog/issues/2942
26-
maxDepth = 5 * 2
27-
maxSize = 2 << 30 // 2 GB
26+
maxDepth = 5 * 2
27+
maxSize = 2 << 30 // 2 GB
28+
maxTimeout = time.Duration(60) * time.Second
2829
)
2930

3031
// SetArchiveMaxSize sets the maximum size of the archive.
@@ -33,6 +34,9 @@ func SetArchiveMaxSize(size int) { maxSize = size }
3334
// SetArchiveMaxDepth sets the maximum depth of the archive.
3435
func SetArchiveMaxDepth(depth int) { maxDepth = depth }
3536

37+
// SetArchiveMaxTimeout sets the maximum timeout for the archive handler.
38+
func SetArchiveMaxTimeout(timeout time.Duration) { maxTimeout = timeout }
39+
3640
// archiveHandler is a handler for common archive files that are supported by the archiver library.
3741
type archiveHandler struct{ *defaultHandler }
3842

pkg/handlers/handlers.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"fmt"
99
"io"
1010
"path/filepath"
11-
"time"
1211

1312
"github.com/gabriel-vasile/mimetype"
1413
"github.com/mholt/archives"
@@ -322,11 +321,6 @@ func selectHandler(mimeT mimeType, isGenericArchive bool) FileHandler {
322321
}
323322
}
324323

325-
var maxTimeout = time.Duration(60) * time.Second
326-
327-
// SetArchiveMaxTimeout sets the maximum timeout for the archive handler.
328-
func SetArchiveMaxTimeout(timeout time.Duration) { maxTimeout = timeout }
329-
330324
// HandleFile orchestrates the complete file handling process for a given file.
331325
// It determines the MIME type of the file,
332326
// selects the appropriate handler based on this type, and processes the file.

0 commit comments

Comments
 (0)