@@ -21,6 +21,7 @@ import (
2121
2222 "github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
2323 "github.com/elastic/elastic-agent/internal/pkg/agent/errors"
24+ "github.com/elastic/elastic-agent/pkg/core/logger"
2425)
2526
2627// unpack unpacks archive correctly, skips root (symlink, config...) unpacks data/*
@@ -30,18 +31,21 @@ func (u *Upgrader) unpack(ctx context.Context, version, archivePath string) (str
3031 var hash string
3132 var err error
3233 if runtime .GOOS == "windows" {
33- hash , err = unzip (version , archivePath )
34+ hash , err = unzip (u . log , version , archivePath )
3435 } else {
35- hash , err = untar (version , archivePath )
36+ hash , err = untar (u . log , version , archivePath )
3637 }
38+
3739 if err != nil {
40+ u .log .Errorw ("Failed to unpack upgrade artifact" , "error.message" , err , "version" , version , "file.path" , archivePath , "hash" , hash )
3841 return "" , err
3942 }
4043
44+ u .log .Infow ("Unpacked upgrade artifact" , "version" , version , "file.path" , archivePath , "hash" , hash )
4145 return hash , nil
4246}
4347
44- func unzip (version , archivePath string ) (string , error ) {
48+ func unzip (log * logger. Logger , version string , archivePath string ) (string , error ) {
4549 var hash , rootDir string
4650 r , err := zip .OpenReader (archivePath )
4751 if err != nil {
@@ -82,8 +86,10 @@ func unzip(version, archivePath string) (string, error) {
8286 path := filepath .Join (paths .Data (), strings .TrimPrefix (fileName , "data/" ))
8387
8488 if f .FileInfo ().IsDir () {
89+ log .Debugw ("Unpacking directory" , "archive" , "zip" , "file.path" , path )
8590 os .MkdirAll (path , f .Mode ())
8691 } else {
92+ log .Debugw ("Unpacking file" , "archive" , "zip" , "file.path" , path )
8793 os .MkdirAll (filepath .Dir (path ), f .Mode ())
8894 f , err := os .OpenFile (path , os .O_WRONLY | os .O_CREATE | os .O_TRUNC , f .Mode ())
8995 if err != nil {
@@ -119,7 +125,7 @@ func unzip(version, archivePath string) (string, error) {
119125 return hash , nil
120126}
121127
122- func untar (version , archivePath string ) (string , error ) {
128+ func untar (log * logger. Logger , version string , archivePath string ) (string , error ) {
123129 r , err := os .Open (archivePath )
124130 if err != nil {
125131 return "" , errors .New (fmt .Sprintf ("artifact for 'elastic-agent' version '%s' could not be found at '%s'" , version , archivePath ), errors .TypeFilesystem , errors .M (errors .MetaKeyPath , archivePath ))
@@ -183,6 +189,7 @@ func untar(version, archivePath string) (string, error) {
183189 mode := fi .Mode ()
184190 switch {
185191 case mode .IsRegular ():
192+ log .Debugw ("Unpacking file" , "archive" , "tar" , "file.path" , abs )
186193 // just to be sure, it should already be created by Dir type
187194 if err := os .MkdirAll (filepath .Dir (abs ), 0755 ); err != nil {
188195 return "" , errors .New (err , "TarInstaller: creating directory for file " + abs , errors .TypeFilesystem , errors .M (errors .MetaKeyPath , abs ))
@@ -201,6 +208,7 @@ func untar(version, archivePath string) (string, error) {
201208 return "" , fmt .Errorf ("TarInstaller: error writing to %s: %w" , abs , err )
202209 }
203210 case mode .IsDir ():
211+ log .Debugw ("Unpacking directory" , "archive" , "tar" , "file.path" , abs )
204212 if err := os .MkdirAll (abs , 0755 ); err != nil {
205213 return "" , errors .New (err , "TarInstaller: creating directory for file " + abs , errors .TypeFilesystem , errors .M (errors .MetaKeyPath , abs ))
206214 }
0 commit comments