Skip to content

Commit 74d6fcb

Browse files
committed
Start of all uploads with a rollback
Only if we make it all the way to the git commit should we actually commit all the way.
1 parent 54b2977 commit 74d6fcb

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/db.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ impl Transaction {
100100
}
101101

102102
pub fn rollback(&self) { self.rollback.set(true); }
103+
pub fn commit(&self) { self.rollback.set(false); }
103104
}
104105

105106
impl Middleware for TransactionMiddleware {
@@ -141,6 +142,8 @@ pub trait RequestTransaction<'a> {
141142

142143
/// Do not commit this request's transaction, even if it finishes ok.
143144
fn rollback(self);
145+
/// Flag this transaction to be committed (this is the default)
146+
fn commit(self);
144147
}
145148

146149
impl<'a> RequestTransaction<'a> for &'a Request + 'a {
@@ -161,6 +164,12 @@ impl<'a> RequestTransaction<'a> for &'a Request + 'a {
161164
.expect("Transaction not present in request")
162165
.rollback()
163166
}
167+
168+
fn commit(self) {
169+
self.extensions().find::<Transaction>()
170+
.expect("Transaction not present in request")
171+
.commit()
172+
}
164173
}
165174

166175
pub trait Connection {

src/krate.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ pub fn show(req: &mut Request) -> CargoResult<Response> {
419419

420420
pub fn new(req: &mut Request) -> CargoResult<Response> {
421421
let app = req.app().clone();
422+
req.rollback();
422423

423424
let (new_crate, user) = try!(parse_new_headers(req));
424425
let name = new_crate.name.as_slice();
@@ -509,6 +510,7 @@ pub fn new(req: &mut Request) -> CargoResult<Response> {
509510

510511
// Now that we've come this far, we're committed!
511512
bomb.path = None;
513+
req.commit();
512514

513515
#[deriving(Encodable)]
514516
struct R { krate: EncodableCrate }

0 commit comments

Comments
 (0)