已合并
【图库看文管】仅删除本地场景bug fix #12264
【图库看文管】仅删除本地场景bug fix #12264
已合并
dichenxu创建于 6月25日
8 个文件变更+170-17
@@ -2046,7 +2046,7 @@ static set<string> GetHiddenUri(const vector<string> &uris)
2046 return result;2046 return result;
2047}2047}
2048 2048 
2049-static void HandleLakeAndFileManager(AccurateRefreshBase &refresh, const std::vector<std::string> &ids)2049+static void HandleLakeAndFileManager(AssetAccurateRefresh &refresh, const std::vector<std::string> &ids)
2050{2050{
2051#ifdef MEDIALIBRARY_LAKE_SUPPORT2051#ifdef MEDIALIBRARY_LAKE_SUPPORT
2052 int32_t ret = LakeFileOperations::MoveAssetsToLake(refresh, ids);2052 int32_t ret = LakeFileOperations::MoveAssetsToLake(refresh, ids);
@@ -38,6 +38,7 @@
38#if defined(MEDIALIBRARY_FILE_MGR_SUPPORT) || defined(MEDIALIBRARY_LAKE_SUPPORT)38#if defined(MEDIALIBRARY_FILE_MGR_SUPPORT) || defined(MEDIALIBRARY_LAKE_SUPPORT)
39#include "media_file_access_utils.h"39#include "media_file_access_utils.h"
40#endif40#endif
41+#include "file_manager_asset_operations.h"
41 42 
42namespace OHOS::Media {43namespace OHOS::Media {
43// LCOV_EXCL_START44// LCOV_EXCL_START
@@ -17,9 +17,10 @@
17#include <string>17#include <string>
18 18 
19#include "asset_accurate_refresh.h"19#include "asset_accurate_refresh.h"
20+#include "photos_po.h"
20 21 
21namespace OHOS::Media {22namespace OHOS::Media {
22- 23+using namespace OHOS::Media::ORM;
23struct MoveAssetsToFileManagerUpdateData {24struct MoveAssetsToFileManagerUpdateData {
24 int32_t mediaId;25 int32_t mediaId;
25 std::string title;26 std::string title;
@@ -32,12 +33,14 @@ class FileManagerAssetOperations {
32public:33public:
33 // 图库到文管,用于隐藏、删除恢复场景34 // 图库到文管,用于隐藏、删除恢复场景
34 static int32_t MoveAssetsToFileManager(35 static int32_t MoveAssetsToFileManager(
35- AccurateRefresh::AccurateRefreshBase &refresh, const std::vector<std::string> &ids);36+ AccurateRefresh::AssetAccurateRefresh &refresh, const std::vector<std::string> &ids);
36 // 文管到图库,用于隐藏、删除场景37 // 文管到图库,用于隐藏、删除场景
37- static int32_t MoveAssetsFromFileManager(AccurateRefresh::AccurateRefreshBase &refresh,38+ static int32_t MoveAssetsFromFileManager(AccurateRefresh::AssetAccurateRefresh &refresh,
38 const std::vector<std::string> &ids, bool needRefresh);39 const std::vector<std::string> &ids, bool needRefresh);
39- static int32_t MoveFileManagerAsset(40+ static int32_t MoveFileManagerAsset(const PhotosPo &photoInfo);
40- const std::string &srcPath, const std::string &destPath, bool isMovingPhoto = false);41+ static int32_t MoveFileManagerAsset(const PhotosPo &photoInfo, const PhotosPo &targetPhotoInfo);
42+ static int32_t MoveFileManagerAsset(const std::string &srcPath,
43+ const std::string &destPath, bool isMovingPhoto = false, bool isLocalRename = true);
41 // 重命名文管资产44 // 重命名文管资产
42 EXPORT static int32_t CheckAndRenameFileManagerAsset(AccurateRefresh::AccurateRefreshBase &refresh,45 EXPORT static int32_t CheckAndRenameFileManagerAsset(AccurateRefresh::AccurateRefreshBase &refresh,
43 MediaLibraryCommand &cmd, const std::shared_ptr<FileAsset> &fileAsset);46 MediaLibraryCommand &cmd, const std::shared_ptr<FileAsset> &fileAsset);
@@ -32,6 +32,8 @@
32#include "photo_file_utils.h"32#include "photo_file_utils.h"
33#include "media_duplicate_checker_utils.h"33#include "media_duplicate_checker_utils.h"
34#include "moving_photo_file_utils.h"34#include "moving_photo_file_utils.h"
35+#include "file_management_utils.h"
36+#include "photo_file_operation.h"
35 37 
36using namespace OHOS::NativeRdb;38using namespace OHOS::NativeRdb;
37using namespace OHOS::Media::AccurateRefresh;39using namespace OHOS::Media::AccurateRefresh;
@@ -57,8 +59,37 @@ static void UpdateModifyTime(const string &path, int64_t localMtime)
57 }59 }
58}60}
59 61 
62+static bool MoveAsset(const std::string &srcPath, const std::string &destPath, bool isLocalRename, int64_t dateModified)
63+{
64+ bool ret = false;
65+ if (isLocalRename) {
66+ std::string localPath = FileManagementUtils::GetLocalPath(destPath);
67+ bool opRet = MediaFileUtils::MoveFile(srcPath, localPath);
68+ if (!opRet) {
69+ MEDIA_WARN_LOG("MoveFile failed, try CrossPolicy mode.");
70+ opRet = MediaFileUtils::MoveFile(srcPath, localPath, true);
71+ if (opRet) {
72+ MediaFileUtils::ModifyFile(localPath, dateModified / MSEC_TO_SEC);
73+ }
74+ }
75+ if (!opRet) {
76+ MEDIA_ERR_LOG("MoveFile failed, srcPath: %{public}s, localPath: %{public}s",
77+ DfxUtils::GetSafePath(srcPath).c_str(), DfxUtils::GetSafePath(localPath).c_str());
78+ return false;
79+ }
80+ } else {
81+ ret = MediaFileUtils::CopyFileAndDelSrc(srcPath, destPath);
82+ if (!ret) {
83+ MEDIA_ERR_LOG("CopyFileUtil failed, srcPath: %{public}s, destPath: %{public}s",
84+ DfxUtils::GetSafePath(srcPath).c_str(), DfxUtils::GetSafePath(destPath).c_str());
85+ return false;
86+ }
87+ }
88+ return true;
89+}
90+ 
60int32_t FileManagerAssetOperations::MoveFileManagerAsset(91int32_t FileManagerAssetOperations::MoveFileManagerAsset(
61- const std::string &srcPath, const std::string &destPath, bool isMovingPhoto)92+ const std::string &srcPath, const std::string &destPath, bool isMovingPhoto, bool isLocalRename)
62{93{
63 MEDIA_INFO_LOG("MoveFileManagerAsset from %{public}s to %{public}s", DfxUtils::GetSafePath(srcPath).c_str(),94 MEDIA_INFO_LOG("MoveFileManagerAsset from %{public}s to %{public}s", DfxUtils::GetSafePath(srcPath).c_str(),
64 DfxUtils::GetSafePath(destPath).c_str());95 DfxUtils::GetSafePath(destPath).c_str());
@@ -75,7 +106,7 @@ int32_t FileManagerAssetOperations::MoveFileManagerAsset(
75 srcPath, destPath, FileSourceType::FILE_MANAGER, true);106 srcPath, destPath, FileSourceType::FILE_MANAGER, true);
76 ret = result.errCode;107 ret = result.errCode;
77 } else {108 } else {
78- ret = MediaFileUtils::CopyFileAndDelSrc(srcPath, destPath) ? E_OK : E_ERR;109+ ret = MoveAsset(srcPath, destPath, isLocalRename, originalDataModified) ? E_OK : E_ERR;
79 }110 }
80 if (isDateModifiedValid) {111 if (isDateModifiedValid) {
81 UpdateModifyTime(destPath, originalDataModified);112 UpdateModifyTime(destPath, originalDataModified);
@@ -83,6 +114,66 @@ int32_t FileManagerAssetOperations::MoveFileManagerAsset(
83 return ret;114 return ret;
84}115}
85 116 
117+int32_t FileManagerAssetOperations::MoveFileManagerAsset(const PhotosPo &photoInfo, const PhotosPo &targetPhotoInfo)
118+{
119+ if (photoInfo.fileSourceType != FileSourceType::FILE_MANAGER) {
120+ MEDIA_ERR_LOG("fileSourceType is not file manager");
121+ return E_ERR;
122+ }
123+ string filePath = photoInfo.data.value_or("");
124+ std::string parentDir = filePath.substr(0, filePath.find_last_of('/'));
125+ if (!MediaFileUtils::IsFileExists(parentDir) && !MediaFileUtils::CreateDirectory(parentDir)) {
126+ MEDIA_ERR_LOG("create dir %{private}s error, the file path is %{public}s",
127+ DfxUtils::GetSafePath(parentDir).c_str(), DfxUtils::GetSafePath(filePath).c_str());
128+ }
129+ int32_t ret = E_ERR;
130+ auto subtype = photoInfo.subtype.value_or(0);
131+ auto effectMode = photoInfo.movingPhotoEffectMode.value_or(0);
132+ auto originalSubtype = photoInfo.originalSubtype.value_or(0);
133+ int64_t dateModified = photoInfo.dateModified.value_or(0);
134+ auto isMovingPhoto = MovingPhotoFileUtils::IsMovingPhoto(subtype, effectMode, originalSubtype);
135+ if (isMovingPhoto) {
136+ MoveResult result = MediaFileAccessUtils::ProcessMovingPhotoToLivePhoto(
137+ photoInfo.data.value_or(""), targetPhotoInfo.storagePath.value_or(""),
138+ FileSourceType::FILE_MANAGER, true);
139+ ret = result.errCode;
140+ } else {
141+ ret = MoveAsset(photoInfo.data.value_or(""),
142+ targetPhotoInfo.storagePath.value_or(""), false, dateModified) ? E_OK : E_ERR;
143+ UpdateModifyTime(targetPhotoInfo.storagePath.value_or(""), dateModified);
144+ }
145+ return ret;
146+}
147+ 
148+int32_t FileManagerAssetOperations::MoveFileManagerAsset(const PhotosPo &photoInfo)
149+{
150+ if (photoInfo.fileSourceType != FileSourceType::FILE_MANAGER) {
151+ MEDIA_ERR_LOG("fileSourceType is not file manager");
152+ return E_ERR;
153+ }
154+ string filePath = photoInfo.data.value_or("");
155+ std::string parentDir = filePath.substr(0, filePath.find_last_of('/'));
156+ if (!MediaFileUtils::IsFileExists(parentDir) && !MediaFileUtils::CreateDirectory(parentDir)) {
157+ MEDIA_ERR_LOG("create dir %{private}s error, the file path is %{public}s",
158+ DfxUtils::GetSafePath(parentDir).c_str(), DfxUtils::GetSafePath(filePath).c_str());
159+ }
160+ int32_t ret = E_ERR;
161+ auto subtype = photoInfo.subtype.value_or(0);
162+ auto effectMode = photoInfo.movingPhotoEffectMode.value_or(0);
163+ auto originalSubtype = photoInfo.originalSubtype.value_or(0);
164+ int64_t dateModified = photoInfo.dateModified.value_or(0);
165+ auto isMovingPhoto = MovingPhotoFileUtils::IsMovingPhoto(subtype, effectMode, originalSubtype);
166+ if (isMovingPhoto) {
167+ MoveResult result = MediaFileAccessUtils::ProcessLivePhotoToMovingPhoto(photoInfo.storagePath.value_or(""),
168+ photoInfo.data.value_or(""), true);
169+ ret = result.errCode;
170+ } else {
171+ ret = MoveAsset(photoInfo.storagePath.value_or(""),
172+ photoInfo.data.value_or(""), true, dateModified) ? E_OK : E_ERR;
173+ }
174+ return ret;
175+}
176+ 
86static int32_t UpdateFileManagerAsset(AccurateRefreshBase &refresh, const MoveAssetsToFileManagerUpdateData &data,177static int32_t UpdateFileManagerAsset(AccurateRefreshBase &refresh, const MoveAssetsToFileManagerUpdateData &data,
87 bool needRefresh)178 bool needRefresh)
88{179{
@@ -138,14 +229,14 @@ static int32_t ReNameAssetsFromFileManager(AccurateRefreshBase &refresh,
138 MoveResult result = MediaFileAccessUtils::ProcessLivePhotoToMovingPhoto(fileManagerPath, mediaPath, true);229 MoveResult result = MediaFileAccessUtils::ProcessLivePhotoToMovingPhoto(fileManagerPath, mediaPath, true);
139 ret = result.errCode;230 ret = result.errCode;
140 } else {231 } else {
141- ret = FileManagerAssetOperations::MoveFileManagerAsset(fileManagerPath, mediaPath);232+ ret = FileManagerAssetOperations::MoveFileManagerAsset(fileManagerPath, mediaPath, false, true);
142 }233 }
143 CHECK_AND_RETURN_RET_LOG(ret == E_OK, E_ERR, "move asset from %{public}s to %{public}s error, errno: %{public}d",234 CHECK_AND_RETURN_RET_LOG(ret == E_OK, E_ERR, "move asset from %{public}s to %{public}s error, errno: %{public}d",
144 DfxUtils::GetSafePath(fileManagerPath).c_str(), DfxUtils::GetSafePath(mediaPath).c_str(), errno);235 DfxUtils::GetSafePath(fileManagerPath).c_str(), DfxUtils::GetSafePath(mediaPath).c_str(), errno);
145 return E_OK;236 return E_OK;
146}237}
147 238 
148-int32_t FileManagerAssetOperations::MoveAssetsFromFileManager(AccurateRefreshBase &refresh,239+int32_t FileManagerAssetOperations::MoveAssetsFromFileManager(AssetAccurateRefresh &refresh,
149 const std::vector<std::string> &ids, bool needRefresh)240 const std::vector<std::string> &ids, bool needRefresh)
150{241{
151 MEDIA_INFO_LOG("MoveAssetsFromFileManager enter %{public}zu", ids.size());242 MEDIA_INFO_LOG("MoveAssetsFromFileManager enter %{public}zu", ids.size());
@@ -178,6 +269,9 @@ int32_t FileManagerAssetOperations::MoveAssetsFromFileManager(AccurateRefreshBas
178 }269 }
179 }270 }
180 resultSet->Close();271 resultSet->Close();
272+ if (needRefresh) {
273+ refresh.RefreshAlbum(NotifyAlbumType::SYS_ALBUM);
274+ }
181 return ret;275 return ret;
182}276}
183 277 
@@ -284,7 +378,7 @@ static int32_t MoveAssetToFileManage(AccurateRefreshBase &refresh,
284 //移动源文件前需要刷新数据库字段378 //移动源文件前需要刷新数据库字段
285 UpdateFileManageAssetInfo(refresh, mediaId, tmpInnerFilePath, tmpDisplayName, tmpTitle);379 UpdateFileManageAssetInfo(refresh, mediaId, tmpInnerFilePath, tmpDisplayName, tmpTitle);
286 int32_t ret = FileManagerAssetOperations::MoveFileManagerAsset(outerFilePath, tmpInnerFilePath,380 int32_t ret = FileManagerAssetOperations::MoveFileManagerAsset(outerFilePath, tmpInnerFilePath,
287- IsMovingPhoto(resultSet));381+ IsMovingPhoto(resultSet), false);
288 CHECK_AND_PRINT_LOG(ret == E_OK, "move asset %{public}s to %{public}s error, errno: %{public}d.",382 CHECK_AND_PRINT_LOG(ret == E_OK, "move asset %{public}s to %{public}s error, errno: %{public}d.",
289 DfxUtils::GetSafePath(outerFilePath).c_str(), DfxUtils::GetSafePath(tmpInnerFilePath).c_str(), errno);383 DfxUtils::GetSafePath(outerFilePath).c_str(), DfxUtils::GetSafePath(tmpInnerFilePath).c_str(), errno);
290 if (ret == E_OK) {384 if (ret == E_OK) {
@@ -295,7 +389,7 @@ static int32_t MoveAssetToFileManage(AccurateRefreshBase &refresh,
295 return E_OK;389 return E_OK;
296}390}
297 391 
298-int32_t FileManagerAssetOperations::MoveAssetsToFileManager(AccurateRefresh::AccurateRefreshBase &refresh,392+int32_t FileManagerAssetOperations::MoveAssetsToFileManager(AccurateRefresh::AssetAccurateRefresh &refresh,
299 const std::vector<std::string> &ids)393 const std::vector<std::string> &ids)
300{394{
301 MEDIA_INFO_LOG("MoveAssetsToFileManage enter %{public}zu", ids.size());395 MEDIA_INFO_LOG("MoveAssetsToFileManage enter %{public}zu", ids.size());
@@ -326,6 +420,7 @@ int32_t FileManagerAssetOperations::MoveAssetsToFileManager(AccurateRefresh::Acc
326 MoveAssetToFileManage(refresh, resultSet);420 MoveAssetToFileManage(refresh, resultSet);
327 }421 }
328 resultSet->Close();422 resultSet->Close();
423+ refresh.RefreshAlbum(NotifyAlbumType::SYS_ALBUM);
329 return E_OK;424 return E_OK;
330}425}
331 426 
@@ -72,6 +72,8 @@ private:
72 int32_t MoveAssetFileOutOfLake(const PhotosPo &photoInfo);72 int32_t MoveAssetFileOutOfLake(const PhotosPo &photoInfo);
73 int32_t CreateLocalAssetWithLakeFile(const PhotosPo &photoInfo, PhotosPo &targetPhotoInfo,73 int32_t CreateLocalAssetWithLakeFile(const PhotosPo &photoInfo, PhotosPo &targetPhotoInfo,
74 std::shared_ptr<AccurateRefresh::AssetAccurateRefresh> &photoRefresh);74 std::shared_ptr<AccurateRefresh::AssetAccurateRefresh> &photoRefresh);
75+ int32_t CreateLocalAssetWithFileManager(const PhotosPo &photoInfo, PhotosPo &targetPhotoInfo,
76+ std::shared_ptr<AccurateRefresh::AssetAccurateRefresh> &photoRefresh);
75 int32_t CopyAndMoveMediaLocalAssetToTrash(const PhotosPo &photoInfo, std::optional<PhotosPo> &targetPhotoInfoOp,77 int32_t CopyAndMoveMediaLocalAssetToTrash(const PhotosPo &photoInfo, std::optional<PhotosPo> &targetPhotoInfoOp,
76 std::shared_ptr<AccurateRefresh::AssetAccurateRefresh> &photoRefresh);78 std::shared_ptr<AccurateRefresh::AssetAccurateRefresh> &photoRefresh);
77 int32_t CopyAndMoveLakeLocalAssetToTrash(const PhotosPo &photoInfo, std::optional<PhotosPo> &targetPhotoInfoOp,79 int32_t CopyAndMoveLakeLocalAssetToTrash(const PhotosPo &photoInfo, std::optional<PhotosPo> &targetPhotoInfoOp,
@@ -119,6 +121,7 @@ private:
119 int32_t GetDentryFileInfo(const PhotosPo &photoInfo, FileManagement::CloudSync::DentryFileInfo &dentryInfo) const;121 int32_t GetDentryFileInfo(const PhotosPo &photoInfo, FileManagement::CloudSync::DentryFileInfo &dentryInfo) const;
120 int32_t ResetUniqueId(PhotosPo &photoInfo);122 int32_t ResetUniqueId(PhotosPo &photoInfo);
121 int32_t ResetTransCode(PhotosPo &photoInfo);123 int32_t ResetTransCode(PhotosPo &photoInfo);
124+ int32_t ResetStoragePath(PhotosPo &photoInfo);
122 125 
123private:126private:
124 MediaAssetsDao mediaAssetsDao_;127 MediaAssetsDao mediaAssetsDao_;
@@ -66,6 +66,7 @@ private:
66 int32_t StoreThumbnailAndEditSize(const PhotosPo &photoInfo);66 int32_t StoreThumbnailAndEditSize(const PhotosPo &photoInfo);
67 int32_t RecoverPackageName(const PhotosPo &sourcePhotoInfo, const PhotosPo &targetPhotoInfo,67 int32_t RecoverPackageName(const PhotosPo &sourcePhotoInfo, const PhotosPo &targetPhotoInfo,
68 std::shared_ptr<AccurateRefresh::AssetAccurateRefresh> &photoRefresh);68 std::shared_ptr<AccurateRefresh::AssetAccurateRefresh> &photoRefresh);
69+ int32_t MoveAssetFileFromMediaToFileManager(const PhotosPo &photoInfo, const PhotosPo &targetPhotoInfo);
69 70 
70private:71private:
71 MediaAssetsDao mediaAssetsDao_;72 MediaAssetsDao mediaAssetsDao_;
@@ -37,6 +37,7 @@
37#include "lake_file_operations.h"37#include "lake_file_operations.h"
38#include "file_scan_utils.h"38#include "file_scan_utils.h"
39#endif39#endif
40+#include "file_manager_asset_operations.h"
40 41 
41namespace OHOS::Media::Common {42namespace OHOS::Media::Common {
42int32_t MediaAssetsDeleteService::DeleteLocalAssets(const std::vector<std::string> &fileIds)43int32_t MediaAssetsDeleteService::DeleteLocalAssets(const std::vector<std::string> &fileIds)
@@ -115,11 +116,8 @@ int32_t MediaAssetsDeleteService::CopyAndMoveFileManagerLocalAssetToTrash(const
115 isValid = isValid && photoInfo.dateTrashed.value_or(0) == 0;116 isValid = isValid && photoInfo.dateTrashed.value_or(0) == 0;
116 CHECK_AND_RETURN_RET(isValid, E_INVALID_MODE);117 CHECK_AND_RETURN_RET(isValid, E_INVALID_MODE);
117 PhotosPo targetPhotoInfo;118 PhotosPo targetPhotoInfo;
118- int32_t opRet = this->CreateLocalAssetWithLakeFile(photoInfo, targetPhotoInfo, photoRefresh);119+ int32_t opRet = this->CreateLocalAssetWithFileManager(photoInfo, targetPhotoInfo, photoRefresh);
119- // Reset the storage position of the LOCAL_AND_CLOUD asset record to CLOUD asset record (cloud only).120+ CHECK_AND_RETURN_RET_LOG(opRet == E_OK, opRet, "CreateLocalAssetWithFileManager fail, ret: %{public}d", opRet);
120- int32_t ret = this->mediaAssetsDao_.ResetFileManagerPositionToCloudOnly(photoRefresh,
121- photoInfo.fileId.value_or(-1));
122- CHECK_AND_RETURN_RET_LOG(ret == E_OK, ret, "UpdatePosition fail, ret: %{public}d", ret);
123 MEDIA_INFO_LOG("CopyAndMoveFileManagerLocalAssetToTrash completed, create asset ret: %{public}d, "121 MEDIA_INFO_LOG("CopyAndMoveFileManagerLocalAssetToTrash completed, create asset ret: %{public}d, "
124 "sourceFileId: %{public}d, targetFileId: %{public}d, cloudId: %{public}s",122 "sourceFileId: %{public}d, targetFileId: %{public}d, cloudId: %{public}s",
125 opRet,123 opRet,
@@ -433,6 +431,9 @@ int32_t MediaAssetsDeleteService::CreateLocalTrashedPhotosPo(const PhotosPo &pho
433 this->ResetSouthDeviceType(targetPhotoInfo); // Reset south_device_type to default: SOUTH_DEVICE_NULL(0).431 this->ResetSouthDeviceType(targetPhotoInfo); // Reset south_device_type to default: SOUTH_DEVICE_NULL(0).
434 this->ResetUniqueId(targetPhotoInfo);432 this->ResetUniqueId(targetPhotoInfo);
435 this->ResetTransCode(targetPhotoInfo);433 this->ResetTransCode(targetPhotoInfo);
434+ if (photoInfo.ShouldHandleAsFileManager()) {
435+ this->ResetStoragePath(targetPhotoInfo);
436+ }
436 return E_OK;437 return E_OK;
437}438}
438 439 
@@ -568,6 +569,31 @@ int32_t MediaAssetsDeleteService::CreateLocalAssetWithLakeFile(const PhotosPo &p
568 return ret;569 return ret;
569}570}
570 571 
572+int32_t MediaAssetsDeleteService::CreateLocalAssetWithFileManager(const PhotosPo &photoInfo, PhotosPo &targetPhotoInfo,
573+ std::shared_ptr<AccurateRefresh::AssetAccurateRefresh> &photoRefresh)
574+{
575+ int32_t ret = this->CreateLocalTrashedPhotosPo(photoInfo, targetPhotoInfo);
576+ CHECK_AND_RETURN_RET_LOG(ret == E_OK, ret, "CreateLocalTrashedPhotosPo fail, ret: %{public}d", ret);
577+ 
578+ // 原图更新为纯云资产,删除本地文件路径
579+ // Reset the storage position of the LOCAL_AND_CLOUD asset record to CLOUD asset record (cloud only).
580+ ret = this->mediaAssetsDao_.ResetFileManagerPositionToCloudOnly(photoRefresh,
581+ photoInfo.fileId.value_or(-1));
582+ CHECK_AND_RETURN_RET_LOG(ret == E_OK, ret, "ResetFileManagerPositionToCloudOnly fail, ret: %{public}d", ret);
583+ 
584+ ret = this->MoveLocalAssetFile(photoInfo, targetPhotoInfo);
585+ CHECK_AND_RETURN_RET_LOG(ret == E_OK, ret, "MoveLocalAssetFile fail, ret: %{public}d", ret);
586+ 
587+ if (targetPhotoInfo.fileSourceType == FileSourceType::MEDIA && targetPhotoInfo.storagePath.value_or("") != "") {
588+ targetPhotoInfo.storagePath = "";
589+ }
590+ // Create the new asset record in the database.
591+ ret = this->CreateNewAssetInfoAndReturnFileId(targetPhotoInfo, photoRefresh);
592+ CHECK_AND_RETURN_RET_LOG(ret == E_OK, ret, "CreateNewAssetInfoAndReturnFileId fail, ret: %{public}d", ret);
593+ this->MoveOrGenerateLocalThumbnail(photoInfo, targetPhotoInfo);
594+ return ret;
595+}
596+ 
571int32_t MediaAssetsDeleteService::CopyAndMoveMediaLocalAssetToTrash(const PhotosPo &photoInfo,597int32_t MediaAssetsDeleteService::CopyAndMoveMediaLocalAssetToTrash(const PhotosPo &photoInfo,
572 std::optional<PhotosPo> &targetPhotoInfoOp, std::shared_ptr<AccurateRefresh::AssetAccurateRefresh> &photoRefresh)598 std::optional<PhotosPo> &targetPhotoInfoOp, std::shared_ptr<AccurateRefresh::AssetAccurateRefresh> &photoRefresh)
573{599{
@@ -1070,4 +1096,10 @@ int32_t MediaAssetsDeleteService::ResetTransCode(PhotosPo &photoInfo)
1070 }1096 }
1071 return E_OK;1097 return E_OK;
1072}1098}
1099+ 
1100+int32_t MediaAssetsDeleteService::ResetStoragePath(PhotosPo &photoInfo)
1101+{
1102+ photoInfo.storagePath.reset();
1103+ return E_OK;
1104+}
1073} // namespace OHOS::Media::Common1105} // namespace OHOS::Media::Common
@@ -30,6 +30,7 @@
30#include "dfx_utils.h"30#include "dfx_utils.h"
31#include "medialibrary_album_operations.h"31#include "medialibrary_album_operations.h"
32#include "medialibrary_photo_operations.h"32#include "medialibrary_photo_operations.h"
33+#include "file_manager_asset_operations.h"
33 34 
34namespace OHOS::Media::Common {35namespace OHOS::Media::Common {
35int32_t MediaAssetsRecoverService::BatchMoveOutTrashAndMergeWithSameAsset(36int32_t MediaAssetsRecoverService::BatchMoveOutTrashAndMergeWithSameAsset(
@@ -242,6 +243,9 @@ int32_t MediaAssetsRecoverService::MoveAssetFileFromMediaToLake(
242{243{
243 std::string mediaPath = photoInfo.data.value_or("");244 std::string mediaPath = photoInfo.data.value_or("");
244 std::string lakePath = targetPhotoInfo.storagePath.value_or("");245 std::string lakePath = targetPhotoInfo.storagePath.value_or("");
246+ if (targetPhotoInfo.ShouldHandleAsMediaFile()) {
247+ return MoveAssetFileFromMediaToFileManager(photoInfo, targetPhotoInfo);
248+ }
245 bool isValid = photoInfo.ShouldHandleAsMediaFile();249 bool isValid = photoInfo.ShouldHandleAsMediaFile();
246 isValid = isValid && !lakePath.empty();250 isValid = isValid && !lakePath.empty();
247 CHECK_AND_RETURN_RET_LOG(isValid, E_OK, "No need to move file, target is not in lake.");251 CHECK_AND_RETURN_RET_LOG(isValid, E_OK, "No need to move file, target is not in lake.");
@@ -438,4 +442,18 @@ int32_t MediaAssetsRecoverService::StoreThumbnailAndEditSize(const PhotosPo &pho
438 MediaLibraryPhotoOperations::StoreThumbnailAndEditSize(std::to_string(fileId), data);442 MediaLibraryPhotoOperations::StoreThumbnailAndEditSize(std::to_string(fileId), data);
439 return E_OK;443 return E_OK;
440}444}
445+ 
446+int32_t MediaAssetsRecoverService::MoveAssetFileFromMediaToFileManager(
447+ const PhotosPo &photoInfo, const PhotosPo &targetPhotoInfo)
448+{
449+ int32_t ret = FileManagerAssetOperations::MoveFileManagerAsset(photoInfo, targetPhotoInfo);
450+ MEDIA_INFO_LOG(
451+ "MoveAssetFileFromMediaToFileManager, ret: %{public}d, storagePath: %{public}s,\
452+ data: %{public}s, errno: %{public}d",
453+ ret,
454+ DfxUtils::GetSafePath(photoInfo.data.value_or("")).c_str(),
455+ DfxUtils::GetSafePath(targetPhotoInfo.storagePath.value_or("")).c_str(),
456+ errno);
457+ return ret;
458+}
441} // namespace OHOS::Media::Common459} // namespace OHOS::Media::Common