Skip to content

Commit 761fba8

Browse files
committed
FIX: QUERY directory size now returns NONE instead of 0
fixes: Oldes/Rebol-issues#2305
1 parent 798b06d commit 761fba8

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

src/core/p-file.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@
106106
{
107107
switch (mode) {
108108
case SYM_SIZE:
109-
SET_INTEGER(ret, file->file.size);
109+
if(file->file.size == MIN_I64) {
110+
SET_NONE(ret);
111+
} else {
112+
SET_INTEGER(ret, file->file.size);
113+
}
110114
break;
111115
case SYM_TYPE:
112116
Init_Word(ret, GET_FLAG(file->modes, RFM_DIR) ? SYM_DIR : SYM_FILE);

src/os/posix/dev-file.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ static int Get_File_Info(REBREQ *file)
132132

133133
if (S_ISDIR(info.st_mode)) {
134134
SET_FLAG(file->modes, RFM_DIR);
135-
file->file.size = 0; // in order to be consistent on all systems
135+
file->file.size = MIN_I64; // using MIN_I64 to notify, that size should be reported as NONE
136136
}
137137
else {
138138
CLR_FLAG(file->modes, RFM_DIR);

src/os/win32/dev-file.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ static BOOL Seek_File_64(REBREQ *file)
408408

409409
if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
410410
SET_FLAG(file->modes, RFM_DIR);
411-
file->file.size = 0;
411+
file->file.size = MIN_I64; // using MIN_I64 to notify, that size should be reported as NONE
412412
}
413413
else {
414414
CLR_FLAG(file->modes, RFM_DIR);

src/tests/units/port-test.r3

+6-8
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Rebol [
4343
--assert 'dir = query/mode %. 'type
4444
--assert date? query/mode %. 'date
4545
--assert what-dir = query/mode %. 'name
46+
;@@ https://github.com/Oldes/Rebol-issues/issues/2305
47+
--assert none? query/mode %. 'size
4648
===end-group===
4749

4850
===start-group=== "file port"
@@ -84,6 +86,10 @@ Rebol [
8486
--assert string? try [read http://google.com]
8587
--test-- "read HTTPS"
8688
--assert string? try [read https://www.google.com]
89+
--test-- "exists? url"
90+
;@@ https://github.com/Oldes/Rebol3/issues/14
91+
--assert exists? http://httpbin.org/
92+
--assert not exists? http://httpbin.org/not-exists
8793
===end-group===
8894

8995

@@ -116,14 +122,6 @@ if "true" <> get-env "CONTINUOUS_INTEGRATION" [
116122
--assert block? v: query/mode system/ports/input m
117123
--assert 4 = length? v
118124
===end-group===
119-
120-
===start-group=== "HTTP"
121-
--test-- "exists? url"
122-
;@@ https://github.com/Oldes/Rebol3/issues/14
123-
--assert exists? http://httpbin.org/
124-
--assert not exists? http://httpbin.org/not-exists
125-
126-
===end-group===
127125
]
128126

129127
~~~end-file~~~

0 commit comments

Comments
 (0)