Skip to content

Commit

Permalink
fix: Avoid collisions when save file on android
Browse files Browse the repository at this point in the history
  • Loading branch information
krille-chan committed Oct 7, 2023
1 parent 9c1c5a4 commit 759d96f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/utils/matrix_sdk_extensions/matrix_file_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ extension MatrixFileExtension on MatrixFile {

Future<String> getDownloadPathAndroid() async {
final directory = await getDownloadDirectoryAndroid();
return '${directory.path}/$name';
var counter = 1;
var path = '${directory.path}/$name';
while (await File(path).exists()) {
path = '${directory.path}/(${counter++})$name';
}
return path;
}

Future<Directory> getDownloadDirectoryAndroid() async {
Expand Down

0 comments on commit 759d96f

Please sign in to comment.