@@ -427,7 +427,7 @@ func Run(ctx context.Context, options Options) error {
427
427
428
428
// It's possible that the container will already have files in it, and
429
429
// we don't want to merge a new container with the old one.
430
- if err := maybeDeleteFilesystem (options .ForceSafe ); err != nil {
430
+ if err := maybeDeleteFilesystem (options .Logger , options . ForceSafe ); err != nil {
431
431
return nil , fmt .Errorf ("delete filesystem: %w" , err )
432
432
}
433
433
@@ -1065,21 +1065,20 @@ func findDevcontainerJSON(options Options) (string, string, error) {
1065
1065
1066
1066
// maybeDeleteFilesystem wraps util.DeleteFilesystem with a guard to hopefully stop
1067
1067
// folks from unwittingly deleting their entire root directory.
1068
- func maybeDeleteFilesystem (force bool ) error {
1068
+ func maybeDeleteFilesystem (log LoggerFunc , force bool ) error {
1069
1069
kanikoDir , ok := os .LookupEnv ("KANIKO_DIR" )
1070
1070
if ! ok || strings .TrimSpace (kanikoDir ) != MagicDir {
1071
1071
if force {
1072
1072
bailoutSecs := 10
1073
- _ , _ = fmt . Fprintln ( os . Stderr , "WARNING! BYPASSING SAFETY CHECK! THIS WILL DELETE YOUR ROOT FILESYSTEM!" )
1074
- _ , _ = fmt . Fprintf ( os . Stderr , "You have %d seconds to bail out" , bailoutSecs )
1075
- for i := 0 ; i < bailoutSecs ; i ++ {
1076
- _ , _ = fmt . Fprintf ( os . Stderr , "." )
1073
+ log ( codersdk . LogLevelWarn , "WARNING! BYPASSING SAFETY CHECK! THIS WILL DELETE YOUR ROOT FILESYSTEM!" )
1074
+ log ( codersdk . LogLevelWarn , "You have %d seconds to bail out! " , bailoutSecs )
1075
+ for i := bailoutSecs ; i > 0 ; i -- {
1076
+ log ( codersdk . LogLevelWarn , "%d..." , i )
1077
1077
<- time .After (time .Second )
1078
1078
}
1079
- _ , _ = fmt .Fprintf (os .Stderr , "\n " )
1080
1079
} else {
1081
- _ , _ = fmt . Fprintf ( os . Stderr , "KANIKO_DIR is not set to %s. Bailing!\n " , MagicDir )
1082
- _ , _ = fmt . Fprintln ( os . Stderr , "To bypass this check, set FORCE_SAFE=true." )
1080
+ log ( codersdk . LogLevelError , "KANIKO_DIR is not set to %s. Bailing!\n " , MagicDir )
1081
+ log ( codersdk . LogLevelError , "To bypass this check, set FORCE_SAFE=true." )
1083
1082
return errors .New ("safety check failed" )
1084
1083
}
1085
1084
}
0 commit comments