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