Skip to content
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

Implemented deno.readDirSync #652

Closed
wants to merge 1 commit into from
Closed

Conversation

XAMPPRocky
Copy link

  • Node: fs.readdirSync returns a list of paths of entries in the path.

  • Rust: fs::read_dir returns an iterator of DirEntrys.

  • Go: ioutil.ReadDir returns a list of os.FileInfos.

  • Ruby: Dir is a class with various methods for general directory operations such as changing directories. Dir["dir/"] returns a array of strings matching the path. This also accepts a general glob pattern as opposed to a strict path.

  • Python: os.listdir returns an list of paths in arbitrary order.

@ry
Copy link
Member

ry commented Sep 1, 2018

@Aaronepower Awesome! I really appreciate you hammering thru all these bindings :)

I think we should follow Go in this situation and not just return a list of strings, but a list of FileInfo objects. It's somewhat wasteful to throw away the extra information and only return strings. What do you think?

@XAMPPRocky
Copy link
Author

@ry I was also thinking about that. The one hang up I had is what to add to FileInfo that is safely reusable for both stat and readDir. We can include path, but not file_name for example.

@ry
Copy link
Member

ry commented Sep 2, 2018

@Aaronepower I'm not sure I understand? I would follow Go's os.FileInfo for both statSync and this readDirSync.

@ry
Copy link
Member

ry commented Sep 2, 2018

@Aaronepower Just a heads up - #659 refactors handlers.rs - please rebase your work on top of that patch. It shouldn't be too difficult.

@XAMPPRocky
Copy link
Author

@ry Okay, I've updated the PR with the rebase and with changes so it now returns FileInfos and FileInfos now return paths and file names.

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good but missing a test that exercises the FileInfos returned from readDirSync

js/os.ts Outdated
*
* for (const path of entries) {
* console.log(path);
* }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the example code here for the new API

js/os_test.ts Outdated
@@ -100,6 +112,37 @@ test(async function readFileSyncSuccess() {
assertEqual(pkg.name, "deno");
});

test(async function readDirSyncSuccess() {
const src = deno.readDirSync("src");
assert(src.length !== 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have a success test that returns non-zero number of entries

@XAMPPRocky
Copy link
Author

@ry Alright, I've updated with those changes and fixed the merge conflicts with the main branch.

js/os_test.ts Outdated
@@ -34,9 +34,21 @@ test(async function statSyncSuccess() {
assert(testingInfo.isDirectory());
assert(!testingInfo.isSymlink());

const srcInfo = deno.statSync("src");
const srcInfo = deno.statSync("src/");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a functional reason for "src/" instead of "src"? Also below you use "js/."
... It's an odd way to write these and I'm wondering if you're doing it for extra clarity?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ry src/ is just for clarity. js/. is to test that the name of that path is js.

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ry
Copy link
Member

ry commented Sep 4, 2018

@Aaronepower Thanks! Can you rebase and squash? (For some reason github isn't able to do this for me?)

@ry
Copy link
Member

ry commented Sep 8, 2018

Sorry I should have got this in earlier. But as it is I will wait for #708 to land before this one.

@XAMPPRocky
Copy link
Author

@ry I've updated it to work with the current codebase, however there appears to be a regression in flatbuffers' Rust codegen, where it won't declare a lifetime for the StatRes struct when it's inner type requires it. The workaround I've put in is just making it a single element array.

@ry
Copy link
Member

ry commented Sep 24, 2018

@Aaronepower hey - sorry about this but this is the oldest PR here now and it's red so I can't merge it. I also don't want to dig in and fix it myself at the moment. So I'd be extremely grateful if you rebased and resubmitted - or if not - I will come back and rebase your code after landing #782. (I'll cite you as the author, of course).
For now I want to clean out the queue and close this. To be continued...

@ry ry closed this Sep 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants