Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
fix: adding a file with path '/storage/emulated/0' shared from outsid…
Browse files Browse the repository at this point in the history
…e ente to an album failing (#1636)
  • Loading branch information
ashilkn authored Jan 6, 2024
2 parents 377ee5d + 56eb676 commit b89e001
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions lib/utils/share_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,33 @@ Future<List<EnteFile>> convertIncomingSharedMediaToFile(
// fileName: img_x.jpg
enteFile.title = basename(media.path);
var ioFile = File(media.path);
ioFile = ioFile.renameSync(
Configuration.instance.getSharedMediaDirectory() + "/" + enteFile.title!,
);
try {
ioFile = ioFile.renameSync(
Configuration.instance.getSharedMediaDirectory() +
"/" +
enteFile.title!,
);
} catch (e) {
if (e is FileSystemException) {
//from renameSync docs:
//On some platforms, a rename operation cannot move a file between
//different file systems. If that is the case, instead copySync the
//file to the new location and then deleteSync the original.
_logger.info("Creating new copy of file in path ${ioFile.path}");
final newIoFile = ioFile.copySync(
Configuration.instance.getSharedMediaDirectory() +
"/" +
enteFile.title!,
);
if (media.path.contains("io.ente.photos")) {
_logger.info("delete original file in path ${ioFile.path}");
ioFile.deleteSync();
}
ioFile = newIoFile;
} else {
rethrow;
}
}
enteFile.localID = sharedMediaIdentifier + enteFile.title!;
enteFile.collectionID = collectionID;
enteFile.fileType =
Expand Down

0 comments on commit b89e001

Please sign in to comment.