@@ -9,7 +9,6 @@ export enum VersionStatus {
9
9
Fetching ,
10
10
Fetched ,
11
11
Loading ,
12
- Extracting ,
13
12
Loaded ,
14
13
}
15
14
@@ -31,7 +30,7 @@ export class ByondService {
31
30
this . _versions . delete ( version . toString ( ) ) ;
32
31
await this . commandQueueService . runToCompletion (
33
32
'/bin/rm' ,
34
- `-rf\0/var/lib/byond/${ version } .zip\0/var/lib /byond/${ version } ` ,
33
+ `-rf\0/var/lib/byond/${ version } .zip\0/mnt/host /byond/${ version } ` ,
35
34
) ;
36
35
if ( this . _activeVersion === version ) this . _activeVersion = null ;
37
36
} ) ;
@@ -41,38 +40,51 @@ export class ByondService {
41
40
public get versions ( ) : ReadonlyMap < string , VersionStatus > {
42
41
return this . _versions ;
43
42
}
44
- public setActive = this . lock . wrap ( async ( version : string ) => {
43
+
44
+ public load = this . lock . wrap ( async ( version : string , setActive ?: boolean ) => {
45
+ setActive ??= true ;
46
+
45
47
const status = this . _versions . get ( version ) ;
46
48
if ( status == null || status < VersionStatus . Fetched ) return ;
47
49
50
+ let destination = `/mnt/host/byond/${ version } ` ;
48
51
if ( status < VersionStatus . Loaded ) {
52
+ if ( setActive ) {
53
+ destination = '/var/lib/byond_staging' ;
54
+ }
49
55
try {
50
56
this . _versions . set ( version , VersionStatus . Loading ) ;
51
57
const zipFile = await this . getVersion ( version , true ) ;
52
58
await this . emulatorService . sendFile (
53
59
`byond/${ version } .zip` ,
54
60
new Uint8Array ( await zipFile . arrayBuffer ( ) ) ,
55
61
) ;
56
- this . _versions . set ( version , VersionStatus . Extracting ) ;
57
- await this . commandQueueService . runToSuccess (
58
- '/bin/unzip' ,
59
- `/mnt/host/byond/${ version } .zip\0byond/bin*\0-j\0-d\0/var/lib/byond/${ version } ` ,
60
- ) ;
61
- await this . commandQueueService . runToSuccess (
62
- '/bin/rm' ,
63
- `/mnt/host/byond/${ version } .zip` ,
64
- ) ;
62
+ await this . commandQueueService . runToSuccess ( [
63
+ `/bin/unzip /mnt/host/byond/${ version } .zip 'byond/bin*' -j -d ${ destination } ` ,
64
+ `/bin/rm /mnt/host/byond/${ version } .zip` ,
65
+ ] ) ;
65
66
this . _versions . set ( version , VersionStatus . Loaded ) ;
66
- this . _activeVersion = version ;
67
67
} catch ( e ) {
68
68
this . _versions . set ( version , VersionStatus . Fetched ) ;
69
69
await this . commandQueueService . runToCompletion (
70
70
'/bin/rm' ,
71
- `-rf\0/var/lib/byond/ ${ version } .zip\0/var/lib/byond/ ${ version } ` ,
71
+ `-rf\0${ destination } ` ,
72
72
) ;
73
73
throw e ;
74
74
}
75
75
}
76
+ if ( setActive ) {
77
+ if ( this . _activeVersion )
78
+ await this . commandQueueService . runToSuccess (
79
+ '/bin/mv' ,
80
+ `/var/lib/byond\0/mnt/host/byond/${ this . _activeVersion } ` ,
81
+ ) ;
82
+ await this . commandQueueService . runToSuccess (
83
+ '/bin/mv' ,
84
+ `${ destination } \0/var/lib/byond` ,
85
+ ) ;
86
+ }
87
+ this . _activeVersion = version ;
76
88
} ) ;
77
89
public getVersion = this . lock . wrap ( async ( version : string ) => {
78
90
try {
@@ -122,10 +134,7 @@ export class ByondService {
122
134
}
123
135
} ) ;
124
136
void this . lock . run ( ( ) =>
125
- commandQueueService . runToSuccess (
126
- '/bin/mkdir' ,
127
- '-p\0/mnt/host/byond\0/var/lib/byond' ,
128
- ) ,
137
+ commandQueueService . runToSuccess ( '/bin/mkdir' , '-p\0/mnt/host/byond' ) ,
129
138
) ;
130
139
}
131
140
@@ -135,8 +144,6 @@ export class ByondService {
135
144
}
136
145
137
146
public useActive < T extends ( path : string | null ) => any > ( fn : T ) {
138
- this . lock . run ( ( ) =>
139
- fn ( this . _activeVersion ? `/var/lib/byond/${ this . _activeVersion } /` : null ) ,
140
- ) ;
147
+ this . lock . run ( ( ) => fn ( this . _activeVersion ? `/var/lib/byond/` : null ) ) ;
141
148
}
142
149
}
0 commit comments