File tree 3 files changed +26
-9
lines changed
3 files changed +26
-9
lines changed Original file line number Diff line number Diff line change @@ -638,6 +638,7 @@ REBINT Mode_Syms[] = {
638
638
DECIDE (file -> file .index > file -> file .size );
639
639
640
640
case A_CLEAR :
641
+ if (!IS_OPEN (file )) Trap1 (RE_NOT_OPEN , path );
641
642
// !! check for write enabled?
642
643
SET_FLAG (file -> modes , RFM_RESEEK );
643
644
SET_FLAG (file -> modes , RFM_TRUNCATE );
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ exists?: func [
28
28
29
29
size? : func [
30
30
{Returns the size of a file or vector (bits per value).}
31
- target [file! url! vector! ]
31
+ target [file! url! port! vector! ]
32
32
] [
33
33
query /mode target 'size
34
34
]
Original file line number Diff line number Diff line change @@ -353,15 +353,31 @@ if system/platform = 'Windows [
353
353
]
354
354
try [delete %file-552 ]
355
355
356
- --test-- "clear file port"
356
+ --test-- "CLEAR file port"
357
357
;@@ https://github.com/Oldes/Rebol-issues/issues/812
358
- --assert file? write %file-812 to-binary "Hello World!"
359
- --assert port? f: open %file-812
360
- --assert "Hello World!" = to-string read f
361
- --assert port? clear f
362
- --assert 0 = length? f
363
- --assert port? close f
364
- try [delete %file-812 ]
358
+ --assert all [
359
+ file? write %file-812 "Hello World!"
360
+ port? f: open %file-812
361
+ "Hello World!" = read /string f
362
+ port? clear f ; this actually does not clear the file as we are at the end of the stream
363
+ 0 = length? f
364
+ "Hello" = read /seek/string/part f 0 5
365
+ 7 = length? f
366
+ port? clear f ; this should truncate the file
367
+ 0 = length? f
368
+ port? close f
369
+ 5 = length? f ; because there is still "Hello" left
370
+ all [
371
+ error? e: try [clear f]
372
+ e/id = 'not-open
373
+ ]
374
+ port? f: open %file-812
375
+ port? clear f ; this should clear the file completely, because the position is at its head
376
+ port? close f
377
+ 0 = size? %file-812
378
+ not error? try [delete %file-812 ]
379
+ ]
380
+
365
381
366
382
--test-- "RENAME file"
367
383
;@@ https://github.com/Oldes/Rebol-issues/issues/446
You can’t perform that action at this time.
0 commit comments