clean up std/os related modules (#20651)
* clean up `std/os` related modules * use `cmpPaths` * reset * cleanup
This commit is contained in:
parent
daf35c6d1b
commit
69eaa4f14c
6 changed files with 140 additions and 157 deletions
|
|
@ -1,6 +1,5 @@
|
|||
include system/inclrtl
|
||||
|
||||
import ospaths2
|
||||
import std/[oserrors]
|
||||
|
||||
when defined(nimPreviewSlimSystem):
|
||||
|
|
@ -9,6 +8,15 @@ when defined(nimPreviewSlimSystem):
|
|||
const weirdTarget* = defined(nimscript) or defined(js)
|
||||
|
||||
|
||||
type
|
||||
ReadDirEffect* = object of ReadIOEffect ## Effect that denotes a read
|
||||
## operation from the directory
|
||||
## structure.
|
||||
WriteDirEffect* = object of WriteIOEffect ## Effect that denotes a write
|
||||
## operation to
|
||||
## the directory structure.
|
||||
|
||||
|
||||
when weirdTarget:
|
||||
discard
|
||||
elif defined(windows):
|
||||
|
|
@ -181,3 +189,23 @@ proc symlinkExists*(link: string): bool {.rtl, extern: "nos$1",
|
|||
else:
|
||||
var res: Stat
|
||||
result = lstat(link, res) >= 0'i32 and S_ISLNK(res.st_mode)
|
||||
|
||||
when defined(windows) and not weirdTarget:
|
||||
proc openHandle*(path: string, followSymlink=true, writeAccess=false): Handle =
|
||||
var flags = FILE_FLAG_BACKUP_SEMANTICS or FILE_ATTRIBUTE_NORMAL
|
||||
if not followSymlink:
|
||||
flags = flags or FILE_FLAG_OPEN_REPARSE_POINT
|
||||
let access = if writeAccess: GENERIC_WRITE else: 0'i32
|
||||
|
||||
when useWinUnicode:
|
||||
result = createFileW(
|
||||
newWideCString(path), access,
|
||||
FILE_SHARE_DELETE or FILE_SHARE_READ or FILE_SHARE_WRITE,
|
||||
nil, OPEN_EXISTING, flags, 0
|
||||
)
|
||||
else:
|
||||
result = createFileA(
|
||||
path, access,
|
||||
FILE_SHARE_DELETE or FILE_SHARE_READ or FILE_SHARE_WRITE,
|
||||
nil, OPEN_EXISTING, flags, 0
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue