diff --git a/google/cloud/storage/parallel_upload.cc b/google/cloud/storage/parallel_upload.cc index 1a1e14723ab07..8d4e7d05cd41f 100644 --- a/google/cloud/storage/parallel_upload.cc +++ b/google/cloud/storage/parallel_upload.cc @@ -381,7 +381,8 @@ Status ParallelUploadFileShard::Upload() { left_to_upload_ = 0; return status; }; - auto const already_uploaded = ostream_.next_expected_byte(); + auto const already_uploaded = + static_cast(ostream_.next_expected_byte()); if (already_uploaded > left_to_upload_) { return fail(StatusCode::kInternal, "Corrupted upload state, uploaded " + std::to_string(already_uploaded) + @@ -395,17 +396,13 @@ Status ParallelUploadFileShard::Upload() { return fail(StatusCode::kNotFound, "cannot open upload file source"); } - static_assert(sizeof(std::ifstream::off_type) >= sizeof(std::uintmax_t), - "files cannot handle uintmax_t for offsets uploads"); - - // TODO(#...) - this cast should not be necessary. - istream.seekg(static_cast(offset_in_file_)); + istream.seekg(offset_in_file_); if (!istream.good()) { return fail(StatusCode::kInternal, "file changed size during upload?"); } while (left_to_upload_ > 0) { - auto const to_copy = static_cast( - std::min(left_to_upload_, upload_buffer_size_)); + auto const to_copy = static_cast( + std::min(left_to_upload_, upload_buffer_size_)); istream.read(buf.data(), to_copy); if (!istream.good()) { return fail(StatusCode::kInternal, "cannot read from file source"); diff --git a/google/cloud/storage/parallel_upload.h b/google/cloud/storage/parallel_upload.h index 9d2e0e6404490..9822be23365d9 100644 --- a/google/cloud/storage/parallel_upload.h +++ b/google/cloud/storage/parallel_upload.h @@ -365,8 +365,12 @@ class ParallelUploadFileShard { std::shared_ptr state_; ObjectWriteStream ostream_; std::string file_name_; - std::uintmax_t offset_in_file_; - std::uintmax_t left_to_upload_; + // GCS only supports objects up to 5TiB, that fits comfortably in a + // `std::int64_t`, allows for any expected growth on that limit (not that we + // anticipate any), and plays nicer with the types in the standard C++ + // library. + std::int64_t offset_in_file_; + std::int64_t left_to_upload_; std::size_t upload_buffer_size_; std::string resumable_session_id_; };