@@ -86,8 +86,7 @@ export const ensurePinnedRuntimeInstalled = Effect.fn("cloud.pinned_runtime.ensu
8686 } ) {
8787 const { fs, runner } = input ;
8888 const paths = pinnedRuntimePaths ( input . path , input . baseDir , input . version ) ;
89- const [ versionDirExists , entryExists , sentinel ] = yield * Effect . all ( [
90- fs . exists ( paths . versionDir ) ,
89+ const [ entryExists , sentinel ] = yield * Effect . all ( [
9190 fs . exists ( paths . entryPath ) ,
9291 fs . readFileString ( paths . sentinelPath ) . pipe ( Effect . option ) ,
9392 ] ) . pipe (
@@ -97,32 +96,11 @@ export const ensurePinnedRuntimeInstalled = Effect.fn("cloud.pinned_runtime.ensu
9796 ) ;
9897 const alreadyPinned =
9998 entryExists && Option . isSome ( sentinel ) && sentinel . value . trim ( ) === input . version ;
100- if ( versionDirExists && ! alreadyPinned ) {
101- yield * fs . remove ( paths . versionDir , { recursive : true , force : true } ) . pipe (
102- Effect . mapError (
103- ( cause ) =>
104- new PinnedRuntimeInstallError ( {
105- step : "removing an incomplete pinned runtime" ,
106- cause,
107- } ) ,
108- ) ,
109- ) ;
110- }
11199 if ( alreadyPinned ) {
112100 const valid = yield * input . validate ( paths ) . pipe (
113101 Effect . as ( true ) ,
114102 Effect . catchTags ( {
115- PinnedRuntimeInstallError : ( ) =>
116- fs . remove ( paths . versionDir , { recursive : true , force : true } ) . pipe (
117- Effect . mapError (
118- ( cause ) =>
119- new PinnedRuntimeInstallError ( {
120- step : "removing an invalid pinned runtime" ,
121- cause,
122- } ) ,
123- ) ,
124- Effect . as ( false ) ,
125- ) ,
103+ PinnedRuntimeInstallError : ( ) => Effect . succeed ( false ) ,
126104 } ) ,
127105 ) ;
128106 if ( valid ) return paths ;
@@ -196,6 +174,16 @@ export const ensurePinnedRuntimeInstalled = Effect.fn("cloud.pinned_runtime.ensu
196174 new PinnedRuntimeInstallError ( { step : "recording the completed install" , cause } ) ,
197175 ) ,
198176 ) ;
177+ // Keep the old path intact until its replacement is ready. Concurrent
178+ // publishers may replace each other, but never leave no valid runtime.
179+ yield * fs
180+ . remove ( paths . versionDir , { recursive : true , force : true } )
181+ . pipe (
182+ Effect . mapError (
183+ ( cause ) =>
184+ new PinnedRuntimeInstallError ( { step : "replacing the pinned runtime" , cause } ) ,
185+ ) ,
186+ ) ;
199187 yield * fs
200188 . rename ( stagingDir , paths . versionDir )
201189 . pipe (
0 commit comments