fix: adding a file with path '/storage/emulated/0' shared from outside ente to an album failing

This commit is contained in:
ashilkn 2024-01-06 12:17:21 +05:30
parent 260e61341b
commit 81c199d3a2

View file

@ -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 =