Skip to content

Commit b8a12cb

Browse files
authored
Fix content/contents mixup. (#81)
The correct term is actually "contents".
1 parent 558b21e commit b8a12cb

File tree

6 files changed

+72
-66
lines changed

6 files changed

+72
-66
lines changed

src/file.toit

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,10 @@ class Stream extends Object with io.CloseableInMixin io.CloseableOutMixin implem
161161
return false
162162

163163

164-
/// Deprecated. Use $read-content instead.
165-
read-contents name:
164+
/**
165+
Use $read-contents instead.
166+
*/
167+
read-content name:
166168
return read-content name
167169

168170
/**
@@ -174,7 +176,7 @@ The content is stored in an off-heap ByteArray.
174176
On small devices with a flash filesystem, simply gets a view
175177
of the underlying bytes. (Not implemented yet)
176178
*/
177-
read-content file-name/string -> ByteArray:
179+
read-contents file-name/string -> ByteArray:
178180
length := size file-name
179181
if length == 0: return #[]
180182
file := Stream.for-read file-name
@@ -194,6 +196,10 @@ read-content file-name/string -> ByteArray:
194196
finally:
195197
file.close
196198

199+
/** Use $write-contents instead. */
200+
write-content content/io.Data --path/string --permissions/int?=null -> none:
201+
write-contents content --path=path --permissions=permissions
202+
197203
/**
198204
Writes the given $content to a file of the given $path.
199205
The file must not change while it is read into memory.
@@ -202,7 +208,7 @@ If $permissions is provided uses it to set the permissions of the file.
202208
The $permissions are only used if the file is created, and not if it is
203209
overwritten.
204210
*/
205-
write-content content/io.Data --path/string --permissions/int?=null -> none:
211+
write-contents content/io.Data --path/string --permissions/int?=null -> none:
206212
stream := Stream.for-write path --permissions=permissions
207213
try:
208214
stream.out.write content

tests/chmod_test.toit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ main:
1414
expect (file.is-directory tmp-dir)
1515

1616
directory.chdir tmp-dir
17-
file.write-content "asdsd" --path="test"
17+
file.write-contents "asdsd" --path="test"
1818
try:
1919
if system.platform == system.PLATFORM-WINDOWS:
2020
file.chmod "test" file.WINDOWS-FILE-ATTRIBUTE-READONLY

tests/copy_test.toit

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,31 @@ test-recursive:
2727

2828
content := "foobar".to-byte-array
2929
other-content := "gee".to-byte-array
30-
file.write-content --path=tmp-file content
30+
file.write-contents --path=tmp-file content
3131

3232
// Copy absolute path to absolute target path.
3333
file2 := "$tmp-dir/file2.txt"
3434
file.copy --source=tmp-file --target=file2
35-
expect-equals content (file.read-content file2)
35+
expect-equals content (file.read-contents file2)
3636

3737
// Copy of relative file to relative directory path.
3838
directory.mkdir "subdir2"
3939
file.copy --source="file.txt" --target="subdir2/file.txt"
40-
expect-equals content (file.read-content "subdir2/file.txt")
41-
expect-equals content (file.read-content "$tmp-dir/subdir2/file.txt")
40+
expect-equals content (file.read-contents "subdir2/file.txt")
41+
expect-equals content (file.read-contents "$tmp-dir/subdir2/file.txt")
4242

4343
// Copy recursive.
4444
directory.mkdir "subdir2/nested-subdir"
45-
file.write-content --path="subdir2/nested-subdir/other.txt" other-content
45+
file.write-contents --path="subdir2/nested-subdir/other.txt" other-content
4646
file.copy --source="subdir2" --target="subdir3" --recursive
47-
expect-equals content (file.read-content "subdir3/file.txt")
48-
expect-equals other-content (file.read-content "subdir3/nested-subdir/other.txt")
47+
expect-equals content (file.read-contents "subdir3/file.txt")
48+
expect-equals other-content (file.read-contents "subdir3/nested-subdir/other.txt")
4949

5050
// Copy recursive to existing directory.
5151
directory.mkdir "subdir4"
5252
file.copy --source="subdir3" --target="subdir4" --recursive
53-
expect-equals content (file.read-content "subdir4/file.txt")
54-
expect-equals other-content (file.read-content "subdir4/nested-subdir/other.txt")
53+
expect-equals content (file.read-contents "subdir4/file.txt")
54+
expect-equals other-content (file.read-contents "subdir4/nested-subdir/other.txt")
5555

5656
test-permissions:
5757
file-permission0/int := ?
@@ -73,7 +73,7 @@ test-permissions:
7373

7474
with-tmp-dir: | tmp-dir |
7575
file1 := "$tmp-dir/file1.txt"
76-
file.write-content --path=file1 "foobar"
76+
file.write-contents --path=file1 "foobar"
7777

7878
file.chmod file1 file-permission0
7979
file.copy --source=file1 --target="$tmp-dir/file2.txt"
@@ -87,31 +87,31 @@ test-permissions:
8787
directory.mkdir dir
8888

8989
file-in-dir := "$tmp-dir/dir/file.txt"
90-
file.write-content --path=file-in-dir "gee"
90+
file.write-contents --path=file-in-dir "gee"
9191

9292
file.chmod dir dir-permission
9393
file.copy --source=dir --target="$tmp-dir/dir2" --recursive
9494
expect-equals dir-permission (file.stat "$tmp-dir/dir2")[file.ST-MODE]
95-
expect-equals "gee".to-byte-array (file.read-content "$tmp-dir/dir2/file.txt")
95+
expect-equals "gee".to-byte-array (file.read-contents "$tmp-dir/dir2/file.txt")
9696

9797
// Note that the directory doesn't allow writing.
9898
// This means that the copy operation must temporarily lift that restriction to copy the
9999
// nested file.
100100
file.chmod dir read-only-dir-permission
101101
file.copy --source=dir --target="$tmp-dir/dir3" --recursive
102102
expect-equals read-only-dir-permission (file.stat "$tmp-dir/dir3")[file.ST-MODE]
103-
expect-equals "gee".to-byte-array (file.read-content "$tmp-dir/dir2/file.txt")
103+
expect-equals "gee".to-byte-array (file.read-contents "$tmp-dir/dir2/file.txt")
104104

105105
test-symlinks:
106106
with-tmp-dir: | tmp-dir |
107107
file-target := "$tmp-dir/file.txt"
108108
file-content := "foobar".to-byte-array
109-
file.write-content --path=file-target file-content
109+
file.write-contents --path=file-target file-content
110110
dir-target := "$tmp-dir/dir"
111111
directory.mkdir dir-target
112112
dir-file := "$dir-target/file.txt"
113113
dir-file-content := "gee".to-byte-array
114-
file.write-content --path=dir-file dir-file-content
114+
file.write-contents --path=dir-file dir-file-content
115115

116116
source-dir := "$tmp-dir/source"
117117
directory.mkdir source-dir
@@ -125,39 +125,39 @@ test-symlinks:
125125

126126
copy-target := "$tmp-dir/copy-target-symlink"
127127
file.copy --source=source-dir --target=copy-target --recursive
128-
expect-equals file-content (file.read-content "$copy-target/relative-link")
129-
expect-equals file-content (file.read-content "$copy-target/absolute-link")
128+
expect-equals file-content (file.read-contents "$copy-target/relative-link")
129+
expect-equals file-content (file.read-contents "$copy-target/absolute-link")
130130
// Change the original file.
131131
// Since the copy is still a link we expect the content to change.
132132
file-content2 := "foobar2".to-byte-array
133-
file.write-content --path=file-target file-content2
134-
expect-equals file-content2 (file.read-content "$copy-target/relative-link")
135-
expect-equals file-content2 (file.read-content "$copy-target/absolute-link")
133+
file.write-contents --path=file-target file-content2
134+
expect-equals file-content2 (file.read-contents "$copy-target/relative-link")
135+
expect-equals file-content2 (file.read-contents "$copy-target/absolute-link")
136136
expect (is-link "$copy-target/relative-link")
137137
expect (is-link "$copy-target/absolute-link")
138138

139-
expect-equals dir-file-content (file.read-content "$copy-target/relative-dir/file.txt")
140-
expect-equals dir-file-content (file.read-content "$copy-target/absolute-dir/file.txt")
139+
expect-equals dir-file-content (file.read-contents "$copy-target/relative-dir/file.txt")
140+
expect-equals dir-file-content (file.read-contents "$copy-target/absolute-dir/file.txt")
141141
// Change the original file.
142142
// Since the copy is still a link we expect the content to change.
143143
dir-file-content2 := "gee2".to-byte-array
144-
file.write-content --path=dir-file dir-file-content2
145-
expect-equals dir-file-content2 (file.read-content "$copy-target/relative-dir/file.txt")
146-
expect-equals dir-file-content2 (file.read-content "$copy-target/absolute-dir/file.txt")
144+
file.write-contents --path=dir-file dir-file-content2
145+
expect-equals dir-file-content2 (file.read-contents "$copy-target/relative-dir/file.txt")
146+
expect-equals dir-file-content2 (file.read-contents "$copy-target/absolute-dir/file.txt")
147147
expect (is-link "$copy-target/relative-dir")
148148
expect (is-link "$copy-target/absolute-dir")
149149

150150
// Dereference links.
151151
copy-target = "$tmp-dir/copy-target-dereference"
152152

153153
file.copy --source=source-dir --target=copy-target --recursive --dereference
154-
expect-equals file-content2 (file.read-content "$copy-target/relative-link")
155-
expect-equals file-content2 (file.read-content "$copy-target/absolute-link")
154+
expect-equals file-content2 (file.read-contents "$copy-target/relative-link")
155+
expect-equals file-content2 (file.read-contents "$copy-target/absolute-link")
156156
expect-not (is-link "$copy-target/relative-link")
157157
expect-not (is-link "$copy-target/absolute-link")
158158

159-
expect-equals dir-file-content2 (file.read-content "$copy-target/relative-dir/file.txt")
160-
expect-equals dir-file-content2 (file.read-content "$copy-target/absolute-dir/file.txt")
159+
expect-equals dir-file-content2 (file.read-contents "$copy-target/relative-dir/file.txt")
160+
expect-equals dir-file-content2 (file.read-contents "$copy-target/absolute-dir/file.txt")
161161
expect-not (is-link "$copy-target/relative-dir")
162162
expect-not (is-link "$copy-target/absolute-dir")
163163

@@ -168,23 +168,23 @@ test-symlinks:
168168
file.copy --source=source-dir --target=copy-target --recursive
169169

170170
// Absolute links still work.
171-
expect-equals file-content2 (file.read-content "$copy-target/absolute-link")
171+
expect-equals file-content2 (file.read-contents "$copy-target/absolute-link")
172172
expect (is-link "$copy-target/absolute-link")
173-
expect-equals dir-file-content2 (file.read-content "$copy-target/absolute-dir/file.txt")
173+
expect-equals dir-file-content2 (file.read-contents "$copy-target/absolute-dir/file.txt")
174174
expect (is-link "$copy-target/absolute-dir")
175175

176-
expect-throws: file.read-content "$copy-target/relative-link"
176+
expect-throws: file.read-contents "$copy-target/relative-link"
177177
expect (is-link "$copy-target/relative-link")
178-
expect-throws: file.read-content "$copy-target/relative-dir/file.txt"
178+
expect-throws: file.read-contents "$copy-target/relative-dir/file.txt"
179179
expect (is-link "$copy-target/relative-dir")
180180

181181
// Create the target.
182-
file.write-content --path="$tmp-dir/other/file.txt" file-content
182+
file.write-contents --path="$tmp-dir/other/file.txt" file-content
183183
directory.mkdir "$tmp-dir/other/dir"
184-
file.write-content --path="$tmp-dir/other/dir/file.txt" dir-file-content
184+
file.write-contents --path="$tmp-dir/other/dir/file.txt" dir-file-content
185185
// Now the symlinks work again.
186-
expect-equals file-content (file.read-content "$copy-target/relative-link")
187-
expect-equals dir-file-content (file.read-content "$copy-target/relative-dir/file.txt")
186+
expect-equals file-content (file.read-contents "$copy-target/relative-link")
187+
expect-equals dir-file-content (file.read-contents "$copy-target/relative-dir/file.txt")
188188

189189
is-link path/string -> bool:
190190
stat := file.stat path --no-follow-links

tests/file_test.toit

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ main:
7070
test-out.out.close
7171

7272
10000.repeat:
73-
file.read-content filename
73+
file.read-contents filename
7474

75-
read-back := (file.read-content filename).to-string
75+
read-back := (file.read-contents filename).to-string
7676

7777
expect-equals test-contents read-back
7878

@@ -86,7 +86,7 @@ main:
8686
test-out.out.close
8787
expect-equals
8888
ByteArray 0
89-
file.read-content filename
89+
file.read-contents filename
9090
finally:
9191
file.delete filename
9292

@@ -100,7 +100,7 @@ main:
100100
test-out.out.write test-contents from to
101101
test-out.out.close
102102

103-
read-back := (file.read-content filename).to-string
103+
read-back := (file.read-contents filename).to-string
104104

105105
expect-equals (test-contents.copy from to) read-back
106106

@@ -112,8 +112,8 @@ main:
112112
expect (not file.size filename)
113113

114114
try:
115-
file.write-content test-contents --path=filename
116-
read-back := (file.read-content filename).to-string
115+
file.write-contents test-contents --path=filename
116+
read-back := (file.read-contents filename).to-string
117117
expect-equals test-contents read-back
118118
finally:
119119
file.delete filename
@@ -123,8 +123,8 @@ main:
123123
// Permissions does not quite work on windows
124124
if platform != PLATFORM-WINDOWS:
125125
try:
126-
file.write-content test-contents --path=filename --permissions=(6 << 6)
127-
read-back := (file.read-content filename).to-string
126+
file.write-contents test-contents --path=filename --permissions=(6 << 6)
127+
read-back := (file.read-contents filename).to-string
128128
expect-equals test-contents read-back
129129
stats := file.stat filename
130130
// We can't require that the permissions are exactly the same (as the umask

tests/link_test.toit

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ main:
1616
expect (file.is-directory tmp-dir)
1717

1818
directory.chdir tmp-dir
19-
file.write-content CONTENT --path="test-file"
20-
expect-equals CONTENT.to-byte-array (file.read-content "test-file")
19+
file.write-contents CONTENT --path="test-file"
20+
expect-equals CONTENT.to-byte-array (file.read-contents "test-file")
2121
directory.mkdir "test-dir"
2222

2323
try:
@@ -39,8 +39,8 @@ main:
3939
expect-equals dir-stat (file.stat "test-dir-soft-link")
4040
expect-not-equals dir-stat (file.stat --follow-links=false "test-dir-soft-link")
4141

42-
expect-equals CONTENT.to-byte-array (file.read-content "test-file-hard-link")
43-
expect-equals CONTENT.to-byte-array (file.read-content "test-file-soft-link")
42+
expect-equals CONTENT.to-byte-array (file.read-contents "test-file-hard-link")
43+
expect-equals CONTENT.to-byte-array (file.read-contents "test-file-soft-link")
4444

4545
// Test that we can't auto detect link type if the target does not exist.
4646
expect-throw "TARGET_NOT_FOUND": file.link --source="test-file" --target="test-file-that-does-not-exist"
@@ -53,33 +53,33 @@ main:
5353
expect-equals "relative-soft-name" (file.readlink "test-dir/relative")
5454
file.link --file --source="test-dir/relative-soft-name" --target="..$(directory.SEPARATOR)test-file"
5555
expect-equals "..$(directory.SEPARATOR)test-file" (file.readlink "test-dir/relative-soft-name")
56-
expect-equals CONTENT.to-byte-array (file.read-content "test-dir/relative")
56+
expect-equals CONTENT.to-byte-array (file.read-contents "test-dir/relative")
5757

5858
// Test that hardlinks are always relative to cwd.
5959
file.link --hard --source="test-dir/relative-hard" --target="test-file"
60-
expect-equals CONTENT.to-byte-array (file.read-content "test-dir/relative-hard")
60+
expect-equals CONTENT.to-byte-array (file.read-contents "test-dir/relative-hard")
6161

6262
// Test that hard-links behaves as hard-link and soft-link behaves as soft-links.
6363
file.delete "test-file"
64-
expect-equals CONTENT.to-byte-array (file.read-content "test-file-hard-link")
65-
expect-throw "FILE_NOT_FOUND: \"test-file-soft-link\"" : file.read-content "test-file-soft-link"
64+
expect-equals CONTENT.to-byte-array (file.read-contents "test-file-hard-link")
65+
expect-throw "FILE_NOT_FOUND: \"test-file-soft-link\"" : file.read-contents "test-file-soft-link"
6666

6767
new-content := "new-content".to-byte-array
68-
file.write-content new-content --path="test-file"
68+
file.write-contents new-content --path="test-file"
6969

7070
// Test relative links that isn't relative to the current directory.
7171
subdir := "$tmp-dir/subdir"
7272
directory.mkdir subdir
7373
file.link --file --source="$subdir/relative-link" --target="../test-file"
74-
expect-equals new-content (file.read-content "$subdir/relative-link")
74+
expect-equals new-content (file.read-contents "$subdir/relative-link")
7575
file.link --source="$subdir/relative-link2" --target="../test-file"
76-
expect-equals new-content (file.read-content "$subdir/relative-link2")
76+
expect-equals new-content (file.read-contents "$subdir/relative-link2")
7777

7878
// Same for directories.
7979
file.link --directory --source="$subdir/relative-dir-link" --target=".."
80-
expect-equals new-content (file.read-content "$subdir/relative-dir-link/test-file")
80+
expect-equals new-content (file.read-contents "$subdir/relative-dir-link/test-file")
8181
file.link --source="$subdir/relative-dir-link2" --target=".."
82-
expect-equals new-content (file.read-content "$subdir/relative-dir-link2/test-file")
82+
expect-equals new-content (file.read-contents "$subdir/relative-dir-link2/test-file")
8383

8484
finally:
8585
directory.rmdir tmp-dir --recursive

tests/mkdir_rmdir_test.toit

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ main:
5959
// Test permissions.
6060
dir0 := "$tmp-dir/perm0"
6161
mkdir dir0
62-
file.write-content --path="$dir0/file1" "content"
62+
file.write-contents --path="$dir0/file1" "content"
6363
dir1 := "$dir0/perm1"
6464
mkdir dir1
65-
file.write-content --path="$dir1/file" "content"
65+
file.write-contents --path="$dir1/file" "content"
6666

6767
old-stat0 := file.stat dir0
6868
old-stat1 := file.stat dir1
@@ -82,7 +82,7 @@ main:
8282
// Test symbolic link.
8383
sym-file-target := "$tmp-dir/sym-file-target"
8484
sym-dir-target := "$tmp-dir/sym-dir-target"
85-
file.write-content --path=sym-file-target "content"
85+
file.write-contents --path=sym-file-target "content"
8686
mkdir sym-dir-target
8787

8888
sub-dir := "$tmp-dir/sub-dir"

0 commit comments

Comments
 (0)