@@ -786,21 +786,23 @@ export default class WSLBackend extends events.EventEmitter implements K8s.Kuber
786786 }
787787
788788 /**
789- * Write the given contents to a given file name in the RD WSL distribution.
789+ * Write the given contents to a given file name in the given WSL distribution.
790790 * @param filePath The destination file path, in the WSL distribution.
791791 * @param fileContents The contents of the file.
792- * @param permissions The file permissions.
792+ * @param [options.permissions=0o644] The file permissions.
793+ * @param [options.distro=INSTANCE_NAME] WSL distribution to write to.
793794 */
794- protected async writeFile ( filePath : string , fileContents : string , permissions : fs . Mode = 0o644 ) {
795+ protected async writeFile ( filePath : string , fileContents : string , options ?: Partial < { permissions : fs . Mode , distro : typeof INSTANCE_NAME | typeof DATA_INSTANCE_NAME } > ) {
796+ const distro = options ?. distro ?? INSTANCE_NAME ;
795797 const workdir = await fs . promises . mkdtemp ( path . join ( os . tmpdir ( ) , `rd-${ path . basename ( filePath ) } -` ) ) ;
796798
797799 try {
798800 const scriptPath = path . join ( workdir , path . basename ( filePath ) ) ;
799- const wslScriptPath = await this . wslify ( scriptPath ) ;
801+ const wslScriptPath = await this . wslify ( scriptPath , distro ) ;
800802
801803 await fs . promises . writeFile ( scriptPath , fileContents . replace ( / \r / g, '' ) , 'utf-8' ) ;
802- await this . execCommand ( 'cp' , wslScriptPath , filePath ) ;
803- await this . execCommand ( ' chmod', permissions . toString ( 8 ) , filePath ) ;
804+ await this . execCommand ( { distro } , 'busybox' , 'cp' , wslScriptPath , filePath ) ;
805+ await this . execCommand ( { distro } , 'busybox' , ' chmod', ( options ?. permissions ?? 0o644 ) . toString ( 8 ) , filePath ) ;
804806 } finally {
805807 await fs . promises . rm ( workdir , { recursive : true } ) ;
806808 }
@@ -1226,19 +1228,19 @@ export default class WSLBackend extends events.EventEmitter implements K8s.Kuber
12261228 const rotateConf = LOGROTATE_K3S_SCRIPT . replace ( / \r / g, '' )
12271229 . replace ( '/var/log' , logPath ) ;
12281230
1229- await this . writeFile ( '/etc/init.d/k3s' , SERVICE_SCRIPT_K3S , 0o755 ) ;
1230- await this . writeFile ( '/etc/logrotate.d/k3s' , rotateConf , 0o644 ) ;
1231+ await this . writeFile ( '/etc/init.d/k3s' , SERVICE_SCRIPT_K3S , { permissions : 0o755 } ) ;
1232+ await this . writeFile ( '/etc/logrotate.d/k3s' , rotateConf ) ;
12311233 await this . execCommand ( 'mkdir' , '-p' , '/etc/cni/net.d' ) ;
1232- await this . writeFile ( '/etc/cni/net.d/10-flannel.conflist' , FLANNEL_CONFLIST , 0o644 ) ;
1233- await this . writeFile ( '/etc/containerd/config.toml' , CONTAINERD_CONFIG , 0o644 ) ;
1234+ await this . writeFile ( '/etc/cni/net.d/10-flannel.conflist' , FLANNEL_CONFLIST ) ;
1235+ await this . writeFile ( '/etc/containerd/config.toml' , CONTAINERD_CONFIG ) ;
12341236 await this . writeConf ( 'containerd' , { log_owner : 'root' } ) ;
1235- await this . writeFile ( '/etc/init.d/docker' , SERVICE_SCRIPT_DOCKERD , 0o755 ) ;
1237+ await this . writeFile ( '/etc/init.d/docker' , SERVICE_SCRIPT_DOCKERD , { permissions : 0o755 } ) ;
12361238 await this . writeConf ( 'docker' , {
12371239 WSL_HELPER_BINARY : await this . getWSLHelperPath ( ) ,
12381240 LOG_DIR : logPath ,
12391241 } ) ;
1240- await this . writeFile ( `/etc/init.d/buildkitd` , SERVICE_BUILDKITD_INIT , 0o755 ) ;
1241- await this . writeFile ( `/etc/conf.d/buildkitd` , SERVICE_BUILDKITD_CONF , 0o644 ) ;
1242+ await this . writeFile ( `/etc/init.d/buildkitd` , SERVICE_BUILDKITD_INIT , { permissions : 0o755 } ) ;
1243+ await this . writeFile ( `/etc/conf.d/buildkitd` , SERVICE_BUILDKITD_CONF ) ;
12421244 await this . execCommand ( 'mkdir' , '-p' , '/var/lib/misc' ) ;
12431245
12441246 await this . runInit ( ) ;
0 commit comments