Skip to content

Commit

Permalink
fix(android): download failing for permission issues #1015
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Jan 5, 2024
1 parent c203ac6 commit 5509cae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
1 change: 0 additions & 1 deletion lib/services/download_manager/chunked_download.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:async';
import 'dart:io';

import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import 'package:spotube/models/logger.dart';

final logger = getLogger("ChunkedDownload");
Expand Down
22 changes: 19 additions & 3 deletions lib/services/download_manager/download_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import 'package:collection/collection.dart';

import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import 'package:path/path.dart' as path;
import 'package:path_provider/path_provider.dart';
import 'package:spotube/models/logger.dart';
import 'package:spotube/services/download_manager/chunked_download.dart';
import 'package:spotube/services/download_manager/download_request.dart';
Expand Down Expand Up @@ -77,7 +79,18 @@ class DownloadManager {

logger.d("[DownloadManager] $url");
final file = File(savePath.toString());
partialFilePath = savePath + partialExtension;

final tmpDirPath = await Directory(
path.join(
(await getTemporaryDirectory()).path,
"spotube-downloads",
),
).create(recursive: true);

partialFilePath = path.join(
tmpDirPath.path,
path.basename(savePath) + partialExtension,
);
partialFile = File(partialFilePath);

final fileExist = await file.exists();
Expand Down Expand Up @@ -111,7 +124,9 @@ class DownloadManager {
await ioSink.addStream(partialChunkFile.openRead());
await partialChunkFile.delete();
await ioSink.close();
await partialFile.rename(savePath);

await partialFile.copy(savePath);
await partialFile.delete();

setStatus(task, DownloadStatus.completed);
}
Expand All @@ -125,7 +140,8 @@ class DownloadManager {
);

if (response.statusCode == HttpStatus.ok) {
await partialFile.rename(savePath);
await partialFile.copy(savePath);
await partialFile.delete();
setStatus(task, DownloadStatus.completed);
}
}
Expand Down

0 comments on commit 5509cae

Please sign in to comment.