11import { field , logger } from "@coder/logger" ;
2+ import { mkdirP } from "@coder/protocol" ;
23import { ServerMessage , SharedProcessActiveMessage } from "@coder/protocol/src/proto" ;
34import { Command , flags } from "@oclif/command" ;
45import { fork , ForkOptions , ChildProcess } from "child_process" ;
56import { randomFillSync } from "crypto" ;
67import * as fs from "fs" ;
8+ import * as os from "os" ;
79import * as path from "path" ;
810import * as WebSocket from "ws" ;
911import { createApp } from "./server" ;
@@ -50,6 +52,20 @@ export class Entry extends Command {
5052 const dataDir = path . resolve ( flags [ "data-dir" ] || path . join ( dataHome , "code-server" ) ) ;
5153 const workingDir = path . resolve ( args [ "workdir" ] ) ;
5254
55+ if ( ! fs . existsSync ( dataDir ) ) {
56+ const oldDataDir = path . resolve ( path . join ( os . homedir ( ) , ".code-server" ) ) ;
57+ if ( fs . existsSync ( oldDataDir ) ) {
58+ fs . renameSync ( oldDataDir , dataDir ) ;
59+ logger . info ( `Moved data directory from ${ oldDataDir } to ${ dataDir } ` ) ;
60+ }
61+ }
62+
63+ await Promise . all ( [
64+ mkdirP ( cacheHome ) ,
65+ mkdirP ( dataDir ) ,
66+ mkdirP ( workingDir ) ,
67+ ] ) ;
68+
5369 setupNativeModules ( dataDir ) ;
5470 const builtInExtensionsDir = path . resolve ( buildDir || path . join ( __dirname , ".." ) , "build/extensions" ) ;
5571 if ( flags [ "bootstrap-fork" ] ) {
@@ -74,14 +90,6 @@ export class Entry extends Command {
7490 return requireFork ( modulePath , JSON . parse ( flags . args ! ) , builtInExtensionsDir ) ;
7591 }
7692
77- if ( ! fs . existsSync ( dataDir ) ) {
78- fs . mkdirSync ( dataDir ) ;
79- }
80-
81- if ( ! fs . existsSync ( cacheHome ) ) {
82- fs . mkdirSync ( cacheHome ) ;
83- }
84-
8593 const logDir = path . join ( cacheHome , "code-server/logs" , new Date ( ) . toISOString ( ) . replace ( / [ - : . T Z ] / g, "" ) ) ;
8694 process . env . VSCODE_LOGS = logDir ;
8795
@@ -173,6 +181,7 @@ export class Entry extends Command {
173181 builtInExtensionsDirectory : builtInExtensionsDir ,
174182 dataDirectory : dataDir ,
175183 workingDirectory : workingDir ,
184+ cacheDirectory : cacheHome ,
176185 fork : ( modulePath : string , args : string [ ] , options : ForkOptions ) : ChildProcess => {
177186 if ( options && options . env && options . env . AMD_ENTRYPOINT ) {
178187 return forkModule ( options . env . AMD_ENTRYPOINT , args , options , dataDir ) ;
@@ -188,11 +197,6 @@ export class Entry extends Command {
188197 } : undefined ,
189198 } ) ;
190199
191- if ( ! fs . existsSync ( workingDir ) ) {
192- logger . info ( "Creating working directory" , field ( "working-dir" , workingDir ) ) ;
193- fs . mkdirSync ( workingDir ) ;
194- }
195-
196200 logger . info ( "Starting webserver..." , field ( "host" , flags . host ) , field ( "port" , flags . port ) ) ;
197201 app . server . listen ( flags . port , flags . host ) ;
198202 let clientId = 1 ;
0 commit comments