-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] 'walkDir' now has a new 'checkDir' flag, to mimic behaviour of other languages #13642
[RFC] 'walkDir' now has a new 'checkDir' flag, to mimic behaviour of other languages #13642
Conversation
AFAIR when demotomohiro in #13011 tried to do exception raising as default option, he got test failures, so Araq rejected it as breaking compatibility "in our own code". Nevertheless I fully support this. The current Nim behavior looks downright stupid to me. Compatibility basis is far-fetched since this behavior of silently omitting the open error has never been documented, hence programs relying on it are incorrect. |
also getting failures in important_packages but I think they're (almost) all originating from a single place, somewhere inside nimble I think; I need to investigate further |
here are bugs I found thanks to this PR:
all the failures are originating from 2 lines in nimble, I'm fixing it in nim-lang/nimble#780 (EDIT: but that PR was unfortunately closed) |
344d133
to
8a70063
Compare
Does Fix #11458 (comment) ?. 🙂 |
this PR is blocked until nim-lang/nimble#780 gets re-opened and merged /cc @dom96 |
Rejected, breaking change. If you care so much about existing directories you can easily check for |
The way I see it, the only breaking changes will actually be bug fixes in user code. let's at least open the debate on this one and get more opinions and perspectives, I'm not the only one supporting this. The only breaking change amongst all packages is a single line in nimble (or 2 lines depending on how you see it), which I fixed here nim-lang/nimble#780 The current behavior is downright error-prone and source of bugs (try:
that's a racy condition, and also doesn't work: if you don't have read access to input dir, other languages also raise for invalid dir: python, D, C, C++, nodejs, matlab/octave, ruby, swift, shell(ls, find)
#include <string>
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main(){
std::string path = "nonexistant";
for (const auto & entry : fs::directory_iterator(path))
std::cout << entry.path() << std::endl;
}
const { readdirSync, statSync } = require('fs')
const { join } = require('path')
const dirs = p => readdirSync(p).filter(f => statSync(join(p, f)).isDirectory())
dirs('nonexistant')
import Foundation
let fileManager = FileManager.default
let files = try fileManager.contentsOfDirectory(atPath:"/tmp/d18")
print(files)
|
8a70063
to
97c4d34
Compare
Well that's your very own bugfix inside compiler/nimbledir. And also how you deal with the changed behaviour inside Nimble in preparation for this PR. It's a big breaking change and it breaks both the Nim compiler and Nimble.
Well APIs taking strings are inherently prone to typos and by the PR's logic Look, if Nimble processed 0 files inside |
I used proc canWalkDir*(dir: string): bool =
if not dirExists(dir): return false
let perms = getFilePermissions(dir)
return canPidAccessDir(getCurrentProcessId(), fpUserRead in perms, fpGroupRead in perms, fpOthersRead in perms) this is fraught with caveats, eg:
After this PR, all you'll need is: # correct fix to nimble:
when defined(nimHasWalkDirRaises): walkDir(dir, checkDir = false)
else: walkDir(dir) which preserves pre-existing semantics 100%.
how so? honest question. I don't see how the
I mentioned no such thing here, and
no, that's not what my PR nim-lang/nimble#780 does; I'm using And finally, you've already agreed that raising when top-level dir was invalid was the right default:
And you had agreed 8 days ago here too: #12676 by merging bbc231f (even though that PR didn't actually fix anything, unlike this PR). There's a good reason why pretty much every language I've ever used raises by default when top-level dir is invalid:
silently ignoring errors causes bugs and shouldn't be the default. |
|
@timotheecour I talked to @Araq and based on our discussion, I've pushed some changes. P.S. For future: please don't disable packages like you did here. Comment them out. |
The problem remains that some packages appear tested but really aren't being tested at all, as I've explained here #13642 (comment): eg see CI logs for this PR https://github.com/nim-lang/Nim/runs/522044580
=> 0 indication that something fishy was going on. proposal
|
I'll keep this short: Adding Thank you for your cooperation. |
pretty much every single language I've every used (see list below in comments) raises when input dir is invalid, and so should nim.
walkDirRec
only throws if top-level dir is invalid, otherwise it would be impossible to resume iteration if a single subdir was bad (eg wrong permissions)removeDir
changes its API to:removeDir(dir: string, checkDir = false)
(backward compatible)future work
provide a means for users to report errors encountered during
walkDirRec
note
Yes, I'm aware of #13163 (/cc @a-mr ) #13011 (/cc @demotomohiro ). These can still be done after this PR.