Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix(desktop-gpui): align upload chunks for Google Drive
Aditya Garude6706f4ce342
diff --git a/apps/desktop-gpui/src/upload.rs b/apps/desktop-gpui/src/upload.rsindex 025f464ab..d8f110859 100644--- a/apps/desktop-gpui/src/upload.rs+++ b/apps/desktop-gpui/src/upload.rs@@ -23,6 +23,7 @@ mod verify_tests;const MIN_CHUNK_SIZE: u64 = 5 * 1024 * 1024;const MAX_CHUNK_SIZE: u64 = 15 * 1024 * 1024;+const DRIVE_CHUNK_ALIGNMENT: u64 = 256 * 1024;const MAX_SEGMENT_UPLOADS: usize = 6;const SEGMENT_URL_PREFETCH: u32 = 20;const SEGMENT_UPLOAD_ATTEMPTS: u32 = 3;@@ -2447,7 +2448,8 @@ fn read_chunk(path: &Path, offset: u64, size: usize) -> Result<Vec<u8>, AuthApiE}fn chunk_size_for(file_size: u64) -> u64 {- (file_size / 100).clamp(MIN_CHUNK_SIZE, MAX_CHUNK_SIZE)+ let size = (file_size / 100).clamp(MIN_CHUNK_SIZE, MAX_CHUNK_SIZE);+ size / DRIVE_CHUNK_ALIGNMENT * DRIVE_CHUNK_ALIGNMENT}fn md5_base64(bytes: &[u8]) -> String {@@ -2862,6 +2864,28 @@ mod tests {assert_eq!(chunk_size_for(MIN_CHUNK_SIZE * 50), MIN_CHUNK_SIZE);}+ #[test]+ fn chunk_sizes_satisfy_drive_resumable_alignment() {+ for file_size in [+ 1,+ MIN_CHUNK_SIZE * 100,+ MIN_CHUNK_SIZE * 100 + 100,+ 600 * 1024 * 1024,+ 1024 * 1024 * 1024,+ MAX_CHUNK_SIZE * 100 - 100,+ MAX_CHUNK_SIZE * 100,+ MAX_CHUNK_SIZE * 200,+ ] {+ let chunk_size = chunk_size_for(file_size);+ assert!((MIN_CHUNK_SIZE..=MAX_CHUNK_SIZE).contains(&chunk_size));+ assert_eq!(+ chunk_size % (256 * 1024),+ 0,+ "Drive requires aligned intermediate chunks for a {file_size}-byte export"+ );+ }+ }+#[test]fn drive_url_detection() {assert!(is_google_drive_resumable_url(diff --git a/apps/desktop-gpui/src/upload/multipart_tests.rs b/apps/desktop-gpui/src/upload/multipart_tests.rsindex dc399850d..df5be2ea8 100644--- a/apps/desktop-gpui/src/upload/multipart_tests.rs+++ b/apps/desktop-gpui/src/upload/multipart_tests.rs@@ -592,7 +592,9 @@ fn fast_local_profile() -> mock_network::Profile {#[tokio::test]async fn drive_urls_without_a_drive_initiate_are_put_in_order_with_content_range() {- let export = TempExport::new(&export_bytes(4500));+ const CHUNK: usize = 6 * 1024 * 1024;+ const SIZE: usize = 2 * CHUNK + 123;+ let export = TempExport::new(&export_bytes(SIZE));let server = mock_network::start(fast_local_profile());let transport = MockPartTransport {addr: server.addr,@@ -606,36 +608,32 @@ async fn drive_urls_without_a_drive_initiate_are_put_in_order_with_content_range)),drive_urls: true,};- let (result, progress) = run(&transport, &export, 1000, &AtomicBool::new(false), None).await;+ let (result, progress) = run(+ &transport,+ &export,+ chunk_size_for(601 * 1024 * 1024),+ &AtomicBool::new(false),+ None,+ )+ .await;let parts = result.unwrap();assert_eq!(parts.iter().map(|part| (part.part_number, part.size)).collect::<Vec<_>>(),- [(1, 1000), (2, 1000), (3, 1000), (4, 1000), (5, 500)]+ [(1, CHUNK), (2, CHUNK), (3, 123)]);assert_eq!(*server.recorded.puts.lock().unwrap(),[- (1, Some("bytes 0-999/4500".to_string())),- (2, Some("bytes 1000-1999/4500".to_string())),- (3, Some("bytes 2000-2999/4500".to_string())),- (4, Some("bytes 3000-3999/4500".to_string())),- (5, Some("bytes 4000-4499/4500".to_string())),+ (1, Some(format!("bytes 0-{}/{SIZE}", CHUNK - 1))),+ (2, Some(format!("bytes {CHUNK}-{}/{SIZE}", 2 * CHUNK - 1))),+ (3, Some(format!("bytes {}-{}/{SIZE}", 2 * CHUNK, SIZE - 1))),]);assert_eq!(server.recorded.max_active_puts.load(Ordering::Acquire), 1);- assert_eq!(- progress,- [- 1000.0 / 4500.0,- 2000.0 / 4500.0,- 3000.0 / 4500.0,- 4000.0 / 4500.0,- 0.99- ]- );+ assert_eq!(progress, [CHUNK as f64 / SIZE as f64, 0.99, 0.99]);}#[tokio::test]