Skip to content

Commit 2d1a66b

Browse files
committed
FIX: exists %/ must return true and not none
fixes: Oldes/Rebol-issues#2317 related to: Oldes/Rebol-issues#2031
1 parent db54adb commit 2d1a66b

File tree

6 files changed

+43
-7
lines changed

6 files changed

+43
-7
lines changed

src/core/p-dir.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@
6161
dir->data = (REBYTE*)(&file);
6262

6363
#ifdef TO_WINDOWS
64-
REBCHR *cp = file.file.path;
65-
if (cp[0] == '/' && cp[1] == 0) {
64+
if (dir->file.path[0] == 0) {
6665
// special case: reading drive letters -> read %/
6766
// https://github.com/Oldes/Rebol-issues/issues/2031
6867
SET_FLAG(dir->modes, RFM_DRIVES);
@@ -180,6 +179,7 @@
180179

181180
Secure_Port(SYM_FILE, dir, path, ser);
182181

182+
if (len == 0) return;
183183
if (len == 1 && dir->file.path[0] == '.') {
184184
if (wild > 0) {
185185
dir->file.path[0] = '*';
@@ -346,7 +346,7 @@
346346
return R_RET;
347347
}
348348
SET_NONE(state);
349-
Init_Dir_Path(&dir, path, -1, REMOVE_TAIL_SLASH | POL_READ);
349+
Init_Dir_Path(&dir, path, -1, POL_READ);
350350
if (OS_DO_DEVICE(&dir, RDC_QUERY) < 0) return R_NONE;
351351
Ret_Query_File(port, &dir, D_RET, D_ARG(ARG_QUERY_FIELD));
352352
///OS_FREE(dir.file.path);

src/core/p-file.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,12 @@
9191
***********************************************************************/
9292
{
9393
REBOL_DAT dat;
94-
95-
OS_FILE_TIME(file, &dat);
96-
Set_Date(val, &dat);
94+
if (file->file.time.h == 0 && file->file.time.l == 0) {
95+
SET_NONE(val);
96+
} else {
97+
OS_FILE_TIME(file, &dat);
98+
Set_Date(val, &dat);
99+
}
97100
}
98101

99102
/***********************************************************************

src/core/s-file.c

+6
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@
142142
dst = Make_Unicode(len+FN_PAD);
143143
out = UNI_HEAD(dst);
144144
#ifdef TO_WINDOWS
145+
if (len == 1) {
146+
// it was really just: %/
147+
// so return empty string in such a case
148+
goto term_out;
149+
}
145150
i++;
146151
if (i < len) {
147152
c = GET_CHAR_UNI(uni, bp, i);
@@ -223,6 +228,7 @@
223228
out[n++] = c;
224229
}
225230
}
231+
term_out:
226232
out[n] = 0;
227233
SERIES_TAIL(dst) = n;
228234
// TERM_SERIES(dst);

src/os/win32/dev-file.c

+13
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,19 @@ static BOOL Seek_File_64(REBREQ *file)
412412
WIN32_FILE_ATTRIBUTE_DATA info;
413413

414414
if (!GetFileAttributesEx(file->file.path, GetFileExInfoStandard, &info)) {
415+
if (file->file.path[0] == 0) {
416+
// special case: query %/
417+
// report it still as a dir...
418+
SET_FLAG(file->modes, RFM_DIR);
419+
// but without size and date
420+
file->file.size = MIN_I64;
421+
file->file.time.l = 0;
422+
file->file.time.h = 0;
423+
// put back removed slash
424+
file->file.path[0] = '/';
425+
file->file.path[1] = 0;
426+
return DR_DONE;
427+
}
415428
file->error = GetLastError();
416429
return DR_ERROR;
417430
}

src/os/win32/host-lib.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ static void *Task_Ready;
630630
**
631631
***********************************************************************/
632632
{
633-
return SetCurrentDirectory(path);
633+
return SetCurrentDirectory( path[0]==0 ? L"\\" : path );
634634
}
635635

636636

src/tests/units/port-test.r3

+14
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,20 @@ if system/platform = 'Windows [
6767
#"/" = last drives/1
6868
]
6969
]
70+
--test-- "exists? %/"
71+
;@@ https://github.com/Oldes/Rebol-issues/issues/2317
72+
--assert exists? %/
73+
--assert object? info: query %/
74+
--assert info/name = %/
75+
--assert info/type = 'dir
76+
--assert none? info/size
77+
either system/platform = 'Windows [
78+
--assert none? info/date
79+
][
80+
; on linux %/ is just a normal directory root
81+
--assert date? info/date
82+
]
83+
7084

7185
===end-group===
7286

0 commit comments

Comments
 (0)