@@ -910,13 +910,13 @@ func decodeGBK(input string) (string, error) {
910910 return decoded , nil
911911}
912912
913- func (f FileOp ) decompressWithSDK (srcFile string , dst string , cType CompressType ) error {
913+ func (f FileOp ) decompressWithSDK (ctx context. Context , srcFile string , dst string , cType CompressType ) error {
914914 format := getFormat (cType )
915915 if cType == Gz {
916- if err := f .tryDecompressTarGz (srcFile , dst , format ); err == nil {
916+ if err := f .tryDecompressTarGz (ctx , srcFile , dst , format ); err == nil {
917917 return nil
918918 }
919- return f .DecompressGzFile (srcFile , dst )
919+ return f .DecompressGzFile (ctx , srcFile , dst )
920920 }
921921
922922 type dirEntry struct {
@@ -976,7 +976,7 @@ func (f FileOp) decompressWithSDK(srcFile string, dst string, cType CompressType
976976 return err
977977 }
978978 defer input .Close ()
979- if err := format .Extract (context . Background () , input , nil , handler ); err != nil {
979+ if err := format .Extract (ctx , input , nil , handler ); err != nil {
980980 return err
981981 }
982982 for i := len (dirs ) - 1 ; i >= 0 ; i -- {
@@ -985,21 +985,21 @@ func (f FileOp) decompressWithSDK(srcFile string, dst string, cType CompressType
985985 return nil
986986}
987987
988- func (f FileOp ) Decompress (srcFile string , dst string , cType CompressType , secret string ) error {
988+ func (f FileOp ) Decompress (ctx context. Context , srcFile string , dst string , cType CompressType , secret string ) error {
989989 if cType == Tar || cType == Zip || cType == TarGz || cType == Rar || cType == X7z {
990990 shellArchiver , err := NewExtractShellArchiver (cType )
991991 if ! f .Stat (dst ) {
992992 _ = f .CreateDir (dst , 0755 )
993993 }
994994 if err == nil {
995- if err = shellArchiver .Extract (srcFile , dst , secret ); err == nil {
995+ if err = shellArchiver .Extract (ctx , srcFile , dst , secret ); err == nil {
996996 return nil
997997 }
998998 if cType == TarGz {
999999 if strings .Contains (err .Error (), "bad decrypt" ) {
10001000 return buserr .New ("ErrBadDecrypt" )
10011001 }
1002- if err := shellArchiver .Extract (srcFile , dst , "-" ); strings .Contains (err .Error (), "bad decrypt" ) {
1002+ if err := shellArchiver .Extract (ctx , srcFile , dst , "-" ); strings .Contains (err .Error (), "bad decrypt" ) {
10031003 return buserr .New ("ErrBadDecrypt" )
10041004 }
10051005 }
@@ -1009,7 +1009,7 @@ func (f FileOp) Decompress(srcFile string, dst string, cType CompressType, secre
10091009 }
10101010 }
10111011 }
1012- return f .decompressWithSDK (srcFile , dst , cType )
1012+ return f .decompressWithSDK (ctx , srcFile , dst , cType )
10131013}
10141014
10151015func ZipFile (ctx context.Context , files []archiver.File , dst afero.File , progress func (current , total int , message string )) error {
@@ -1088,7 +1088,7 @@ func (r *contextReader) Read(p []byte) (int, error) {
10881088 }
10891089}
10901090
1091- func (f FileOp ) tryDecompressTarGz (srcFile string , dst string , format archiver.CompressedArchive ) error {
1091+ func (f FileOp ) tryDecompressTarGz (ctx context. Context , srcFile string , dst string , format archiver.CompressedArchive ) error {
10921092 input , err := f .Fs .Open (srcFile )
10931093 if err != nil {
10941094 return err
@@ -1139,7 +1139,7 @@ func (f FileOp) tryDecompressTarGz(srcFile string, dst string, format archiver.C
11391139 return nil
11401140 }
11411141
1142- if err := format .Extract (context . Background () , input , nil , handler ); err != nil {
1142+ if err := format .Extract (ctx , input , nil , handler ); err != nil {
11431143 return err
11441144 }
11451145 if ! extracted {
@@ -1151,7 +1151,7 @@ func (f FileOp) tryDecompressTarGz(srcFile string, dst string, format archiver.C
11511151 return nil
11521152}
11531153
1154- func (f FileOp ) DecompressGzFile (srcFile , dst string ) error {
1154+ func (f FileOp ) DecompressGzFile (ctx context. Context , srcFile , dst string ) error {
11551155 var archiveModTime time.Time
11561156 if st , err := f .Fs .Stat (srcFile ); err == nil {
11571157 archiveModTime = st .ModTime ()
@@ -1163,7 +1163,7 @@ func (f FileOp) DecompressGzFile(srcFile, dst string) error {
11631163 }
11641164 defer in .Close ()
11651165
1166- gr , err := gzip .NewReader (in )
1166+ gr , err := gzip .NewReader (& contextReader { ctx : ctx , r : in } )
11671167 if err != nil {
11681168 return fmt .Errorf ("gzip reader creation failed: %w" , err )
11691169 }
0 commit comments