Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Simplify by removing range probe fallback

laurenspriem661231796eec
diff --git a/mobile/apps/photos/lib/services/remote_assets_service.dart b/mobile/apps/photos/lib/services/remote_assets_service.dart
index 626fa13068..ae5d969b19 100644
--- a/mobile/apps/photos/lib/services/remote_assets_service.dart
+++ b/mobile/apps/photos/lib/services/remote_assets_service.dart
@@ -113,26 +113,13 @@ class RemoteAssetsService {
if (_shouldUseResumableDownload(probe)) {
await _downloadFileResumable(url, savePath, probe!);
} else {
- await _downloadFileSingleShot(
- url,
- savePath,
- preservePartialDownload: await _hasResumableDownloadState(savePath),
- );
+ await _downloadFileSingleShot(url, savePath);
}
_logger.info("Downloaded " + url);
}
- Future<void> _downloadFileSingleShot(
- String url,
- String savePath, {
- bool preservePartialDownload = false,
- }) async {
- if (preservePartialDownload) {
- await _downloadFileSingleShotPreservingResume(url, savePath);
- return;
- }
-
+ Future<void> _downloadFileSingleShot(String url, String savePath) async {
await _clearResumeArtifacts(savePath);
await _dio.download(
@@ -144,29 +131,6 @@ class RemoteAssetsService {
);
}
- Future<void> _downloadFileSingleShotPreservingResume(
- String url,
- String savePath,
- ) async {
- final scratchFile = File(_singleShotScratchPath(savePath));
- await _deleteFileIfExists(scratchFile);
-
- try {
- await _dio.download(
- url,
- scratchFile.path,
- onReceiveProgress: (received, total) {
- _emitProgress(url, received, total);
- },
- );
- await _replaceFile(scratchFile, File(savePath));
- await _deleteResumeMetadata(savePath);
- } catch (e) {
- await _deleteFileIfExists(scratchFile);
- rethrow;
- }
- }
-
Future<void> cleanupOldModelsIfNeeded() async {
if (checkRemovedOldAssets) return;
const oldModelNames = [
@@ -212,8 +176,6 @@ class RemoteAssetsService {
String _resumeMetadataPath(String tempPath) => "$tempPath.resume.json";
- String _singleShotScratchPath(String savePath) => "$savePath.single";
-
bool _shouldUseResumableDownload(_RemoteAssetProbe? probe) {
if (!_resumableDownloadsEnabled || probe == null) {
return false;
@@ -226,24 +188,6 @@ class RemoteAssetsService {
return null;
}
- final headProbe = await _probeWithHead(url);
- if (headProbe != null &&
- (headProbe.canResume ||
- headProbe.totalBytes <= _resumableThresholdBytes)) {
- return headProbe;
- }
-
- final rangeProbe = await _probeWithRange(url);
- if (headProbe == null) {
- return rangeProbe;
- }
- if (rangeProbe == null) {
- return headProbe;
- }
- return headProbe.merge(rangeProbe);
- }
-
- Future<_RemoteAssetProbe?> _probeWithHead(String url) async {
try {
final response = await _dio.head<void>(url);
return _RemoteAssetProbe.fromHeaders(
@@ -257,41 +201,6 @@ class RemoteAssetsService {
}
}
- Future<_RemoteAssetProbe?> _probeWithRange(String url) async {
- Response<ResponseBody>? response;
- try {
- response = await _dio.get<ResponseBody>(
- url,
- options: Options(
- responseType: ResponseType.stream,
- headers: {
- HttpHeaders.rangeHeader: "bytes=0-0",
- },
- validateStatus: (status) =>
- status == HttpStatus.ok || status == HttpStatus.partialContent,
- ),
- );
- return _RemoteAssetProbe.fromHeaders(
- url,
- response.statusCode,
- response.headers,
- );
- } catch (e) {
- _logger.fine("Range probe failed for $url: $e");
- return null;
- } finally {
- await _cancelProbeResponse(response?.data);
- }
- }
-
- Future<void> _cancelProbeResponse(ResponseBody? body) async {
- if (body == null) {
- return;
- }
- final subscription = body.stream.listen((_) {});
- await subscription.cancel();
- }
-
Future<void> _downloadFileResumable(
String url,
String savePath,
@@ -505,17 +414,6 @@ class RemoteAssetsService {
}
}
- Future<bool> _hasResumableDownloadState(String savePath) async {
- final tempFile = File(savePath);
- if (!await tempFile.exists()) {
- return false;
- }
- if (await tempFile.length() <= 0) {
- return false;
- }
- return File(_resumeMetadataPath(savePath)).exists();
- }
-
Future<void> _clearResumeArtifacts(String tempPath) async {
await _deleteFileIfExists(File(tempPath));
await _deleteResumeMetadata(tempPath);
@@ -590,16 +488,6 @@ class _RemoteAssetProbe {
bool get canResume => acceptsRanges && hasStableValidator;
- _RemoteAssetProbe merge(_RemoteAssetProbe other) {
- return _RemoteAssetProbe(
- url: url,
- totalBytes: other.totalBytes > 0 ? other.totalBytes : totalBytes,
- acceptsRanges: acceptsRanges || other.acceptsRanges,
- etag: other.etag ?? etag,
- lastModified: other.lastModified ?? lastModified,
- );
- }
-
static int? _parseTotalBytes(Headers headers) {
final contentRange = headers.value(HttpHeaders.contentRangeHeader);
if (contentRange != null) {