1
1
import { field , logger } from "@coder/logger" ;
2
+ import { mkdirP } from "@coder/protocol" ;
2
3
import { ServerMessage , SharedProcessActiveMessage } from "@coder/protocol/src/proto" ;
3
4
import { Command , flags } from "@oclif/command" ;
4
5
import { fork , ForkOptions , ChildProcess } from "child_process" ;
5
6
import { randomFillSync } from "crypto" ;
6
7
import * as fs from "fs" ;
8
+ import * as os from "os" ;
7
9
import * as path from "path" ;
8
10
import * as WebSocket from "ws" ;
9
11
import { createApp } from "./server" ;
@@ -50,6 +52,20 @@ export class Entry extends Command {
50
52
const dataDir = path . resolve ( flags [ "data-dir" ] || path . join ( dataHome , "code-server" ) ) ;
51
53
const workingDir = path . resolve ( args [ "workdir" ] ) ;
52
54
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
+
53
69
setupNativeModules ( dataDir ) ;
54
70
const builtInExtensionsDir = path . resolve ( buildDir || path . join ( __dirname , ".." ) , "build/extensions" ) ;
55
71
if ( flags [ "bootstrap-fork" ] ) {
@@ -74,14 +90,6 @@ export class Entry extends Command {
74
90
return requireFork ( modulePath , JSON . parse ( flags . args ! ) , builtInExtensionsDir ) ;
75
91
}
76
92
77
- if ( ! fs . existsSync ( dataDir ) ) {
78
- fs . mkdirSync ( dataDir ) ;
79
- }
80
-
81
- if ( ! fs . existsSync ( cacheHome ) ) {
82
- fs . mkdirSync ( cacheHome ) ;
83
- }
84
-
85
93
const logDir = path . join ( cacheHome , "code-server/logs" , new Date ( ) . toISOString ( ) . replace ( / [ - : . T Z ] / g, "" ) ) ;
86
94
process . env . VSCODE_LOGS = logDir ;
87
95
@@ -173,6 +181,7 @@ export class Entry extends Command {
173
181
builtInExtensionsDirectory : builtInExtensionsDir ,
174
182
dataDirectory : dataDir ,
175
183
workingDirectory : workingDir ,
184
+ cacheDirectory : cacheHome ,
176
185
fork : ( modulePath : string , args : string [ ] , options : ForkOptions ) : ChildProcess => {
177
186
if ( options && options . env && options . env . AMD_ENTRYPOINT ) {
178
187
return forkModule ( options . env . AMD_ENTRYPOINT , args , options , dataDir ) ;
@@ -188,11 +197,6 @@ export class Entry extends Command {
188
197
} : undefined ,
189
198
} ) ;
190
199
191
- if ( ! fs . existsSync ( workingDir ) ) {
192
- logger . info ( "Creating working directory" , field ( "working-dir" , workingDir ) ) ;
193
- fs . mkdirSync ( workingDir ) ;
194
- }
195
-
196
200
logger . info ( "Starting webserver..." , field ( "host" , flags . host ) , field ( "port" , flags . port ) ) ;
197
201
app . server . listen ( flags . port , flags . host ) ;
198
202
let clientId = 1 ;
0 commit comments