@@ -5,12 +5,11 @@ import ../common
5
5
import ./ pyCfg
6
6
import ../ util/ handle_signal
7
7
8
- when not InJS:
9
- importConfig [
10
- stats,
11
- os
12
- ]
13
- else :
8
+ importConfig [
9
+ stats,
10
+ os
11
+ ]
12
+ when InJS:
14
13
template decl(f, val) =
15
14
const `HAVE f` = val
16
15
decl lstat, true
@@ -31,6 +30,7 @@ import std/macros
31
30
TODO: impl our own stat... Get rid of `_wstat`
32
31
]#
33
32
33
+ const DWin = defined(windows)
34
34
when InJs:
35
35
import std/ jsffi
36
36
import ./ jsStat
@@ -75,7 +75,6 @@ when InJs:
75
75
76
76
77
77
else:
78
- const DWin = defined(windows)
79
78
when DWin:
80
79
import ../util/[
81
80
mywinlean, getFileInfo]
@@ -205,15 +204,15 @@ func to_result(s: sink Stat): stat_result =
205
204
result = stat_result(data: s)
206
205
207
206
when InJs:
208
- proc statAux(st: var Stat, path: int |PathLike ) =
207
+ proc statAux(st: var Stat, path: int |string ) =
209
208
catchJsErrAndRaise:
210
209
st =
211
210
when path is int :
212
211
fstatSync(path.cint )
213
212
else:
214
- let cs = cstring ($ path)
213
+ let cs = cstring (path)
215
214
statSync(cs)
216
- proc lstatAux (st: var Stat, fd: int ) =
215
+ proc fstatAux (st: var Stat, fd: int ) =
217
216
catchJsErrAndRaise:
218
217
st = fstatSync(fd.cint )
219
218
proc lstatAux(st: var Stat, path: PathLike) =
@@ -494,7 +493,7 @@ when DWin:
494
493
goto_cleanup
495
494
496
495
497
- proc win32_xstat_impl(path: LPCWSTR, status: var Stat, traverse: bool ): int =
496
+ proc win32_xstat_impl(path: LPCWSTR, status: var Stat, traverse: bool ): cint =
498
497
var statInfo: FILE_STAT_BASIC_INFORMATION
499
498
if Py_GetFileInformationByName(path, FileStatBasicByNameInfo, addr statInfo, sizeof(statInfo).DWORD):
500
499
if (statInfo.FileAttributes and DWORD FILE_ATTRIBUTE_REPARSE_POINT) == 0 or
@@ -513,7 +512,7 @@ when DWin:
513
512
514
513
return win32_xstat_slow_impl(path, status, traverse)
515
514
516
- proc win32_xstat(path: WideCString, status: var Stat, traverse: bool ): int =
515
+ proc win32_xstat(path: WideCString, status: var Stat, traverse: bool ): cint =
517
516
#[ Protocol violation: we explicitly clear errno, instead of
518
517
setting it to a POSIX error. Callers should use GetLastError.]#
519
518
result = win32_xstat_impl(path, status, traverse)
@@ -523,20 +522,35 @@ when DWin:
523
522
status.st_ctime = status.st_birthtime
524
523
status.st_ctime_nsec = status.st_birthtime_nsec
525
524
525
+ template def3STAT(S, L, F){.dirty.} =
526
+ template STATf(p: string , s): cint = S
527
+ template LSTAT(p: string , s): cint = L
528
+ template FSTAT(p: int , s): cint = F
529
+
526
530
527
- template STATf(p, s): untyped = win32_xstat(newWideCString p, s, true )
528
- template LSTAT(p, s): untyped = win32_xstat(newWideCString p, s, false )
529
- template FSTAT(p, s): untyped = Py_fstat_noraise(p, s)
531
+ when DWin:
532
+ def3STAT(
533
+ win32_xstat(newWideCString p, s, true ),
534
+ win32_xstat(newWideCString p, s, false ),
535
+ Py_fstat_noraise(p, s),
536
+ )
530
537
elif InJs:
531
- template STATf(p, s): untyped = statAux(p, s)
532
- template LSTAT(p, s): untyped = lstatAux(p, s)
533
- template FSTAT(p, s): untyped = fstatAux(p, s)
538
+ template ret0(body): cint =
539
+ body
540
+ 0
541
+ def3STAT(
542
+ ret0 statAux(s, p),
543
+ ret0 lstatAux(s, p),
544
+ ret0 fstatAux(s, p),
545
+ )
534
546
else :
535
- template STATf(p, s): untyped = posix.stat(cstring p, s)
536
- template LSTAT(p, s): untyped = posix.lstat(cstring p, s)
537
- template FSTAT(p, s): untyped = posix.fstat(cint p, s)
547
+ def3STAT(
548
+ posix.stat(cstring p, s),
549
+ posix.lstat(cstring p, s),
550
+ posix.fstat(cint p, s),
551
+ )
538
552
539
- proc Py_fstat_noraise* (fd: int , status: var Stat): int =
553
+ proc Py_fstat_noraise* (fd: int , status: var Stat): cint =
540
554
# # EXT.
541
555
# #
542
556
# # fileutils.c `_Py_fstat_noraise`
@@ -585,8 +599,8 @@ proc Py_fstat_noraise*(fd: int, status: var Stat): int =
585
599
586
600
Py_attribute_data_to_stat(info, 0 , addr basicInfo, pIdInfo, status)
587
601
return 0
588
- else :
589
- int posix.fstat( cint fd, status)
602
+ elif InJS :
603
+ int FSTAT( fd, status)
590
604
591
605
proc Py_fstat* (fd: int , status: var Stat) =
592
606
# # EXT.
0 commit comments