Skip to content

Commit 9c72f2b

Browse files
authored
Avoid leaking with directories. (#9)
Forward port. Requires a recent Toit version.
1 parent b3b60e7 commit 9c72f2b

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.packages/

package.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# Toit Lock File.
1+
sdk: ^1.6.10

package.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
# Toit Package File.
1+
environment:
2+
sdk: ^1.6.10

src/directory.toit

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ chdir name:
8383

8484
// An open directory, used to iterate over the named entries in a directory.
8585
class DirectoryStream:
86-
fd_ := ?
86+
dir_ := ?
8787

8888
constructor name:
89-
fd_ = opendir_ name
89+
dir_ = opendir_ resource_freeing_module_ name
9090

9191
/**
9292
Returns a string with the next name from the directory.
@@ -95,18 +95,19 @@ class DirectoryStream:
9595
*/
9696
next -> string?:
9797
while true:
98-
byte_array := readdir_ fd_
98+
byte_array := readdir_ dir_
9999
if not byte_array: return null
100100
str := byte_array.to_string
101101
if str == "." or str == "..": continue
102102
return str
103103

104104
close -> none:
105-
fd := fd_
106-
closedir_ fd
105+
if dir_:
106+
closedir_ dir_
107+
dir_ = null
107108

108-
opendir_ name:
109-
#primitive.file.opendir
109+
opendir_ resource_group name:
110+
#primitive.file.opendir2
110111

111112
readdir_ dir -> ByteArray:
112113
#primitive.file.readdir

0 commit comments

Comments
 (0)