@@ -73,7 +73,7 @@ func (u *CoreUpdater) Update(currentExePath string) (err error) {
7373 u .mu .Lock ()
7474 defer u .mu .Unlock ()
7575
76- _ , err = os .Stat (currentExePath )
76+ info , err : = os .Stat (currentExePath )
7777 if err != nil {
7878 return fmt .Errorf ("check currentExePath %q: %w" , currentExePath , err )
7979 }
@@ -136,7 +136,7 @@ func (u *CoreUpdater) Update(currentExePath string) (err error) {
136136 return fmt .Errorf ("downloading: %w" , err )
137137 }
138138
139- err = u .unpack (updateDir , packagePath )
139+ err = u .unpack (updateDir , packagePath , info . Mode () )
140140 if err != nil {
141141 return fmt .Errorf ("unpacking: %w" , err )
142142 }
@@ -230,16 +230,16 @@ func (u *CoreUpdater) download(updateDir, packagePath, packageURL string) (err e
230230}
231231
232232// unpack extracts the files from the downloaded archive.
233- func (u * CoreUpdater ) unpack (updateDir , packagePath string ) error {
233+ func (u * CoreUpdater ) unpack (updateDir , packagePath string , fileMode os. FileMode ) error {
234234 log .Infoln ("updater: unpacking package" )
235235 if strings .HasSuffix (packagePath , ".zip" ) {
236- _ , err := u .zipFileUnpack (packagePath , updateDir )
236+ _ , err := u .zipFileUnpack (packagePath , updateDir , fileMode )
237237 if err != nil {
238238 return fmt .Errorf (".zip unpack failed: %w" , err )
239239 }
240240
241241 } else if strings .HasSuffix (packagePath , ".gz" ) {
242- _ , err := u .gzFileUnpack (packagePath , updateDir )
242+ _ , err := u .gzFileUnpack (packagePath , updateDir , fileMode )
243243 if err != nil {
244244 return fmt .Errorf (".gz unpack failed: %w" , err )
245245 }
@@ -295,7 +295,7 @@ func (u *CoreUpdater) clean(updateDir string) {
295295// Existing files are overwritten
296296// All files are created inside outDir, subdirectories are not created
297297// Return the output file name
298- func (u * CoreUpdater ) gzFileUnpack (gzfile , outDir string ) (outputName string , err error ) {
298+ func (u * CoreUpdater ) gzFileUnpack (gzfile , outDir string , fileMode os. FileMode ) (outputName string , err error ) {
299299 f , err := os .Open (gzfile )
300300 if err != nil {
301301 return "" , fmt .Errorf ("os.Open(): %w" , err )
@@ -330,7 +330,7 @@ func (u *CoreUpdater) gzFileUnpack(gzfile, outDir string) (outputName string, er
330330 outputName = filepath .Join (outDir , originalName )
331331
332332 // Create the output file
333- wc , err := os .OpenFile (outputName , os .O_WRONLY | os .O_CREATE | os .O_TRUNC , 0o755 )
333+ wc , err := os .OpenFile (outputName , os .O_WRONLY | os .O_CREATE | os .O_TRUNC , fileMode )
334334 if err != nil {
335335 return "" , fmt .Errorf ("os.OpenFile(%s): %w" , outputName , err )
336336 }
@@ -355,7 +355,7 @@ func (u *CoreUpdater) gzFileUnpack(gzfile, outDir string) (outputName string, er
355355// Existing files are overwritten
356356// All files are created inside 'outDir', subdirectories are not created
357357// Return the output file name
358- func (u * CoreUpdater ) zipFileUnpack (zipfile , outDir string ) (outputName string , err error ) {
358+ func (u * CoreUpdater ) zipFileUnpack (zipfile , outDir string , fileMode os. FileMode ) (outputName string , err error ) {
359359 zrc , err := zip .OpenReader (zipfile )
360360 if err != nil {
361361 return "" , fmt .Errorf ("zip.OpenReader(): %w" , err )
@@ -394,7 +394,7 @@ func (u *CoreUpdater) zipFileUnpack(zipfile, outDir string) (outputName string,
394394 }
395395
396396 var wc io.WriteCloser
397- wc , err = os .OpenFile (outputName , os .O_WRONLY | os .O_CREATE | os .O_TRUNC , fi . Mode () )
397+ wc , err = os .OpenFile (outputName , os .O_WRONLY | os .O_CREATE | os .O_TRUNC , fileMode )
398398 if err != nil {
399399 return "" , fmt .Errorf ("os.OpenFile(): %w" , err )
400400 }
0 commit comments