Repository navigation
File and directory helpers on std::filesystem; mkdir() without the shell (#323) (4.2.31) - #787
Merged
Merged
Conversation
…ell (#323) (4.2.31) Stage 1 of #323. - NLP++ mkdir() ran a shell "mkdir PATH": a path with spaces, or on Windows with forward slashes, made nothing; a path with & or ; ran a command; and it always returned 1. It now uses create_directories and returns whether the directory exists. - lite dir_exists/make_dir/rm_dir were #ifndef LINUX: on Linux and macOS dir_exists was always true and make_dir/rm_dir did nothing. - kbdumptree() ran "cat" through the shell on Linux and macOS; all platforms now concatenate in C++, after closing the files being read. - prim make_dir/rm_dir, file_size, file_exists (a directory no longer "exists" as a file on Linux), and nlp_engine stat/mkdir use std::filesystem. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stage 1 of #323: the file and directory helpers move to
std::filesystem. Moving them turned up real bugs.NLP++
mkdir()(security + correctness). It built a shell commandmkdir PATHand ran it withsystem(). Checked against 4.2.18 on Windows:mkdir(G("$apppath") + "/made/plain")made nothing, becausecmdreads/madeas a switch. It still returned 1.mkdir(base + "/x & echo pwned > pwned_323.txt")ran theechoand wrote the file.It now uses
create_directoriesand returns whether the directory exists afterwards. Parent folders are made, and an existing folder returns 1. This applies to the interpreter and the compiled runtime.dir_exists/make_dir/rm_dirin lite/mach.cpp were wrapped in#ifndef LINUX. On Linux and macOS,dir_existswas always true andmake_dir/rm_dirdid nothing. nlp.cpp relies on these for output and log folders.kbdumptree()shelled out tocaton Linux and macOS. Every platform now concatenates in C++. It also closes the three part files first: they were read while still open, so their last buffered lines could be missing. The dump is byte-identical to 4.2.18's on Windows.Also on std::filesystem: prim
make_dir/rm_dir,file_size,file_exists(a directory no longer counts as an existing file on Linux), and nlp_engine'sstat/mkdir/CreateDirectory.Left alone on purpose:
system()builtin and the Python pass (shell use is their job);msdev,kb_release.bat,_OLDWAY_);Tests:
tests/fs-opswith CI steps on Windows and Linux. It checks:pwned_323.txtappears;quit.$GITHUB_WORKSPACEand always fails locally.Docs: a visualtext-files PR for the
mkdirpage follows. Batched: don't tag yet.🤖 Generated with Claude Code