Merge branch 'devel' of github.com:nim-lang/Nim into devel
This commit is contained in:
commit
0c04da6f26
2 changed files with 141 additions and 128 deletions
|
|
@ -305,15 +305,6 @@ proc absolutePath*(path: string, root = getCurrentDir()): string =
|
||||||
raise newException(ValueError, "The specified root is not absolute: " & root)
|
raise newException(ValueError, "The specified root is not absolute: " & root)
|
||||||
joinPath(root, path)
|
joinPath(root, path)
|
||||||
|
|
||||||
when isMainModule:
|
|
||||||
doAssertRaises(ValueError): discard absolutePath("a", "b")
|
|
||||||
doAssert absolutePath("a") == getCurrentDir() / "a"
|
|
||||||
doAssert absolutePath("a", "/b") == "/b" / "a"
|
|
||||||
when defined(Posix):
|
|
||||||
doAssert absolutePath("a", "/b/") == "/b" / "a"
|
|
||||||
doAssert absolutePath("a", "/b/c") == "/b/c" / "a"
|
|
||||||
doAssert absolutePath("/a", "b/") == "/a"
|
|
||||||
|
|
||||||
proc expandFilename*(filename: string): string {.rtl, extern: "nos$1",
|
proc expandFilename*(filename: string): string {.rtl, extern: "nos$1",
|
||||||
tags: [ReadDirEffect].} =
|
tags: [ReadDirEffect].} =
|
||||||
## Returns the full (`absolute`:idx:) path of an existing file `filename`,
|
## Returns the full (`absolute`:idx:) path of an existing file `filename`,
|
||||||
|
|
@ -1724,13 +1715,22 @@ proc getFileInfo*(path: string, followSymlink = true): FileInfo =
|
||||||
rawToFormalFileInfo(rawInfo, path, result)
|
rawToFormalFileInfo(rawInfo, path, result)
|
||||||
|
|
||||||
proc isHidden*(path: string): bool =
|
proc isHidden*(path: string): bool =
|
||||||
## Determines whether a given path is hidden or not. Returns false if the
|
## Determines whether ``path`` is hidden or not, using this
|
||||||
## file doesn't exist. The given path must be accessible from the current
|
## reference https://en.wikipedia.org/wiki/Hidden_file_and_hidden_directory
|
||||||
## working directory of the program.
|
|
||||||
##
|
##
|
||||||
## On Windows, a file is hidden if the file's 'hidden' attribute is set.
|
## On Windows: returns true if it exists and its "hidden" attribute is set.
|
||||||
## On Unix-like systems, a file is hidden if it starts with a '.' (period)
|
##
|
||||||
## and is not *just* '.' or '..' ' ."
|
## On posix: returns true if ``lastPathPart(path)`` starts with ``.`` and is
|
||||||
|
## not ``.`` or ``..``. Note: paths are not normalized to determine `isHidden`.
|
||||||
|
runnableExamples:
|
||||||
|
when defined(posix):
|
||||||
|
doAssert ".foo".isHidden
|
||||||
|
doAssert: not ".foo/bar".isHidden
|
||||||
|
doAssert: not ".".isHidden
|
||||||
|
doAssert: not "..".isHidden
|
||||||
|
doAssert: not "".isHidden
|
||||||
|
doAssert ".foo/".isHidden
|
||||||
|
|
||||||
when defined(Windows):
|
when defined(Windows):
|
||||||
when useWinUnicode:
|
when useWinUnicode:
|
||||||
wrapUnary(attributes, getFileAttributesW, path)
|
wrapUnary(attributes, getFileAttributesW, path)
|
||||||
|
|
@ -1739,14 +1739,8 @@ proc isHidden*(path: string): bool =
|
||||||
if attributes != -1'i32:
|
if attributes != -1'i32:
|
||||||
result = (attributes and FILE_ATTRIBUTE_HIDDEN) != 0'i32
|
result = (attributes and FILE_ATTRIBUTE_HIDDEN) != 0'i32
|
||||||
else:
|
else:
|
||||||
if fileExists(path):
|
let fileName = lastPathPart(path)
|
||||||
let
|
result = len(fileName) >= 2 and fileName[0] == '.' and fileName != ".."
|
||||||
fileName = extractFilename(path)
|
|
||||||
nameLen = len(fileName)
|
|
||||||
if nameLen == 2:
|
|
||||||
result = (fileName[0] == '.') and (fileName[1] != '.')
|
|
||||||
elif nameLen > 2:
|
|
||||||
result = (fileName[0] == '.') and (fileName[3] != '.')
|
|
||||||
|
|
||||||
{.pop.}
|
{.pop.}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@ true
|
||||||
|
|
||||||
import os, strutils
|
import os, strutils
|
||||||
|
|
||||||
|
block fileOperations:
|
||||||
let files = @["these.txt", "are.x", "testing.r", "files.q"]
|
let files = @["these.txt", "are.x", "testing.r", "files.q"]
|
||||||
let dirs = @["some", "created", "test", "dirs"]
|
let dirs = @["some", "created", "test", "dirs"]
|
||||||
|
|
||||||
|
|
@ -155,9 +156,10 @@ echo dirExists("../dest/a/b")
|
||||||
echo fileExists("../dest/a/file.txt")
|
echo fileExists("../dest/a/file.txt")
|
||||||
removeDir("../dest")
|
removeDir("../dest")
|
||||||
|
|
||||||
|
import times
|
||||||
|
block modificationTime:
|
||||||
# Test get/set modification times
|
# Test get/set modification times
|
||||||
# Should support at least microsecond resolution
|
# Should support at least microsecond resolution
|
||||||
import times
|
|
||||||
let tm = fromUnix(0) + 100.microseconds
|
let tm = fromUnix(0) + 100.microseconds
|
||||||
writeFile("a", "")
|
writeFile("a", "")
|
||||||
setLastModificationTime("a", tm)
|
setLastModificationTime("a", tm)
|
||||||
|
|
@ -168,9 +170,8 @@ else:
|
||||||
echo getLastModificationTime("a") == tm
|
echo getLastModificationTime("a") == tm
|
||||||
removeFile("a")
|
removeFile("a")
|
||||||
|
|
||||||
when defined(posix):
|
|
||||||
|
|
||||||
block normalizedPath:
|
block normalizedPath:
|
||||||
|
when defined(posix):
|
||||||
block relative:
|
block relative:
|
||||||
doAssert normalizedPath(".") == "."
|
doAssert normalizedPath(".") == "."
|
||||||
doAssert normalizedPath("..") == ".."
|
doAssert normalizedPath("..") == ".."
|
||||||
|
|
@ -199,8 +200,6 @@ when defined(posix):
|
||||||
doAssert normalizedPath("/a/b/c/../") == "/a/b"
|
doAssert normalizedPath("/a/b/c/../") == "/a/b"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
block normalizedPath:
|
|
||||||
block relative:
|
block relative:
|
||||||
doAssert normalizedPath(".") == "."
|
doAssert normalizedPath(".") == "."
|
||||||
doAssert normalizedPath("..") == ".."
|
doAssert normalizedPath("..") == ".."
|
||||||
|
|
@ -227,3 +226,23 @@ else:
|
||||||
doAssert normalizedPath("\\a\\\\\\b") == "\\a\\b"
|
doAssert normalizedPath("\\a\\\\\\b") == "\\a\\b"
|
||||||
doAssert normalizedPath("\\a\\b\\c\\..") == "\\a\\b"
|
doAssert normalizedPath("\\a\\b\\c\\..") == "\\a\\b"
|
||||||
doAssert normalizedPath("\\a\\b\\c\\..\\") == "\\a\\b"
|
doAssert normalizedPath("\\a\\b\\c\\..\\") == "\\a\\b"
|
||||||
|
|
||||||
|
block isHidden:
|
||||||
|
when defined(posix):
|
||||||
|
doAssert ".foo.txt".isHidden
|
||||||
|
doAssert "bar/.foo.ext".isHidden
|
||||||
|
doAssert: not "bar".isHidden
|
||||||
|
doAssert: not "foo/".isHidden
|
||||||
|
# Corner cases: paths are not normalized when determining `isHidden`
|
||||||
|
doAssert: not ".foo/.".isHidden
|
||||||
|
doAssert: not ".foo/..".isHidden
|
||||||
|
|
||||||
|
block absolutePath:
|
||||||
|
doAssertRaises(ValueError): discard absolutePath("a", "b")
|
||||||
|
doAssert absolutePath("a") == getCurrentDir() / "a"
|
||||||
|
doAssert absolutePath("a", "/b") == "/b" / "a"
|
||||||
|
when defined(Posix):
|
||||||
|
doAssert absolutePath("a", "/b/") == "/b" / "a"
|
||||||
|
doAssert absolutePath("a", "/b/c") == "/b/c" / "a"
|
||||||
|
doAssert absolutePath("/a", "b/") == "/a"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue