@@ -14,6 +14,37 @@ import { writeFileStringAtomically } from "./atomicWrite.ts";
1414import * as HostProcess from "./HostProcess.ts" ;
1515
1616it . layer ( NodeServices . layer ) ( "writeFileStringAtomically" , ( it ) => {
17+ for ( const hops of [ 39 , 40 , 41 ] ) {
18+ it . effect . skipIf ( HostProcess . Platform . defaultValue ( ) !== "linux" ) (
19+ `matches native file access for a chain of ${ hops } symlinks` ,
20+ ( ) =>
21+ Effect . gen ( function * ( ) {
22+ const fs = yield * FileSystem . FileSystem ;
23+ const path = yield * Path . Path ;
24+ const root = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-atomic-write-" } ) ;
25+ const destination = path . join ( root , "settings.json" ) ;
26+ const first = path . join ( root , "link-0" ) ;
27+ yield * fs . writeFileString ( destination , "before" ) ;
28+ for ( let index = hops - 1 ; index >= 0 ; index -- ) {
29+ const target = index === hops - 1 ? "settings.json" : `link-${ index + 1 } ` ;
30+ yield * fs . symlink ( target , path . join ( root , `link-${ index } ` ) ) ;
31+ }
32+
33+ const read = yield * Effect . exit ( fs . readFileString ( first ) ) ;
34+ const write = yield * Effect . exit (
35+ writeFileStringAtomically ( { filePath : first , contents : "after" } ) ,
36+ ) ;
37+
38+ assert . strictEqual ( Exit . isSuccess ( write ) , Exit . isSuccess ( read ) ) ;
39+ assert . strictEqual (
40+ yield * fs . readFileString ( destination ) ,
41+ Exit . isSuccess ( read ) ? "after" : "before" ,
42+ ) ;
43+ assert . strictEqual ( yield * fs . readLink ( first ) , "link-1" ) ;
44+ } ) ,
45+ ) ;
46+ }
47+
1748 it . effect ( "keeps a symlinked file linked and rewrites its destination" , ( ) =>
1849 Effect . gen ( function * ( ) {
1950 const fs = yield * FileSystem . FileSystem ;
0 commit comments