Skip to content
This repository was archived by the owner on Oct 18, 2021. It is now read-only.

Commit f513ef3

Browse files
authored
update chrono and bson dependencies (#222)
1 parent 58d28bb commit f513ef3

File tree

3 files changed

+111
-63
lines changed

3 files changed

+111
-63
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ version = "0.3.0"
1111

1212
[dependencies]
1313
bitflags = "0.9.1"
14-
bson = "0.8.0"
14+
bson = "0.9.0"
1515
bufstream = "0.1.3"
1616
byteorder = "1.0.0"
17-
chrono = "0.3.1"
17+
chrono = "0.4.0"
1818
data-encoding = "1.2.0"
1919
rand = "0.3.15"
2020
rust-crypto = "0.2.36"

src/gridfs/file.rs

Lines changed: 63 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use bson::{self, Bson, oid};
33
use bson::spec::BinarySubtype;
44

5-
use chrono::{DateTime, UTC};
5+
use chrono::{DateTime, Utc};
66
use crypto::digest::Digest;
77
use crypto::md5::Md5;
88

@@ -80,7 +80,7 @@ pub struct GfsFile {
8080
// The filename of the document.
8181
pub name: Option<String>,
8282
// The date the document was first stored in GridFS.
83-
pub upload_date: Option<DateTime<UTC>>,
83+
pub upload_date: Option<DateTime<Utc>>,
8484
// The content type of the file.
8585
pub content_type: Option<String>,
8686
// Any additional metadata provided by the user.
@@ -195,7 +195,7 @@ impl File {
195195
if self.mode == Mode::Write {
196196
if try!(self.err_description()).is_none() {
197197
if self.doc.upload_date.is_none() {
198-
self.doc.upload_date = Some(UTC::now());
198+
self.doc.upload_date = Some(Utc::now());
199199
}
200200
self.doc.md5 = self.wsum.result_str();
201201
try!(self.gfs.files.insert_one(self.doc.to_bson(), None));
@@ -205,11 +205,15 @@ impl File {
205205

206206
let mut opts = IndexOptions::new();
207207
opts.unique = Some(true);
208-
try!(self.gfs.chunks.create_index(doc!{ "files_id" => 1, "n" => 1}, Some(opts)));
208+
try!(self.gfs.chunks.create_index(
209+
doc!{ "files_id" => 1, "n" => 1},
210+
Some(opts),
211+
));
209212
} else {
210-
try!(self.gfs
211-
.chunks
212-
.delete_many(doc!{ "files_id" => (self.doc.id.clone()) }, None));
213+
try!(self.gfs.chunks.delete_many(
214+
doc!{ "files_id" => (self.doc.id.clone()) },
215+
None,
216+
));
213217
}
214218
}
215219

@@ -240,7 +244,8 @@ impl File {
240244
let mut vec_buf = Vec::with_capacity(buf.len());
241245
vec_buf.extend(buf.iter().cloned());
242246

243-
let document = doc! {
247+
let document =
248+
doc! {
244249
"_id" => (try!(oid::ObjectId::new())),
245250
"files_id" => (self.doc.id.clone()),
246251
"n" => n,
@@ -322,8 +327,10 @@ impl File {
322327
}
323328
};
324329

325-
let result = arc_gfs.chunks
326-
.find_one(Some(doc!{"files_id" => (id), "n" => (next_chunk_num)}), None);
330+
let result = arc_gfs.chunks.find_one(
331+
Some(doc!{"files_id" => (id), "n" => (next_chunk_num)}),
332+
None,
333+
);
327334

328335
match result {
329336
Ok(Some(doc)) => {
@@ -333,8 +340,10 @@ impl File {
333340
cache.err = None;
334341
}
335342
_ => {
336-
cache.err = Some(OperationError(String::from("Chunk contained \
337-
no data.")))
343+
cache.err = Some(OperationError(String::from(
344+
"Chunk contained \
345+
no data.",
346+
)))
338347
}
339348
}
340349
}
@@ -361,7 +370,10 @@ impl io::Write for File {
361370

362371
let description = try!(self.err_description());
363372
if description.is_some() {
364-
return Err(io::Error::new(io::ErrorKind::Other, OperationError(description.unwrap())));
373+
return Err(io::Error::new(
374+
io::ErrorKind::Other,
375+
OperationError(description.unwrap()),
376+
));
365377
}
366378

367379
let mut data = buf;
@@ -393,16 +405,19 @@ impl io::Write for File {
393405

394406
// If over a megabyte is being written at once, wait for the load to reduce.
395407
while self.doc.chunk_size * self.wpending.load(Ordering::SeqCst) as i32 >=
396-
MEGABYTE as i32 {
408+
MEGABYTE as i32
409+
{
397410
guard = match self.condvar.wait(guard) {
398411
Ok(guard) => guard,
399412
Err(_) => return Err(io::Error::new(io::ErrorKind::Other, PoisonLockError)),
400413
};
401414

402415
let description = try!(self.err_description());
403416
if description.is_some() {
404-
return Err(io::Error::new(io::ErrorKind::Other,
405-
OperationError(description.unwrap())));
417+
return Err(io::Error::new(
418+
io::ErrorKind::Other,
419+
OperationError(description.unwrap()),
420+
));
406421
}
407422
}
408423

@@ -423,16 +438,19 @@ impl io::Write for File {
423438

424439
// Pending megabyte
425440
while self.doc.chunk_size * self.wpending.load(Ordering::SeqCst) as i32 >=
426-
MEGABYTE as i32 {
441+
MEGABYTE as i32
442+
{
427443
guard = match self.condvar.wait(guard) {
428444
Ok(guard) => guard,
429445
Err(_) => return Err(io::Error::new(io::ErrorKind::Other, PoisonLockError)),
430446
};
431447

432448
let description = try!(self.err_description());
433449
if description.is_some() {
434-
return Err(io::Error::new(io::ErrorKind::Other,
435-
OperationError(description.unwrap())));
450+
return Err(io::Error::new(
451+
io::ErrorKind::Other,
452+
OperationError(description.unwrap()),
453+
));
436454
}
437455
}
438456

@@ -461,7 +479,8 @@ impl io::Write for File {
461479

462480
// Pending megabyte
463481
while self.doc.chunk_size * self.wpending.load(Ordering::SeqCst) as i32 >=
464-
MEGABYTE as i32 {
482+
MEGABYTE as i32
483+
{
465484
guard = match self.condvar.wait(guard) {
466485
Ok(guard) => guard,
467486
Err(_) => return Err(io::Error::new(io::ErrorKind::Other, PoisonLockError)),
@@ -486,7 +505,10 @@ impl io::Write for File {
486505

487506
let description = try!(self.err_description());
488507
if description.is_some() {
489-
return Err(io::Error::new(io::ErrorKind::Other, OperationError(description.unwrap())));
508+
return Err(io::Error::new(
509+
io::ErrorKind::Other,
510+
OperationError(description.unwrap()),
511+
));
490512
}
491513

492514
Ok(())
@@ -613,7 +635,8 @@ impl GfsFile {
613635

614636
/// Converts a GfsFile into a bson document.
615637
pub fn to_bson(&self) -> bson::Document {
616-
let mut doc = doc! {
638+
let mut doc =
639+
doc! {
617640
"_id" => (self.id.clone()),
618641
"chunkSize" => (self.chunk_size),
619642
"length" => (self.len),
@@ -622,19 +645,27 @@ impl GfsFile {
622645
};
623646

624647
if self.name.is_some() {
625-
doc.insert("filename",
626-
Bson::String(self.name.as_ref().unwrap().to_owned()));
648+
doc.insert(
649+
"filename",
650+
Bson::String(self.name.as_ref().unwrap().to_owned()),
651+
);
627652
}
628653

629654
if self.content_type.is_some() {
630-
doc.insert("contentType",
631-
Bson::String(self.content_type.as_ref().unwrap().to_owned()));
655+
doc.insert(
656+
"contentType",
657+
Bson::String(self.content_type.as_ref().unwrap().to_owned()),
658+
);
632659
}
633660

634661
if self.metadata.is_some() {
635-
doc.insert("metadata",
636-
Bson::Binary(BinarySubtype::Generic,
637-
self.metadata.as_ref().unwrap().clone()));
662+
doc.insert(
663+
"metadata",
664+
Bson::Binary(
665+
BinarySubtype::Generic,
666+
self.metadata.as_ref().unwrap().clone(),
667+
),
668+
);
638669
}
639670

640671
doc
@@ -647,7 +678,9 @@ impl CachedChunk {
647678
CachedChunk {
648679
n: n,
649680
data: Vec::new(),
650-
err: Some(Error::DefaultError(String::from("Chunk has not yet been initialized"))),
681+
err: Some(Error::DefaultError(
682+
String::from("Chunk has not yet been initialized"),
683+
)),
651684
}
652685
}
653686
}

src/topology/monitor.rs

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use {Client, Result};
33
use Error::{self, ArgumentError, OperationError};
44

55
use bson::{self, Bson, oid};
6-
use chrono::{DateTime, UTC};
6+
use chrono::{DateTime, Utc};
77

88
use coll::options::FindOptions;
99
use command_type::CommandType;
@@ -33,7 +33,7 @@ pub struct IsMasterResult {
3333
pub is_master: bool,
3434
pub max_bson_object_size: i64,
3535
pub max_message_size_bytes: i64,
36-
pub local_time: Option<DateTime<UTC>>,
36+
pub local_time: Option<DateTime<Utc>>,
3737
pub min_wire_version: i64,
3838
pub max_wire_version: i64,
3939

@@ -220,13 +220,14 @@ impl IsMasterResult {
220220

221221
impl Monitor {
222222
/// Returns a new monitor connected to the server.
223-
pub fn new(client: Client,
224-
host: Host,
225-
pool: Arc<ConnectionPool>,
226-
top_description: Arc<RwLock<TopologyDescription>>,
227-
server_description: Arc<RwLock<ServerDescription>>,
228-
connector: StreamConnector)
229-
-> Monitor {
223+
pub fn new(
224+
client: Client,
225+
host: Host,
226+
pool: Arc<ConnectionPool>,
227+
top_description: Arc<RwLock<TopologyDescription>>,
228+
server_description: Arc<RwLock<ServerDescription>>,
229+
connector: StreamConnector,
230+
) -> Monitor {
230231
Monitor {
231232
client: client,
232233
host: host.clone(),
@@ -263,15 +264,17 @@ impl Monitor {
263264

264265
let time_start = time::get_time();
265266

266-
let cursor = try!(Cursor::query_with_stream(stream,
267-
self.client.clone(),
268-
String::from("local.$cmd"),
269-
flags,
270-
filter.clone(),
271-
options,
272-
CommandType::IsMaster,
273-
false,
274-
None));
267+
let cursor = try!(Cursor::query_with_stream(
268+
stream,
269+
self.client.clone(),
270+
String::from("local.$cmd"),
271+
flags,
272+
filter.clone(),
273+
options,
274+
CommandType::IsMaster,
275+
false,
276+
None,
277+
));
275278

276279
let time_end = time::get_time();
277280

@@ -291,18 +294,21 @@ impl Monitor {
291294

292295
// Updates the server description associated with this monitor using an isMaster server
293296
// response.
294-
fn update_server_description(&self,
295-
doc: bson::Document,
296-
round_trip_time: i64)
297-
-> Result<ServerDescription> {
297+
fn update_server_description(
298+
&self,
299+
doc: bson::Document,
300+
round_trip_time: i64,
301+
) -> Result<ServerDescription> {
298302

299303
let ismaster_result = IsMasterResult::new(doc);
300304
let mut server_description = self.server_description.write().unwrap();
301305
match ismaster_result {
302306
Ok(ismaster) => server_description.update(ismaster, round_trip_time),
303307
Err(err) => {
304308
server_description.set_err(err);
305-
return Err(OperationError(String::from("Failed to parse ismaster result.")));
309+
return Err(OperationError(
310+
String::from("Failed to parse ismaster result."),
311+
));
306312
}
307313
}
308314

@@ -312,10 +318,12 @@ impl Monitor {
312318
// Updates the topology description associated with this monitor using a new server description.
313319
fn update_top_description(&self, description: ServerDescription) {
314320
let mut top_description = self.top_description.write().unwrap();
315-
top_description.update(self.host.clone(),
316-
description,
317-
self.client.clone(),
318-
self.top_description.clone());
321+
top_description.update(
322+
self.host.clone(),
323+
description,
324+
self.client.clone(),
325+
self.top_description.clone(),
326+
);
319327
}
320328

321329
// Updates server and topology descriptions using a successful isMaster cursor result.
@@ -330,7 +338,9 @@ impl Monitor {
330338
self.set_err(err);
331339
}
332340
None => {
333-
self.set_err(OperationError(String::from("ismaster returned no response.")));
341+
self.set_err(OperationError(
342+
String::from("ismaster returned no response."),
343+
));
334344
}
335345
}
336346
}
@@ -379,12 +389,17 @@ impl Monitor {
379389
self.execute_update();
380390

381391
if let Ok(description) = self.top_description.read() {
382-
self.heartbeat_frequency_ms.store(description.heartbeat_frequency_ms as usize,
383-
Ordering::SeqCst);
392+
self.heartbeat_frequency_ms.store(
393+
description.heartbeat_frequency_ms as usize,
394+
Ordering::SeqCst,
395+
);
384396
}
385397

386398
let frequency = self.heartbeat_frequency_ms.load(Ordering::SeqCst) as u64;
387-
guard = self.condvar.wait_timeout(guard, Duration::from_millis(frequency)).unwrap().0;
399+
guard = self.condvar
400+
.wait_timeout(guard, Duration::from_millis(frequency))
401+
.unwrap()
402+
.0;
388403
}
389404
}
390405
}

0 commit comments

Comments
 (0)