@@ -468,7 +468,7 @@ func getCacheDir() (string, error) {
468468 }
469469
470470 path := filepath .Join (dir , "fetch" )
471- err = os .MkdirAll (path , 0755 )
471+ err = os .MkdirAll (path , 0700 )
472472 if err != nil {
473473 return "" , err
474474 }
@@ -483,18 +483,32 @@ func updateLastAttemptTime(dir string, now time.Time) error {
483483 }
484484
485485 path := filepath .Join (dir , "metadata.json" )
486- tempPath := path + ".__temp"
487- err = os .WriteFile (tempPath , data , 0666 )
486+ f , err := os .CreateTemp (dir , ".metadata-*.tmp" )
487+ if err != nil {
488+ return err
489+ }
490+ tempPath := f .Name ()
491+ defer func () {
492+ // Clean up temp file on error.
493+ if err != nil {
494+ os .Remove (tempPath )
495+ }
496+ }()
497+ _ , err = f .Write (data )
498+ if err2 := f .Close (); err == nil {
499+ err = err2
500+ }
488501 if err != nil {
489502 return err
490503 }
491504
492- return os .Rename (tempPath , path )
505+ err = os .Rename (tempPath , path )
506+ return err
493507}
494508
495509func acquireLock (ctx context.Context , p * core.Printer , dir string , block bool ) (func (), error ) {
496510 path := filepath .Join (dir , ".update-lock" )
497- f , err := os .OpenFile (path , os .O_CREATE | os .O_RDWR , 0666 )
511+ f , err := os .OpenFile (path , os .O_CREATE | os .O_RDWR , 0600 )
498512 if err != nil {
499513 return nil , err
500514 }
0 commit comments