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

refactor: Rust filesystem modules #4224

Closed
wants to merge 4 commits into from

Conversation

dubiousjim
Copy link
Contributor

This is part of a series of smaller PRs towards #4017.

It improves debug! calls, and does some other cleanup-type refactoring in Rust filesystem modules.

cli/ops/fs.rs Outdated
@@ -6,7 +6,6 @@ use crate::op_error::OpError;
use crate::ops::dispatch_json::JsonResult;
use crate::state::State;
use deno_core::*;
use remove_dir_all::remove_dir_all;
Copy link
Member

Choose a reason for hiding this comment

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

I think this import can be removed (along with entry in Cargo.toml) and replaced with std::fs::remove_dir_all

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do. Probably this is a good opportunity to start shifting over to the tokio::fs versions, as you propose in #4188.

Q: after removing the import from Cargo.toml, should I also commit an updated Cargo.lock? Or do you defer that until just before a release?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but #4188 should be done in a separate PR (I think I saw this code in one of your PRs)

Yes, Cargo.lock should be committed as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, there's a problem using std::fs::remove_dir_all as I do in 97c1a69 (below). Then the tests fail on Windows with a error: Uncaught Error: The directory is not empty. (os error 145). I assume this comes from removeAllSyncDirSuccess or removeAllDirSuccess, but those tests aren't currently written so as to catch that failure. So for the moment, I guess we should stick with remove_dir_all::remove_dir_all? It may be that the tokio::fs version works better on Windows.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, makes sense 👍

cli/ops/fs.rs Outdated Show resolved Hide resolved
@bartlomieju
Copy link
Member

@dubiousjim heads up: I've made significant changes to test, could you resolve the conflicts?

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.

Hey @dubiousjim - I appreciate the effort but I'm having trouble understanding what's happening here. Is this fixing something? If so, it should add a test to demo what is fixed. If this patch is not fixing anything then it seems to just move code around without changing behavior - and it would be a net gain of code - which is undesirable.

@@ -95,7 +96,7 @@ pub fn make_temp(
}

pub fn mkdir(path: &Path, perm: u32, recursive: bool) -> std::io::Result<()> {
debug!("mkdir -p {}", path.display());
// debug!("mkdir -p {}", path.display());
Copy link
Member

Choose a reason for hiding this comment

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

Unnecessary. You can either remove the line or leave it as is, but leaving dead code isn't helpful. Suggest leaving it as is.

} catch (e) {
success = false;
}
assert(success);
Copy link
Member

Choose a reason for hiding this comment

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

What's the purpose of this try-catch if it's supposed to succeed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this PR has gotten confusing as it's evolved. It might be better for me to just close it and re-push a new version of it with some of these commits squashed together. But for explanation, here's what's going on/how we got here. Other than the debug! improvements, there's not much else in this PR except a bit of refactoring. One thing I did with the refactoring was move the third-party imports to cli/fs.rs, because I thought that was the guiding intent about how to divide work between cli/fs.rs and cli/ops/fs.rs. You explained in an earlier comment thread on this PR that no, things are probably just divided as they are because of the contingencies of past refactorings, and stuff should ideally all be in cli/ops/fs.rs if it can be. So I pushed revisions to this branch that moved things back. Also, @bartlomieju noticed that one of the imports I was moving back and forth between the files was of the third-party crate remove_dir_all. He said, we don't need that, there's such a function in std::fs. I hadn't noticed that, so I tried replacing the use of remove_dir_all::remove_dir_all with a plain std::fs::remove_dir_all. That turned out to work fine on Mac and Unix, but when I pushed it to the branch this PR is based on, the CI test for Windows turned out to fail. (See above comment exchange between me and @bartlomieju.) So I pushed another revision that re-instated the use of remove_dir_all::remove_dir_all, at least for the time being until we worked out a good solution for all platforms. Also, I noticed that the report of the failure on Windows was funny: it didn't say that a specific test failed, but there was just a error: Uncaught Error: The directory is not empty. (os error 145). I don't understand why. I tried adding the try ... catch blocks to those tests, so that if someone else breaks this in the same way later, they'd get a better error report. But maybe those fixes are stupid, and would fail in just the same way that the bare remove call did.

Anyway, hope that explains what's going on. Should I close this PR and resubmit a squashed/pruned version of it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ry, check out this branch on my fork. That has six commits on top of denoland/master, the first four being the good parts of this PR, and the last two replacing the use of remove_dir_all::remove_dir_all with std::fs::remove_dir_all. Based on what happened before, I'm expecting the branch to fail CI tests on Windows, and so the last two commits should be reverted/dropped. That would be the pruned version of this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Confirmed that that fails, with only this information:

error: Uncaught Error: The directory is not empty. (os error 145)
$deno$/dispatch_json.ts:41:11
at unwrapResponse ($deno$/dispatch_json.ts:41:11)
at sendAsync ($deno$/dispatch_json.ts:96:10)
test tests::std_tests ... FAILED

failures:

---- tests::std_tests stdout ----
target_dir D:\a\deno\deno\target\release
##[error]thread 'tests::std_tests' panicked at 'assertion failed: status.success()', cli\tests\std_tests.rs:31:5
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace.
error: test failed, to rerun pass '-p deno --test std_tests'

failures:
tests::std_tests

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

##[error]Process completed with exit code 1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fails only on windows.

} catch (e) {
success = false;
}
assert(success);
Copy link
Member

Choose a reason for hiding this comment

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

ditto

@dubiousjim
Copy link
Contributor Author

@dubiousjim heads up: I've made significant changes to test, could you resolve the conflicts?

Done.

@dubiousjim
Copy link
Contributor Author

Am going to push --force a new branch to my fork overwriting this one, that contains just a pruned version of the useful parts of this PR, without the confusing history. Not sure how it will come out on this page. If it's a mess, I'll close this PR and open a new one.

@dubiousjim dubiousjim force-pushed the filesystem1b branch 2 times, most recently from 66ad22e to 59b9dfc Compare March 6, 2020 13:57
@dubiousjim
Copy link
Contributor Author

Hm, this page shows the push --force but doesn't present the commits for review. Guess I should close & reopen a different PR.

@ry
Copy link
Member

ry commented Mar 6, 2020

@dubiousjim I think it's better to combine these changes (if at all) with some other ones. Closing.

@ry ry closed this Mar 6, 2020
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.

3 participants