@@ -6,40 +6,40 @@ internal struct MemoryDirEntry: WASIDir {
66 let dirNode : MemoryDirectoryNode
77 let path : String
88 let fileSystem : MemoryFileSystem
9-
9+
1010 func attributes( ) throws -> WASIAbi . Filestat {
1111 return WASIAbi . Filestat (
1212 dev: 0 , ino: 0 , filetype: . DIRECTORY,
1313 nlink: 1 , size: 0 ,
1414 atim: 0 , mtim: 0 , ctim: 0
1515 )
1616 }
17-
17+
1818 func fileType( ) throws -> WASIAbi . FileType {
1919 return . DIRECTORY
2020 }
21-
21+
2222 func status( ) throws -> WASIAbi . Fdflags {
2323 return [ ]
2424 }
25-
25+
2626 func setTimes(
2727 atim: WASIAbi . Timestamp , mtim: WASIAbi . Timestamp ,
2828 fstFlags: WASIAbi . FstFlags
2929 ) throws {
3030 // No-op for memory filesystem - timestamps not tracked
3131 }
32-
32+
3333 func advise(
3434 offset: WASIAbi . FileSize , length: WASIAbi . FileSize , advice: WASIAbi . Advice
3535 ) throws {
3636 // No-op for memory filesystem
3737 }
38-
38+
3939 func close( ) throws {
4040 // No-op for memory filesystem - no resources to release
4141 }
42-
42+
4343 func openFile(
4444 symlinkFollow: Bool ,
4545 path: String ,
@@ -51,39 +51,39 @@ internal struct MemoryDirEntry: WASIDir {
5151 // File opening is handled through the WASI bridge's path_open implementation
5252 throw WASIAbi . Errno. ENOTSUP
5353 }
54-
54+
5555 func createDirectory( atPath path: String ) throws {
5656 let fullPath = self . path. hasSuffix ( " / " ) ? self . path + path : self . path + " / " + path
5757 try fileSystem. ensureDirectory ( at: fullPath)
5858 }
59-
59+
6060 func removeDirectory( atPath path: String ) throws {
6161 try fileSystem. removeNode ( in: dirNode, at: path, mustBeDirectory: true )
6262 }
63-
63+
6464 func removeFile( atPath path: String ) throws {
6565 try fileSystem. removeNode ( in: dirNode, at: path, mustBeDirectory: false )
6666 }
67-
67+
6868 func symlink( from sourcePath: String , to destPath: String ) throws {
6969 // Symlinks not supported in memory filesystem
7070 throw WASIAbi . Errno. ENOTSUP
7171 }
72-
72+
7373 func rename( from sourcePath: String , toDir newDir: any WASIDir , to destPath: String ) throws {
7474 guard let newMemoryDir = newDir as? MemoryDirEntry else {
7575 throw WASIAbi . Errno. EXDEV
7676 }
77-
77+
7878 try fileSystem. rename (
7979 from: sourcePath, in: dirNode,
8080 to: destPath, in: newMemoryDir. dirNode
8181 )
8282 }
83-
83+
8484 func readEntries( cookie: WASIAbi . DirCookie ) throws -> AnyIterator < Result < ReaddirElement , any Error > > {
8585 let children = dirNode. listChildren ( )
86-
86+
8787 let iterator = children. enumerated ( )
8888 . dropFirst ( Int ( cookie) )
8989 . map { ( index, name) -> Result < ReaddirElement , any Error > in
@@ -92,38 +92,38 @@ internal struct MemoryDirEntry: WASIDir {
9292 guard let childNode = fileSystem. lookup ( at: childPath) else {
9393 throw WASIAbi . Errno. ENOENT
9494 }
95-
95+
9696 let fileType : WASIAbi . FileType
9797 switch childNode. type {
9898 case . directory: fileType = . DIRECTORY
9999 case . file: fileType = . REGULAR_FILE
100100 case . characterDevice: fileType = . CHARACTER_DEVICE
101101 }
102-
102+
103103 let dirent = WASIAbi . Dirent (
104104 dNext: WASIAbi . DirCookie ( index + 1 ) ,
105105 dIno: 0 ,
106106 dirNameLen: WASIAbi . DirNameLen ( name. utf8. count) ,
107107 dType: fileType
108108 )
109-
109+
110110 return ( dirent, name)
111111 } )
112112 }
113113 . makeIterator ( )
114-
114+
115115 return AnyIterator ( iterator)
116116 }
117-
117+
118118 func attributes( path: String , symlinkFollow: Bool ) throws -> WASIAbi . Filestat {
119119 let fullPath = self . path. hasSuffix ( " / " ) ? self . path + path : self . path + " / " + path
120120 guard let node = fileSystem. lookup ( at: fullPath) else {
121121 throw WASIAbi . Errno. ENOENT
122122 }
123-
123+
124124 let fileType : WASIAbi . FileType
125125 var size : WASIAbi . FileSize = 0
126-
126+
127127 switch node. type {
128128 case . directory:
129129 fileType = . DIRECTORY
@@ -135,19 +135,19 @@ internal struct MemoryDirEntry: WASIDir {
135135 case . characterDevice:
136136 fileType = . CHARACTER_DEVICE
137137 }
138-
138+
139139 return WASIAbi . Filestat (
140140 dev: 0 , ino: 0 , filetype: fileType,
141141 nlink: 1 , size: size,
142142 atim: 0 , mtim: 0 , ctim: 0
143143 )
144144 }
145-
145+
146146 func setFilestatTimes(
147147 path: String ,
148148 atim: WASIAbi . Timestamp , mtim: WASIAbi . Timestamp ,
149149 fstFlags: WASIAbi . FstFlags , symlinkFollow: Bool
150150 ) throws {
151151 // No-op for memory filesystem - timestamps not tracked
152152 }
153- }
153+ }
0 commit comments