Skip to content

Add a dry_run flag to /crates/new #1517

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

Closed
wants to merge 2 commits into from

Conversation

sgrif
Copy link
Contributor

@sgrif sgrif commented Oct 12, 2018

Note: Includes #1516

There is interest from Cargo in having the ability to make cargo publish --dry-run hit crates.io to see if there are any checks that we
perform which Cargo does not. This looks for a dry_run query param in
the publish function, and will roll back the database transaction before
attempting to upload to S3 or update the index, but after all other
checks are complete.

The code is fairly straightforward, the only hard part here is actually
being able to check why we rolled back the transaction in the first
place. We have to re-implement the inherent methods from Any here,
since we can't call inherent methods from dyn Any on dyn CargoError
even though all CargoErrors implement Any.

Fixes #1515

sgrif added 2 commits October 12, 2018 10:00
The way we handled this before with a `Shim` struct breaks any later
downcasting we may try to do, and can lead to errors slipping through in
a hard to debug way. It's much easier if we just directly implement
`CargoError` on those types (and lets us get rid of some trivial impls).

This new impl conflicts with `impl<T: CargoError> CargoError for
Box<T>`. It's fine to remove that impl. It means that
`Box<ConcreteType>` no longer implements `CargoError`, but we wouldn't
have boxed the error in the first place unless we needed `dyn
CargoError`.
There is interest from Cargo in having the ability to make `cargo
publish --dry-run` hit crates.io to see if there are any checks that we
perform which Cargo does not. This looks for a `dry_run` query param in
the publish function, and will roll back the database transaction before
attempting to upload to S3 or update the index, but after all other
checks are complete.

The code is fairly straightforward, the only hard part here is actually
being able to check why we rolled back the transaction in the first
place. We have to re-implement the inherent methods from `Any` here,
since we can't call inherent methods from `dyn Any` on `dyn CargoError`
even though all `CargoError`s implement `Any`.
Copy link
Member

@jtgeibel jtgeibel left a comment

Choose a reason for hiding this comment

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

The only thing that concerns me a bit is that even if the transaction is rolled back, my understanding is that id numbers can still be consumed. Even the existing code could use a lot of improvement here.

Ideally, we would check all the static things up front, outside of the transaction. Right now, we render the README inside the transaction as the last thing before checking the dry_run flag! We should probably do this before even obtaining a database connection from the pool.

Here is a rough outline of what I'm thinking:

  • Verify all possible crate metadata first, and render the README.
  • Obtain a connection from the pool and enter the transaction.
  • Check that all dependencies exist and have valid version ranges. Do other read only checks.
  • Check user permissions to upload. If this is our last step, then we can reply with something like "everything else looks good, but FYI you don't have upload permission".
  • Abort if this is a dry run.
  • Anything that does UPDATE/INSERT (I think UPDATES sooner are fine, but defer if practical).

We may also be able to collect a list of errors so that we can report as many issues as possible at once.

if self.is::<T>() {
unsafe {
Some(&*(self as *const Self as *const T))
}
Copy link
Member

Choose a reason for hiding this comment

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

Our own in-tree unsafe! Matches what is in std so should be fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hah is this really the first use of unsafe? \o/

@sgrif
Copy link
Contributor Author

sgrif commented Oct 13, 2018

I really don't think we need to worry about even remotely approaching the limit of 64 bit integers here, but you're definitely right that this will use ids for uncommitted rows.

I went with this approach because it was the (mostly) shortest path to what cargo is looking for. I would definitely love to have a larger refactoring on this, but it's not something I personally have time for (maybe @joelgallant would be interested in it?)

@jtgeibel
Copy link
Member

I've just opened #1522. I don't see the proposed changes as a hard blocker on the --dry-run change, but it would be nice to make some progress there before merging this functionality.

@sgrif
Copy link
Contributor Author

sgrif commented Oct 16, 2018

👍 Closing this then

@sgrif sgrif closed this Oct 16, 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