diff --git a/frameworks/native/cloudsync_kit_inner/src/cloud_sync_common.cpp b/frameworks/native/cloudsync_kit_inner/src/cloud_sync_common.cpp index b3688e4a3e94c6bf9a6b5765f881183cdc8cf36c..633009c067edbaeeab0be0fa4b12a30b69b8119e 100644 --- a/frameworks/native/cloudsync_kit_inner/src/cloud_sync_common.cpp +++ b/frameworks/native/cloudsync_kit_inner/src/cloud_sync_common.cpp @@ -475,7 +475,7 @@ bool CloudFileInfo::ReadFromParcel(Parcel &parcel) std::string DownloadProgressObj::to_string() { std::stringstream ss; - std::string pathAnony = GetAnonyString(path); + std::string pathAnony = GetAnonyPath(path); ss << "DownloadProgressObj [path: " << pathAnony; ss << " state: " << state; ss << " downloaded: " << downloadedSize; diff --git a/services/clouddisk_database/src/clouddisk_rdbstore.cpp b/services/clouddisk_database/src/clouddisk_rdbstore.cpp index 571f95b20f31dfc0360c0a23fbe6d67f15431d81..f5fb6d79311a29881a812b357dda36a8677dd7ef 100644 --- a/services/clouddisk_database/src/clouddisk_rdbstore.cpp +++ b/services/clouddisk_database/src/clouddisk_rdbstore.cpp @@ -381,7 +381,7 @@ static int32_t CreateFile(const std::string &fileName, const std::string &filePa { int32_t ret = stat(filePath.c_str(), statInfo); if (ret) { - LOGE("filePath %{private}s is invalid", GetAnonyString(filePath).c_str()); + LOGE("filePath %{public}s is invalid", GetAnonyPath(filePath).c_str()); return E_PATH; } fileInfo.PutInt(FileColumn::IS_DIRECTORY, FILE); @@ -611,7 +611,7 @@ int32_t CloudDiskRdbStore::Write(const std::string &fileName, const std::string struct stat statInfo {}; ret = stat(filePath.c_str(), &statInfo); if (ret) { - LOGE("filePath %{private}s is invalid", GetAnonyString(filePath).c_str()); + LOGE("filePath %{public}s is invalid", GetAnonyPath(filePath).c_str()); return E_PATH; } CloudDiskFileInfo info; diff --git a/services/cloudfiledaemon/src/cloud_disk/file_operations_cloud.cpp b/services/cloudfiledaemon/src/cloud_disk/file_operations_cloud.cpp index de9d960d06023edc9b49d99cb7d9d1796e523658..6a4932f6e582a47a71975d319455240c13f16825 100644 --- a/services/cloudfiledaemon/src/cloud_disk/file_operations_cloud.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/file_operations_cloud.cpp @@ -436,7 +436,8 @@ static int32_t HandleCloudOpenSuccess(struct fuse_file_info *fi, struct CloudDis auto rdbstore = databaseManager.GetRdbStore(inoPtr->bundleName, data->userId); rdbstore->UpdateTHMStatus(metaFile, metaBase, CloudSync::DOWNLOADED_THM); } else { - LOGE("path rename failed, tmpPath:%{public}s, errno:%{public}d", tmpPath.c_str(), errno); + LOGE("path rename failed, tmpPath:%{public}s, errno:%{public}d", + GetAnonyPath(tmpPath).c_str(), errno); return errno; } } @@ -610,7 +611,7 @@ void FileOperationsCloud::Open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_ int32_t fd = open(path.c_str(), flags); if (fd < 0) { CLOUD_FILE_FAULT_REPORT(CloudFile::CloudFileFaultInfo{"", CloudFile::FaultOperation::OPEN, - CloudFile::FaultType::FILE, errno, "open file failed path:" + GetAnonyString(path) + + CloudFile::FaultType::FILE, errno, "open file failed path:" + GetAnonyPath(path) + " errno: " + std::to_string(errno)}); fuse_inval(data->se, inoPtr->parent, ino, inoPtr->fileName); return (void) fuse_reply_err(req, errno); @@ -642,7 +643,7 @@ static int32_t CreateLocalFile(const string &cloudId, const string &bundleName, int32_t fd = open(path.c_str(), (mode & O_NOFOLLOW) | O_CREAT | O_RDWR, STAT_MODE_REG); if (fd < 0) { CLOUD_FILE_FAULT_REPORT(CloudFile::CloudFileFaultInfo{"", CloudFile::FaultOperation::MKNOD, - CloudFile::FaultType::FILE, errno, "create file failed :" + GetAnonyString(path) + + CloudFile::FaultType::FILE, errno, "create file failed :" + GetAnonyPath(path) + " err: " + std::to_string(errno)}); return -errno; } @@ -655,7 +656,7 @@ void RemoveLocalFile(const string &path) int32_t err = remove(path.c_str()); if (err != 0) { CLOUD_FILE_FAULT_REPORT(CloudFile::CloudFileFaultInfo{"", CloudFile::FaultOperation::MKNOD, - CloudFile::FaultType::WARNING, errno, "remove file " + GetAnonyString(path) + " failed, "+ + CloudFile::FaultType::WARNING, errno, "remove file " + GetAnonyPath(path) + " failed, "+ "error: " + std::to_string(errno)}); } } @@ -1428,7 +1429,7 @@ int32_t DoCloudUnlink(fuse_req_t req, fuse_ino_t parent, const char *name) LOGD("doUnlink, dentry file has been deleted"); if (isDirectory == FILE && position != CLOUD) { string localPath = CloudFileUtils::GetLocalFilePath(cloudId, parentInode->bundleName, data->userId); - LOGI("unlink %{public}s", GetAnonyString(localPath).c_str()); + LOGI("unlink %{public}s", GetAnonyPath(localPath).c_str()); int32_t ret = unlink(localPath.c_str()); if (ret != 0 && errno == ENOENT) { std::string errMsg = "doCloudUnlink, unlink local file ret ENOENT."; @@ -1719,7 +1720,7 @@ static int32_t UpdateCacheDentrySize(CloudDiskFuseData *data, fuse_ino_t ino) int32_t ret = stat(filePath.c_str(), &statInfo); if (ret != 0) { CLOUD_FILE_FAULT_REPORT(CloudFile::CloudFileFaultInfo{inoPtr->bundleName, CloudFile::FaultOperation::WRITE, - CloudFile::FaultType::FILE, errno, "filePath " + GetAnonyString(filePath) + " is invalid"}); + CloudFile::FaultType::FILE, errno, "filePath " + GetAnonyPath(filePath) + " is invalid"}); return errno; } MetaBase metaBase(inoPtr->fileName); diff --git a/services/cloudfiledaemon/src/cloud_disk/file_operations_helper.cpp b/services/cloudfiledaemon/src/cloud_disk/file_operations_helper.cpp index 03b35c1d53dd817a114aeb762a24995f7460dc4e..860e405583c296954b472728fd5a9fdb3698b5fd 100644 --- a/services/cloudfiledaemon/src/cloud_disk/file_operations_helper.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/file_operations_helper.cpp @@ -168,7 +168,7 @@ shared_ptr FileOperationsHelper::GenerateCloudDiskInode(struct C int32_t err = stat(path.c_str(), &child->stat); if (err != 0) { CLOUD_FILE_FAULT_REPORT(CloudFile::CloudFileFaultInfo{child->bundleName, CloudFile::FaultOperation::READDIR, - CloudFile::FaultType::INODE_FILE, errno, "GenerateCloudDiskInode " + GetAnonyString(path) + " error" + + CloudFile::FaultType::INODE_FILE, errno, "GenerateCloudDiskInode " + GetAnonyPath(path) + " error" + "err: " + std::to_string(errno)}); return nullptr; } diff --git a/services/cloudfiledaemon/src/cloud_disk/file_operations_local.cpp b/services/cloudfiledaemon/src/cloud_disk/file_operations_local.cpp index 78371776d7cae2fa1bcd31d54ebaa4ec73901bac..91b2b909a97ec0ced98343ca16eb253befdbf1d8 100644 --- a/services/cloudfiledaemon/src/cloud_disk/file_operations_local.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/file_operations_local.cpp @@ -57,7 +57,7 @@ static int32_t DoLocalLookup(fuse_req_t req, fuse_ino_t parent, const char *name if (createFlag) { if (stat(path.c_str(), &child->stat) != 0) { CLOUD_FILE_FAULT_REPORT(CloudFile::CloudFileFaultInfo{child->bundleName, CloudFile::FaultOperation::LOOKUP, - CloudFile::FaultType::INODE_FILE, errno, "lookup " + GetAnonyString(path) + " error, err: " + + CloudFile::FaultType::INODE_FILE, errno, "lookup " + GetAnonyPath(path) + " error, err: " + std::to_string(errno)}); return errno; } @@ -123,7 +123,7 @@ void FileOperationsLocal::GetAttr(fuse_req_t req, fuse_ino_t ino, struct fuse_fi int err = stat(path.c_str(), &statBuf); if (err != 0) { CLOUD_FILE_FAULT_REPORT(CloudFile::CloudFileFaultInfo{"", CloudFile::FaultOperation::GETATTR, - CloudFile::FaultType::FILE, errno, "lookup " + GetAnonyString(path) + " error, err: " + + CloudFile::FaultType::FILE, errno, "lookup " + GetAnonyPath(path) + " error, err: " + std::to_string(errno)}); fuse_reply_err(req, errno); #ifdef HICOLLIE_ENABLE @@ -176,7 +176,7 @@ void FileOperationsLocal::ReadDir(fuse_req_t req, fuse_ino_t ino, size_t size, o if (dir == NULL) { CLOUD_FILE_FAULT_REPORT(CloudFile::CloudFileFaultInfo{"", CloudFile::FaultOperation::READDIR, CloudFile::FaultType::FILE, errno, "opendir error " + std::to_string(errno) + ", path: " + - GetAnonyString(path)}); + GetAnonyPath(path)}); return; } diff --git a/services/cloudfiledaemon/src/fuse_manager/fuse_manager.cpp b/services/cloudfiledaemon/src/fuse_manager/fuse_manager.cpp index 9c6ccb2f49622f85c6cc35a37626f7403ad19ba8..6bcc2a8c25553b5af531fa7c97c1426352b0d420 100644 --- a/services/cloudfiledaemon/src/fuse_manager/fuse_manager.cpp +++ b/services/cloudfiledaemon/src/fuse_manager/fuse_manager.cpp @@ -359,7 +359,7 @@ static void XcollieCallback(void *xcollie) break; } - string msg = "In XcollieCallback, path:" + GetAnonyString((inode->path).c_str()); + string msg = "In XcollieCallback, path:" + GetAnonyPath((inode->path).c_str()); CLOUD_FILE_FAULT_REPORT(CloudFileFaultInfo{PHOTOS_BUNDLE_NAME, xcollieInput->faultOperation_, faultType, EWOULDBLOCK, msg}); } @@ -730,7 +730,7 @@ static void DownloadThmOrLcd(shared_ptr cInode, shared_ptrnotify_one(); - LOGI("download done, path: %{public}s", GetAnonyString(cInode->path).c_str()); + LOGI("download done, path: %{public}s", GetAnonyPath(cInode->path).c_str()); return; } @@ -852,7 +852,7 @@ static int DoCloudOpen(shared_ptr cInode, struct fuse_file_info *fi, }); if (!waitStatus) { string prepareTraceId = cInode->readSession->GetPrepareTraceId(); - string msg = "init session timeout, path: " + GetAnonyString((cInode->path).c_str()) + + string msg = "init session timeout, path: " + GetAnonyPath((cInode->path).c_str()) + " prepareTraceId: " + prepareTraceId; CLOUD_FILE_FAULT_REPORT(CloudFileFaultInfo{PHOTOS_BUNDLE_NAME, FaultOperation::OPEN, FaultType::OPEN_CLOUD_FILE_TIMEOUT, ENETUNREACH, msg}); @@ -936,7 +936,7 @@ static void CloudOpenHelper(fuse_req_t req, fuse_ino_t ino, struct fuse_file_inf std::unique_lock wSesLock(cInode->sessionLock, std::defer_lock); string prepareTraceId = GetPrepareTraceId(data->userId); - LOGI("%{public}d open %{public}s", pid, GetAnonyString(CloudPath(data, ino)).c_str()); + LOGI("%{public}d open %{public}s", pid, GetAnonyPath(CloudPath(data, ino)).c_str()); if (!database) { LOGE("database is null"); fuse_inval(data->se, cInode->parent, ino, cInode->mBase->name); @@ -1008,7 +1008,7 @@ static void CloudRelease(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info * } std::unique_lock wSesLock(cInode->sessionLock, std::defer_lock); LOGI("%{public}d release %{public}s, sessionRefCount: %{public}d", pid, - GetAnonyString(cInode->path).c_str(), cInode->sessionRefCount.load()); + GetAnonyPath(cInode->path).c_str(), cInode->sessionRefCount.load()); wSesLock.lock(); cInode->sessionRefCount--; if (fi->fh != UINT64_MAX) { @@ -1246,7 +1246,7 @@ static void CloudReadOnCloudFile(pid_t pid, shared_ptr readSession) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - LOGI("PRead CloudFile, path: %{public}s, size: %{public}zd, off: %{public}lu", GetAnonyString(cInode->path).c_str(), + LOGI("PRead CloudFile, path: %{public}s, size: %{public}zd, off: %{public}lu", GetAnonyPath(cInode->path).c_str(), readArgs->size, static_cast(readArgs->offset)); uint64_t startTime = UTCTimeMilliSeconds(); @@ -1320,7 +1320,7 @@ static void CloudReadOnCacheFile(shared_ptr readArgs, readArgs->size = MAX_READ_SIZE; readArgs->buf.reset(new char[MAX_READ_SIZE], [](char *ptr) { delete[] ptr; }); LOGI("To do preread cloudfile path: %{public}s, size: %{public}zd, offset: %{public}ld*4M", - GetAnonyString(cInode->path).c_str(), readArgs->size, static_cast(cacheIndex)); + GetAnonyPath(cInode->path).c_str(), readArgs->size, static_cast(cacheIndex)); *readArgs->readResult = readSession->PRead(readArgs->offset, readArgs->size, readArgs->buf.get(), *readArgs->ckError); @@ -1598,7 +1598,7 @@ static void CloudRead(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, return; } LOGI("CloudRead: %{public}s, size=%{public}zd, off=%{public}lu", - GetAnonyString(CloudPath(data, ino)).c_str(), size, (unsigned long)off); + GetAnonyPath(CloudPath(data, ino)).c_str(), size, (unsigned long)off); if (!CloudReadHelper(req, size, cInode)) { return; diff --git a/services/cloudfiledaemon/src/ipc/cloud_daemon.cpp b/services/cloudfiledaemon/src/ipc/cloud_daemon.cpp index 9ad6c858375eb6bf6f79e1793c2342848f5243e4..ab56b4a39eb3e3a0646238fe17a3699c28f62010 100644 --- a/services/cloudfiledaemon/src/ipc/cloud_daemon.cpp +++ b/services/cloudfiledaemon/src/ipc/cloud_daemon.cpp @@ -131,27 +131,27 @@ void HandleStartMove(int32_t userId) string removePath = srcBase + "/" + subList[1] + "/backup"; bool ret = Storage::DistributedFile::Utils::ForceRemoveDirectoryDeepFirst(removePath); if (!ret) { - LOGE("remove failed path: %{public}s", GetAnonyString(removePath).c_str()); + LOGE("remove failed path: %{public}s", GetAnonyPath(removePath).c_str()); } const auto copyOptions = filesystem::copy_options::overwrite_existing | filesystem::copy_options::recursive; for (auto sub : subList) { string srcPath = srcBase + '/' + sub; string dstPath = dstBase + '/' + sub; if (access(srcPath.c_str(), F_OK) != 0) { - LOGI("srcPath %{public}s not found", GetAnonyString(srcPath).c_str()); + LOGI("srcPath %{public}s not found", GetAnonyPath(srcPath).c_str()); continue; } - LOGI("Begin to move path: %{public}s", GetAnonyString(srcPath).c_str()); + LOGI("Begin to move path: %{public}s", GetAnonyPath(srcPath).c_str()); error_code errCode; filesystem::copy(srcPath, dstPath, copyOptions, errCode); if (errCode.value() != 0) { LOGE("copy failed path: %{public}s, errCode: %{public}d", - GetAnonyString(srcPath).c_str(), errCode.value()); + GetAnonyPath(srcPath).c_str(), errCode.value()); } - LOGI("End move path: %{public}s", GetAnonyString(srcPath).c_str()); + LOGI("End move path: %{public}s", GetAnonyPath(srcPath).c_str()); bool ret = Storage::DistributedFile::Utils::ForceRemoveDirectoryDeepFirst(srcPath); if (!ret) { - LOGE("remove failed path: %{public}s", GetAnonyString(srcPath).c_str()); + LOGE("remove failed path: %{public}s", GetAnonyPath(srcPath).c_str()); } } system::SetParameter(moveFile, "true"); diff --git a/services/cloudsyncservice/src/ipc/cloud_sync_service.cpp b/services/cloudsyncservice/src/ipc/cloud_sync_service.cpp index 7574dcb100595e63d3e9d10643012e8ec104629a..1a3787f156d0f591ebf5b428afc4490e59ef0843 100644 --- a/services/cloudsyncservice/src/ipc/cloud_sync_service.cpp +++ b/services/cloudsyncservice/src/ipc/cloud_sync_service.cpp @@ -968,7 +968,7 @@ int32_t CloudSyncService::DownloadFile(const int32_t userId, asset.uri = GetHmdfsPath(assetInfoObj.uri, userId); if (asset.uri.empty()) { - LOGE("fail to get download path from %{public}s", GetAnonyString(assetInfoObj.uri).c_str()); + LOGE("fail to get download path from %{public}s", GetAnonyPath(assetInfoObj.uri).c_str()); return E_INVAL_ARG; } @@ -1007,7 +1007,7 @@ int32_t CloudSyncService::DownloadFiles(const int32_t userId, asset.assetName = obj.assetName; asset.uri = GetHmdfsPath(obj.uri, userId); if (asset.uri.empty()) { - LOGE("fail to get download path from %{private}s", GetAnonyString(obj.uri).c_str()); + LOGE("fail to get download path from %{private}s", GetAnonyPath(obj.uri).c_str()); return E_INVAL_ARG; } DownloadAssetInfo assetToDownload{obj.recordType, obj.recordId, {}, asset, {}}; diff --git a/services/cloudsyncservice/src/transport/file_transfer_manager.cpp b/services/cloudsyncservice/src/transport/file_transfer_manager.cpp index d74c251108487f30dfefc9ea955432249c5d8fa3..4f5f174ac34a82d37940ece5de7eb00514fb04e1 100644 --- a/services/cloudsyncservice/src/transport/file_transfer_manager.cpp +++ b/services/cloudsyncservice/src/transport/file_transfer_manager.cpp @@ -58,7 +58,7 @@ void FileTransferManager::DownloadFileFromRemoteDevice(const std::string &networ LOGI("send data, dataLen:%{public}d, taskId: %{public}" PRIu64 "", dataLen, taskId); auto ret = sessionManager_->SendData(networkId, data.get(), dataLen); if (ret != E_OK) { - LOGE("download file failed, uri:%{public}s, ret:%{public}d", GetAnonyString(uri).c_str(), ret); + LOGE("download file failed, uri:%{public}s, ret:%{public}d", GetAnonyPath(uri).c_str(), ret); DownloadAssetCallbackManager::GetInstance().OnDownloadFinshed(taskId, uri, ret); DecTransTaskCount(); } else { @@ -152,7 +152,7 @@ void FileTransferManager::OnMessageHandle(const std::string &senderNetworkId, void FileTransferManager::OnFileRecvHandle(const std::string &senderNetworkId, const char *filePath, int result) { - LOGE("received file, file path:%{public}s, result:%{public}d", GetAnonyString(filePath).c_str(), result); + LOGE("received file, file path:%{public}s, result:%{public}d", GetAnonyPath(filePath).c_str(), result); DecTransTaskCount(); // allways dec task count when finsh one task if (filePath != nullptr) { FinishTransTask(string(filePath), result); @@ -179,7 +179,7 @@ void FileTransferManager::OnSessionClosed() // avoid sa cannot unload when sessi bool FileTransferManager::IsFileExists(const std::string &filePath) { if (access(filePath.c_str(), F_OK) != E_OK) { - LOGE("file is not exist, path:%{public}s, error:%{public}s", GetAnonyString(filePath).c_str(), strerror(errno)); + LOGE("file is not exist, path:%{public}s, error:%{public}s", GetAnonyPath(filePath).c_str(), strerror(errno)); return false; } return true; diff --git a/utils/log/include/utils_log.h b/utils/log/include/utils_log.h index 82b307282dfedd9d8708aee7f716ff3f1788a7e9..7712fc4fbfcd6b28eb2b1547d32050ef95b0d7fb 100644 --- a/utils/log/include/utils_log.h +++ b/utils/log/include/utils_log.h @@ -45,5 +45,6 @@ std::string GetFileNameFromFullPath(const char *str); std::string GetAnonyString(const std::string &value); std::string GetAnonyInt32(const int32_t value); +std::string GetAnonyPath(const std::string &value); } // namespace OHOS #endif // UTILS_LOG_H \ No newline at end of file diff --git a/utils/log/src/utils_log.cpp b/utils/log/src/utils_log.cpp index b6abc932d8c35ca90957c14432530a8508103747..9d246aeba7edf34db6c215d4eeea107a767e318f 100644 --- a/utils/log/src/utils_log.cpp +++ b/utils/log/src/utils_log.cpp @@ -53,4 +53,24 @@ std::string GetAnonyInt32(const int32_t value) std::string tmpStr = std::to_string(value); return GetAnonyString(tmpStr); } + +std::string GetAnonyPath(const std::string &value) +{ + auto pathAnony = GetAnonyString(value); + auto pos = pathAnony.find_last_of('/'); + if (pos == std::string::npos) { + return pathAnony; + } + auto res = pathAnony.substr(0, pos + 1); + std::string anonyStr("********"); + auto fileName = pathAnony.substr(pos + 1); + auto exPos = fileName.find_last_of('.'); + if (exPos == std::string::npos) { + res += anonyStr; + } else { + res += anonyStr + fileName.substr(exPos); + } + + return res; +} } // namespace OHOS