summary refs log tree commit diff stats
path: root/tests/stdlib/tos.nim
Commit message (Collapse)AuthorAgeFilesLines
* fixes #24174; allow copyDir and copyDirWithPermissions skipping special ↵ringabout2024-09-271-2/+13
| | | | | files (#24190) fixes #24174
* Fix searchExtPos so that it returns -1 when the path is not a file ext (#22245)Tomohiro2023-08-041-0/+32
| | | | | | | * Fix searchExtPos so that it returns -1 when the path is not a file ext * fix comparision expression * Remove splitDrive from searchExtPos
* stdlib tests now check refc too (#21664)ringabout2023-04-211-0/+1
| | | | | | | | | | | * stdlib tests now check refc too * typo * fixes line numbers * disable cpp * do not touch
* Fix #20628 for Windows (#20667)Andrey Makarov2022-10-281-4/+4
| | | | | | | * Fix #20628 for Windows * Move isRegular - !isSpecial and onlyRegular - skipSpecial * Forgot to change it in 1 more place
* Implement Unix file regularity check (#20448) (#20628)Andrey Makarov2022-10-251-2/+17
| | | | | * Implement Unix file regularity check * update std/dirs also
* Undeprecate isvalidfilename (#19643)Juan Carlos2022-09-291-26/+47
| | | | | | | | | | * Remove deprecated isvalidfilename * https://github.com/nim-lang/Nim/pull/19643#issuecomment-1235102314 * https://github.com/nim-lang/Nim/pull/19643#issuecomment-1235102314 * https://github.com/nim-lang/Nim/pull/19643#issuecomment-1235102314 * Add unittests * Add more Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* make more standard libraries work with `nimPreviewSlimSystem` (#20343)ringabout2022-09-271-0/+1
| | | | | | | | | | | | | | | | | | | | | | | * make more standard libraries work with `nimPreviewSlimSystem` * typo * part two * Delete specutils.nim * fixes more tests * more fixes * fixes tests * fixes three more tests * add formatfloat import * fix * last
* Fix cannot create Windows directory in root (#20311)havardjohn2022-09-111-1/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Fix cannot create Windows directory in root Fixes #20306, a regression bug with `createDir` caused by `23e0160af283bb0bb573a86145e6c1c792780d49`. The issue is that, if the path consists only of a drive and a single directory (e.g. "Y:\nimcache2" in the original issue), then no directories will be created. This works fine if there are multiple directories (e.g. "Y:\nimcache2\test"). In the case of "Y:\nimcache2", `omitNext` in `createDir` is `false` on the last condition in `createDir`. This means that the "nimcache2" directory will not be created, and no exception will be raised. Fixed by refactoring to use `parentDirs` iterator instead of iterating over the string characters. Motivation is reduced code complexity. Will not test the specific "C:\test" `createDir` case, since there is no standard Windows drive with write permissions in the root. Creating a custom drive-mapping to Windows Temp is a non-option. That could mess up some users running the test. Added `parentDirs` tests since they are lacking on for POSIX paths. * Fix `createDir("")` causing error The change to `createDir` caused `createDir("")` to raise an error, where it previously didn't. Fixed so `createDir("")` does not fail, and added test case.
* Add improved Windows UNC path support in std/os (#20281)havardjohn2022-09-031-1/+69
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add improved Windows UNC path support in std/os Original issue: `std/os.createDir` tries to create every component of the given path as a directory. The problem is that `createDir` interprets every backslash/slash as a path separator. For a UNC path this is incorrect. E.g. one UNC form is `\\Server\Volume\Path`. It's an error to create the `\\Server` directory, as well as creating `\\Server\Volume`. Add `ntpath.nim` module with `splitDrive` proc. This implements UNC path parsing as implemented in the Python `ntpath.py` module. The following UNC forms are supported: * `\\Server\Volume\Path` * `\\?\Volume\Path` * `\\?\UNC\Server\Volume\Path` Improves support for UNC paths in various procs in `std/os`: --- * pathnorm.addNormalizePath * Issue: This had incomplete support for UNC paths * The UNC prefix (first 2 characters of a UNC path) was assumed to be exactly `\\`, but it can be `//` and `\/`, etc. as well * Also, the UNC prefix must be normalized to the `dirSep` argument of `addNormalizePath` * Resolution: Changed to account for different UNC prefixes, and normalizing the prefixes according to `dirSep` * Affected procs that get tests: `relativePath`, `joinPath` * Issue: The server/volume part of UNC paths can be stripped when normalizing `..` path components * This error should be negligable, so ignoring this * splitPath * Now make sure the UNC drive is not split; return the UNC drive as `head` if the UNC drive is the only component of the path * Consequently fixes `extractFilename`, `lastPathPart` * parentDir / `/../` * Strip away drive before working on the path, prepending the drive after all work is done - prevents stripping UNC components * Return empty string if drive component is the only component; this is the behavior for POSIX paths as well * Alternative implementation: Just call something like `pathnorm.normalizePath(path & "/..")` for the whole proc - maybe too big of a change * tailDir * If drive is present in path, just split that from path and return path * parentDirs iterator * Uses `parentDir` for going backwards * When going forwards, first `splitDrive`, yield the drive field, and then iterate over path field as normal * splitFile * Make sure path parsing stops at end of drive component * createDir * Fixed by skipping drive part before creating directories * Alternative implementation: use `parentDirs` iterator instead of iterating over characters * Consequence is that it will try to create the root directory * isRootDir * Changed to treat UNC drive alone as root (e.g. "//?/c:" is root) * This change prevents the empty string being yielded by the `parentDirs` iterator with `fromRoot = false` * Internal `sameRoot` * The "root" refers to the drive, so `splitDrive` can be used here This adds UNC path support to all procs that could use it in std/os. I don't think any more work has to be done to support UNC paths. For the future, I believe the path handling code can be refactored due to duplicate code. There are multiple ways of manipulating paths, such as manually searching string for path separator and also having a path normalizer (pathnorm.nim). If all path manipulation used `pathnorm.nim`, and path component splitting used `parentDirs` iterator, then a lot of code could be removed. Tests --- Added test file for `pathnorm.nim` and `ntpath.nim`. `pathnorm.normalizePath` has no tests, so I'm adding a few unit tests. `ntpath.nim` contains tests copied from Python's test suite. Added integration tests to `tos.nim` that tests UNC paths. Removed incorrect `relativePath` runnableExamples from being tested on Windows: --- `relativePath("/Users///me/bar//z.nim", "//Users/", '/') == "me/bar/z.nim"` This is incorrect on Windows because the `/` and `//` are not the same root. `/` (or `\`) is expanded to the drive in the current working directory (e.g. `C:\`). `//` (or `\\`), however, are the first two characters of a UNC path. The following holds true for normal Windows installations: * `dirExists("/Users") != dirExists("//Users")` * `dirExists("\\Users") != dirExists("\\\\Users")` Fixes #19103 Questions: --- * Should the `splitDrive` proc be in `os.nim` instead with copyright notice above the proc? * Is it fine to put most of the new tests into the `runnableExamples` section of the procs in std/os? * [skipci] Apply suggestions from code review Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com> * [skip ci] Update lib/pure/os.nim Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com> * Move runnableExamples tests in os.nim to tos.nim * tests/topt_no_cursor: Change from using splitFile to splitDrive `splitFile` can no longer be used in the test, because it generates different ARC code on Windows and Linux. This replaces `splitFile` with `splitDrive`, because it generates same ARC code on Windows and Linux, and returns a tuple. I assume the test wants a proc that returns a tuple. * Drop copyright attribute to Python Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com>
* fix #18670 quoteShellCommand, quoteShell, quoteShellWindows on windows (#18671)Timothee Cour2021-08-121-1/+12
|
* Remove tracking of environment from osenv.nim v2 (#18575)Timothee Cour2021-07-291-26/+8
| | | | | | | | | | | | | * Remove unnecessary environment tracking * try to fix windows * fix delEnv * make putEnv work on windows even with empty values; improve tests: add tests, add js, vm testing * [skip ci] fix changelog Co-authored-by: Caden Haustein <code@brightlysalty.33mail.com>
* fixes #18565 (#18593)Andreas Rumpf2021-07-271-0/+1
| | | * fixes #18565
* followup #18453 (#18582)Timothee Cour2021-07-251-2/+2
|
* Replace calls to `putenv` with `setenv` (#18530)Caden Haustein2021-07-231-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | * Replace calls to C `putenv` with C `setenv` to remove possible memory leaks * Add test of correct behaviour on invalid input * Fix style in tests/stdlib/tos.nim Co-authored-by: Timothee Cour <timothee.cour2@gmail.com> * Update tests/stdlib/tos.nim Co-authored-by: Timothee Cour <timothee.cour2@gmail.com> * Update tests/stdlib/tos.nim Co-authored-by: Timothee Cour <timothee.cour2@gmail.com> * Add comment with bug number to tests/stdlib/tos.nim Co-authored-by: Timothee Cour <timothee.cour2@gmail.com> * Fix possible msvc arch issues Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
* Revert #17398 and #17402 (#18480)Miran2021-07-181-3/+3
| | | | | | | | | | | * Revert "followup #17398: `getTempDir`, `getConfigDir` now do not have trailing DirSep (#17402)" This reverts commit 2356d0603f70cad90f76fa57999054bf5c0a9157. * Revert "fix #17393 getHomeDir and expandTilde should not include trailing `/` (#17398)" This reverts commit bebf2ce24a43bef4cde5c90c4010631a1e4a7927. * fix test
* #18216 make moveDir work across partitions on windows (#18223)Fröhlich A2021-06-101-0/+45
| | | | | | | * return false if AccessDeniedError in tryMoveFSObject - fixes #18216 * add moveDir & moveFile tests * rename `isMoveDir` parameter to `isDir`
* add `os.getCacheDir` (#18126)Timothee Cour2021-05-311-0/+3
| | | | | | | * add `os.getCacheDir` * fixup * address comments
* typo: nonexistant => nonexistent (#17918)Timothee Cour2021-05-021-4/+4
| | | | | * typo: nonexistant => nonexistent * fix test (ordering differs because of https://github.com/nim-lang/Nim/issues/17910)
* followup #17398: `getTempDir`, `getConfigDir` now do not have trailing ↵Timothee Cour2021-03-181-3/+3
| | | | | | | DirSep (#17402) * followup #17398: `getTempDir`, `getConfigDir` now do not have trailing DirSep * fix test
* stdlib/os: add isAdmin (#17012)Roman Inflianskas2021-03-071-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | * stdlib/os: add isAdmin * uint8 -> cuchar, assert isAdmin on Azure Co-authored-by: Timothee Cour <timothee.cour2@gmail.com> * Update lib/pure/os.nim docs Co-authored-by: Timothee Cour <timothee.cour2@gmail.com> * Address comments on #17012 * Raise on errors in #17012 * Check the result of FreeSid in #17012 * Change case in #17012 * Fix memory leak in #17012 * Address comments in #17012 Co-authored-by: Timothee Cour <timothee.cour2@gmail.com> Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
* use lowercase --define switches (#17283)flywind2021-03-071-2/+2
|
* https://github.com/nim-lang/Nim/pull/15826/files#r585368355 (#17233)Juan Carlos2021-03-031-1/+5
|
* stdlib/os: handle symlinks in copy/move functions (#16709)Roman Inflianskas2021-02-041-0/+107
| | | | | | | | | | | | | | | | | | | | | | | | | | * stdlib/os: handle symlinks in copy/move functions - Added optional `options` argument to `copyFile`, `copyFileToDir`, and `copyFileWithPermissions`. By default, symlinks are followed (copy files symlinks point to). - `copyDir` and `copyDirWithPermissions` copy symlinks as symlinks (instead of skipping them as it was before). - `moveFile` and `moveDir` move symlinks as symlinks (instead of skipping them sometimes as it was before). - Added optional `followSymlinks` argument to `setFilePermissions`. See also: https://github.com/nim-lang/RFCs/issues/319 Co-authored-by: Timothee Cour <timothee.cour2@gmail.com> * Address comments in #16709 Co-authored-by: Timothee Cour <timothee.cour2@gmail.com> * Address comments in #16709 (second iteration) Skip symlinks on Windows. Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
* 2.5x- 3x faster copyFile on osx (#16883)Timothee Cour2021-02-011-9/+14
|
* use doAssert in tests (#16486)flywind2020-12-281-8/+8
|
* os: add overload copyFile*(source, dest: string, isDir = false) (#15537)Timothee Cour2020-10-111-0/+19
| | | | | * os: add overload copyFile*(source, dest: string, isDir = false) * renamed to copyFileToDir
* normalizeExe (#14668)Timothee Cour2020-06-151-0/+10
|
* remove isMainModule from json,os,sequtils (#14572)Timothee Cour2020-06-061-0/+63
| | | | | * move json.isMainModule => tjson * move isMainModule => tos,tsequtils
* fix #13222: make relativePath more robust and flexible (#13451)Timothee Cour2020-04-211-0/+3
| | | | | | | | | * * relativePath(foo) now works * relativePath(rel, abs) and relativePath(abs, rel) now work (fixes #13222) * relativePath, absolutePath, getCurrentDir now available in more targets (eg: vm, nodejs etc) * fix bug: isAbsolutePath now works with -d:js; add tests * workaround https://github.com/nim-lang/Nim/issues/13469 * remove `relativePath(path)` overload for now * add back changelog after rebase
* [RFC] 'walkDir' now has a new 'checkDir' flag, to mimic behaviour of other ↵Timothee Cour2020-03-201-7/+13
| | | | | languages (#13642) Co-authored-by: narimiran
* fix #13579 joinPath("/foo/", "../a") is now /a (#13586)Andreas Rumpf2020-03-051-0/+13
|
* fix #13455 ; joinPath(a,b) now honors trailing slashes in b (or a if b = "") ↵Timothee Cour2020-02-261-3/+26
| | | | | | | (#13467) * fix #13455 ; joinPath(a,b) now honors trailing slashes in b (or a if b = "") * fix test windows
* fix 3 minor bugs in joinPath (see #13455) (#13462) [backport]Andrey Makarov2020-02-231-0/+4
|
* relativePath("foo", "foo") is now ".", not "" (#13452)Timothee Cour2020-02-221-4/+8
|
* fix lots of bugs with parentDir, refs #8734 (#13236)Timothee Cour2020-01-231-5/+5
|
* new os.isRelativeTo (#13212)Timothee Cour2020-01-231-0/+12
|
* fix #13211 relativePath("foo", ".") (#13213)Timothee Cour2020-01-211-0/+4
|
* On windows, os.relativePath returns path as is when roots are different (#12329)Tomohiro2019-10-071-0/+15
| | | | | | | * On windows, os.relativePath returns path as is when roots are different * Implement os.sameRoot without windows API * Fix compile error when compiling lib/nimhcr.nim * Fix compile error when compiling lib/nimhcr.nim on Windows
* Fix how `relativePath` handle case sensitiviy (#12312) [backport]Tomohiro2019-10-011-0/+4
|
* Fixes splitfile (#11918) [bugfix]pgkos2019-08-151-0/+1
|
* [feature] Added os.delEnv; add delEnv support to nimscript too (#11466)Kaushal Modi2019-06-151-0/+13
| | | [feature] Fixes https://github.com/nim-lang/Nim/issues/11452.
* Use TMPDIR env var if available to get the temp dir name (#11443) [bugfix]Kaushal Modi2019-06-101-0/+12
| | | | | | Additionally, use normalizePathEnd to suffix the dir name with "/" or "\" as appropriate for the current OS. Fixes https://github.com/nim-lang/Nim/issues/11439.
* move tests from `tospaths` to `tos`, fixes #9671narimiran2019-01-231-43/+111
| | | | Also, change some of `echo`s to `doAssert`.
* fixes #10273 execShellCmd now returns nonzero when child killed with signal ↵Timothee Cour2019-01-131-0/+2
| | | | | | | | | | + other fixes (#10274) * s/exitStatus(...)/exitStatusLikeShell(...)/ * fix #10273 execShellCmd now returns nonzero when child exits with signal * test case for #10249 and explanation for the bug * fix test failure * add tests/nim.cfg
* os.walkDir: correctly evaluate paths when relative = true (#10057) [backport]alaviss2018-12-211-0/+8
|
* fix test failureTimothee Cour2018-12-191-0/+1
|
* fix #8255 numerous issues with splitFileTimothee Cour2018-12-191-0/+15
|
* [os] fix #10017 regression, fix #10025 regression (#10018)Timothee Cour2018-12-181-2/+5
| | | | | * [os] fix #10017 regression * [os] fix #10025 regression
* os.nim: use the new pathnorm.normalizePath implementationAraq2018-12-141-55/+26
|
* Add `relative` parameter to walkDirRecOscar Nihlgård2018-11-261-0/+19
|