summary refs log tree commit diff stats
path: root/lib/pure/os.nim
Commit message (Collapse)AuthorAgeFilesLines
* docgen: implement cross-document links (#20990)Andrey Makarov2023-01-041-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * docgen: implement cross-document links Fully implements https://github.com/nim-lang/RFCs/issues/125 Follow-up of: https://github.com/nim-lang/Nim/pull/18642 (for internal links) and https://github.com/nim-lang/Nim/issues/20127. Overview -------- Explicit import-like directive is required, called `.. importdoc::`. (the syntax is % RST, Markdown will use it for a while). Then one can reference any symbols/headings/anchors, as if they were in the local file (but they will be prefixed with a module name or markup document in link text). It's possible to reference anything from anywhere (any direction in `.nim`/`.md`/`.rst` files). See `doc/docgen.md` for full description. Working is based on `.idx` files, hence one needs to generate all `.idx` beforehand. A dedicated option `--index:only` is introduced (and a separate stage for `--index:only` is added to `kochdocs.nim`). Performance note ---------------- Full run for `./koch docs` now takes 185% of the time before this PR. (After: 315 s, before: 170 s on my PC). All the time seems to be spent on `--index:only` run, which takes almost as much (85%) of normal doc run -- it seems that most time is spent on file parsing, turning off HTML generation phase has not helped much. (One could avoid it by specifying list of files that can be referenced and pre-processing only them. But it can become error-prone and I assume that these linke will be **everywhere** in the repository anyway, especially considering https://github.com/nim-lang/RFCs/issues/478. So every `.nim`/`.md` file is processed for `.idx` first). But that's all without significant part of repository converted to cross-module auto links. To estimate impact I checked the time for `doc`ing a few files (after all indexes have been generated), and everywhere difference was **negligible**. E.g. for `lib/std/private/osfiles.nim` that `importdoc`s large `os.idx` and hence should have been a case with relatively large performance impact, but: * After: 0.59 s. * Before: 0.59 s. So Nim compiler works so slow that doc part basically does not matter :-) Testing ------- 1) added `extlinks` test to `nimdoc/` 2) checked that `theindex.html` is still correct 2) fixed broken auto-links for modules that were derived from `os.nim` by adding appropriate ``importdoc`` Implementation note ------------------- Parsing and formating of `.idx` entries is moved into a dedicated `rstidx.nim` module from `rstgen.nim`. `.idx` file format changed: * fields are not escaped in most cases because we need original strings for referencing, not HTML ones (the exception is linkTitle for titles and headings). Escaping happens later -- on the stage of `rstgen` buildIndex, etc. * all lines have fixed number of columns 6 * added discriminator tag as a first column, it always allows distinguish Nim/markup entries, titles/headings, etc. `rstgen` does not rely any more (in most cases) on ad-hoc logic to determine what type each entry is. * there is now always a title entry added at the first line. * add a line number as 6th column * linkTitle (4th) column has a different format: before it was like `module: funcName()`, now it's `proc funcName()`. (This format is also propagated to `theindex.html` and search results, I kept it that way since I like it more though it's discussible.) This column is what used for Nim symbols resolution. * also changed details on column format for headings and titles: "keyword" is original, "linkTitle" is HTML one * fix paths on Windows + more clear code * Update compiler/docgen.nim Co-authored-by: Andreas Rumpf <rumpf_a@web.de> * Handle .md and .nim paths uniformly in findRefFile * handle titles better + more comments * don't allow markup overwrite index title for .nim files Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* Move command line parameter code (#20946)IgorDeepakM2022-11-301-270/+5
| | | | | Command line paramater code moved from os.nim to cmdparam.nim Co-authored-by: IgorDeepakM <IgorDeepak@noreply.com>
* Fix #20628 for Windows (#20667)Andrey Makarov2022-10-281-6/+9
| | | | | | | * Fix #20628 for Windows * Move isRegular - !isSpecial and onlyRegular - skipSpecial * Forgot to change it in 1 more place
* clean up `std/os` related modules (#20651)ringabout2022-10-251-65/+0
| | | | | | | | | * clean up `std/os` related modules * use `cmpPaths` * reset * cleanup
* Implement Unix file regularity check (#20448) (#20628)Andrey Makarov2022-10-251-4/+7
| | | | | * Implement Unix file regularity check * update std/dirs also
* move procs in os to `appdirs` (#20605)ringabout2022-10-201-141/+3
| | | | | * move procs in os to `appdirs` * Update lib/std/private/osappdirs.nim
* [std/os] split and re-export (#20593)ringabout2022-10-201-2044/+17
| | | | | | | * [std/os] split and export * move to private modules * fixes docs and tests Co-authored-by: xflywind <43030857+xflywind@users.noreply.github.com>
* refactor envvars, oserrors; register vmops (#20592)ringabout2022-10-181-9/+5
| | | | | * refactor envvars, oserrors; register vmops * remove type definitions
* [`std/os` clean up] import and export `osseps` (#20580)ringabout2022-10-171-1/+2
| | | import and export osseps
* Markdown indented code blocks (#20473)Andrey Makarov2022-10-051-5/+6
| | | | | | | | | | | | | | | | | | | | | | | * Implement Markdown indented code blocks Additional indentation of 4 spaces makes a block an "indented code block" (monospaced text without syntax highlighting). Also `::` RST syntax for code blocks is disabled. So instead of ```rst see:: Some code ``` the code block should be written as ```markdown see: Some code ``` * Migrate RST literal blocks :: to Markdown's ones
* move widestrs out of system (#20462)metagn2022-10-011-0/+3
| | | | | * move widestrs out of system * fix osproc
* Undeprecate isvalidfilename (#19643)Juan Carlos2022-09-291-7/+12
| | | | | | | | | | * 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>
* moderate system cleanup & refactor (#20355)metagn2022-09-281-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * system refactor, move out 600 lines * compilation, slice, backwardsindex, misc_num moved out of system * some procs/types moved into arithmetics, basic_types * system no longer depends on syncio * some procs moved around to fit with their surroundings * make exceptions an import, old ops to misc_num * move instantiationInfo back * move back nim version, fix windows echo * include compilation * better docs for imported modules, fix unsigned ops also remove ze, ze64, toU8, toU16, toU32 with nimPreviewSlimSystem * fix terminal * workaround IC test & weird csize bug, changelog * move NimMajor etc back to compilation, rebase for CI * try ic fix * form single `indices`, slim out TaintedString, try fix IC * fix CI, update changelog, addQuitProc * fix CI * try fix CI * actually fix CI finally hopefully * Update lib/system/compilation.nim Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com> * update kochdocs * hopefully fix csize uses for slimsystem * fix tquit Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
* Fix cannot create Windows directory in root (#20311)havardjohn2022-09-111-19/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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-43/+62
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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>
* make implicit cstring conversions explicit (#19488)ee72022-08-191-10/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The Nim manual says that an implicit conversion to cstring will eventually not be allowed [1]: A Nim `string` is implicitly convertible to `cstring` for convenience. [...] Even though the conversion is implicit, it is not *safe*: The garbage collector does not consider a `cstring` to be a root and may collect the underlying memory. For this reason, the implicit conversion will be removed in future releases of the Nim compiler. Certain idioms like conversion of a `const` string to `cstring` are safe and will remain to be allowed. And from Nim 1.6.0, such a conversion triggers a warning [2]: A dangerous implicit conversion to `cstring` now triggers a `[CStringConv]` warning. This warning will become an error in future versions! Use an explicit conversion like `cstring(x)` in order to silence the warning. However, some files in this repo produced such a warning. For example, before this commit, compiling `parsejson.nim` would produce: /foo/Nim/lib/pure/parsejson.nim(221, 37) Warning: implicit conversion to 'cstring' from a non-const location: my.buf; this will become a compile time error in the future [CStringConv] /foo/Nim/lib/pure/parsejson.nim(231, 39) Warning: implicit conversion to 'cstring' from a non-const location: my.buf; this will become a compile time error in the future [CStringConv] This commit resolves the most visible `CStringConv` warnings, making the cstring conversions explicit. [1] https://github.com/nim-lang/Nim/blob/d2318d9ccfe6/doc/manual.md#cstring-type [2] https://github.com/nim-lang/Nim/blob/d2318d9ccfe6/changelogs/changelog_1_6_0.md#type-system
* Fixed typo in std/os doc (#20054)LetThereBeLemons2022-07-181-1/+1
| | | Fixed typo
* Fixes Compilation error with --app:lib (#19965)Juan M Gómez2022-07-101-1/+1
| | | | Fixes Compilation error with --app:lib when a module tries to pull os.paramStr on posix by throwing a runtime exception instead. More details here: #19964
* RST: improve simple tables (#19859)Andrey Makarov2022-06-041-6/+6
| | | | | | | * RST: improve simple tables * nim 1.0 gotchas * Still allow legacy boundaries like `----`
* move assertions out of system (#19599)flywind2022-03-231-1/+1
|
* Remove backslash in glob pattern (#19524)konsumlamm2022-02-141-3/+3
|
* move io out of system (#19442)flywind2022-02-021-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | * move io out of system * fix tests * fix tests * next step * rename to syncio * rename * fix nimscript * comma * fix * fix parts of errors * good for now * fix test
* os: faster getFileSize (#19438)ehmry2022-01-241-5/+4
| | | | Use "stat" rather than "open", "seek", and "close" system calls. The Windows implementation remains the same.
* stylecheck usages part two: stdlib cleanup (#19338)flywind2022-01-081-1/+1
| | | | | | | | | | | | | * stylecheck usages part two: stdlib cleanup typeinfo.nim: importCompilerProc => importcompilerproc nre.nim: newLineFlags => newlineFlags system.nim: JSRoot => JsRoot ref #19319 * prefer importCompilerProc
* Merge file size fields correctly on Windows (#19141)Clay Sweetser2021-11-121-1/+5
| | | | | | | | | | * Merge file size fields correctly on Windows Merge file size fields correctly on Windows - Merge the two 32-bit file size fields from `BY_HANDLE_FILE_INFORMATION` correctly in `rawToFormalFileInfo`. - Fixes #19135 * Update os.nim
* change os.nim doc links to new style (#19102)Andrey Makarov2021-11-081-282/+276
|
* Fix isInvalidFilename & always operate on the full passed in string (#19004)John Novak2021-10-201-45/+46
| | | | | | | | | | | | | * Fix isInvalidFilename segfault & deprecate the method * Update lib/pure/os.nim Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com> * Update lib/pure/os.nim Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com> Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>
* envPairs works in vm, nims (#18615)Timothee Cour2021-09-291-2/+1
| | | | | * envPairs works in vm, nims * fixup
* ported Nim to proprietary CrossOS [backport] (#18889)Andreas Rumpf2021-09-241-1/+1
|
* fix #18670 quoteShellCommand, quoteShell, quoteShellWindows on windows (#18671)Timothee Cour2021-08-121-5/+6
|
* Switch maintanance (#18668)RSDuck2021-08-111-8/+1
| | | | | | | | | * Fix and improve Nintendo Switch support * Document the necessity for nimAllocPagesViaMalloc * update changelog * Use --gc:orc in examples
* follow up #18517 (#18537)flywind2021-07-201-2/+3
| | | | | | | | | | | * follow up #18517 * Update lib/pure/os.nim Co-authored-by: Timothee Cour <timothee.cour2@gmail.com> * Update lib/pure/os.nim Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
* [std/os]document `checkDir` and use `runnableExamples` (#18517)flywind2021-07-191-22/+16
| | | Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
* Revert #17398 and #17402 (#18480)Miran2021-07-181-25/+15
| | | | | | | | | | | * 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
* OS.nim: style changes (#18331)Andreas Rumpf2021-06-231-30/+28
|
* #18216 make moveDir work across partitions on windows (#18223)Fröhlich A2021-06-101-19/+25
| | | | | | | * 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-6/+38
| | | | | | | * add `os.getCacheDir` * fixup * address comments
* system.nim cleanup some exported constants which should never have be… ↵Andreas Rumpf2021-05-011-1/+1
| | | | | | (#17909) * system.nim cleanup some exported constants which should never have been exported
* CIs: attempt to use csources_v1 (#16282)Andreas Rumpf2021-04-211-4/+4
| | | | | | | | * CIs: attempt to use csources_v1 * also updated the BSDs * also updated azure pipelines * std modules should not itself use the 'std/' import dir... * compiler has to be careful with std/ for v1 booting
* [docs minor] close #16553 (#17612)flywind2021-04-021-10/+6
| | | Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
* followup #17398: `getTempDir`, `getConfigDir` now do not have trailing ↵Timothee Cour2021-03-181-7/+11
| | | | | | | DirSep (#17402) * followup #17398: `getTempDir`, `getConfigDir` now do not have trailing DirSep * fix test
* fix #17393 getHomeDir and expandTilde should not include trailing `/` (#17398)Timothee Cour2021-03-171-2/+12
| | | | | * fix #17393 getHomeDir and expandTilde should not include trailing `/` * changelog
* Use `.. warning::` (#17320)konsumlamm2021-03-101-13/+11
|
* stdlib/os: add isAdmin (#17012)Roman Inflianskas2021-03-071-0/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | * 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-17/+17
|
* runnableExamples for walkFiles + friends (#17271)Timothee Cour2021-03-061-0/+12
| | | | | * runnableExamples for walkFiles + friends * address comments
* clarify the docs of existsOrCreateDir a bit (#17182)flywind2021-02-251-4/+3
| | | | | | | * remove unnecessary when statement * remove outdated codes * clarify the docs a bit
* mark inline (#17180)flywind2021-02-241-2/+2
|
* [nodejs backend] paramStr, paramCount (#17082)flywind2021-02-181-9/+33
|
* fix the unused warnings on windows (#17073)flywind2021-02-171-8/+13
|