mirror of
https://gitee.com/openharmony/request_request
synced 2024-11-23 15:00:48 +00:00
适配元服务物理路径中包名增加AccountUid的变化
Signed-off-by: ZhangJianxin <zhangjianxin23@huawei.com> Change-Id: Ie29c0c923ff5465e4343b37c73039c6808173866
This commit is contained in:
parent
cd793e169b
commit
d4d7989777
@ -24,7 +24,8 @@
|
||||
"ohos.permission.SEND_TASK_COMPLETE_EVENT",
|
||||
"ohos.permission.ACCESS_CERT_MANAGER",
|
||||
"ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS",
|
||||
"ohos.permission.MANAGE_LOCAL_ACCOUNTS"
|
||||
"ohos.permission.MANAGE_LOCAL_ACCOUNTS",
|
||||
"ohos.permission.GET_DISTRIBUTED_ACCOUNTS"
|
||||
],
|
||||
"caps": [
|
||||
"CAP_CHOWN"
|
||||
|
@ -80,6 +80,7 @@ ohos_static_library("download_server_cxx") {
|
||||
"hilog:libhilog",
|
||||
"ipc:ipc_single",
|
||||
"netmanager_base:net_conn_manager_if",
|
||||
"os_account:libaccountkits",
|
||||
"os_account:os_account_innerkits",
|
||||
"relational_store:native_appdatafwk",
|
||||
"relational_store:native_dataability",
|
||||
|
@ -19,6 +19,8 @@
|
||||
#include <vector>
|
||||
|
||||
#include "cxx.h"
|
||||
#include "errors.h"
|
||||
#include "ohos_account_kits.h"
|
||||
#include "os_account_info.h"
|
||||
#include "os_account_manager.h"
|
||||
#include "os_account_subscribe_info.h"
|
||||
@ -31,54 +33,47 @@ using namespace OHOS::AccountSA;
|
||||
struct TaskManagerTx;
|
||||
class SubscriberWrapper : public OsAccountSubscriber {
|
||||
public:
|
||||
explicit SubscriberWrapper(
|
||||
OS_ACCOUNT_SUBSCRIBE_TYPE type, rust::box<TaskManagerTx> task_manager,
|
||||
rust::fn<void(const int &id, const TaskManagerTx &task_manager)>
|
||||
on_accounts_changed,
|
||||
rust::fn<void(const int &newId, const int &oldId,
|
||||
const TaskManagerTx &task_manager)>
|
||||
on_accounts_switch);
|
||||
explicit SubscriberWrapper(OS_ACCOUNT_SUBSCRIBE_TYPE type, rust::box<TaskManagerTx> task_manager,
|
||||
rust::fn<void(const int &id, const TaskManagerTx &task_manager)> on_accounts_changed,
|
||||
rust::fn<void(const int &newId, const int &oldId, const TaskManagerTx &task_manager)> on_accounts_switch);
|
||||
|
||||
~SubscriberWrapper();
|
||||
~SubscriberWrapper();
|
||||
|
||||
virtual void OnAccountsChanged(const int &id) override;
|
||||
virtual void OnAccountsSwitch(const int &newId, const int &oldId) override;
|
||||
virtual void OnAccountsChanged(const int &id) override;
|
||||
virtual void OnAccountsSwitch(const int &newId, const int &oldId) override;
|
||||
|
||||
private:
|
||||
TaskManagerTx *task_manager_;
|
||||
rust::fn<void(const int &id, const TaskManagerTx &task_manager)>
|
||||
on_accounts_changed_;
|
||||
rust::fn<void(const int &newId, const int &oldId,
|
||||
const TaskManagerTx &task_manager)>
|
||||
on_accounts_switch_;
|
||||
TaskManagerTx *task_manager_;
|
||||
rust::fn<void(const int &id, const TaskManagerTx &task_manager)> on_accounts_changed_;
|
||||
rust::fn<void(const int &newId, const int &oldId, const TaskManagerTx &task_manager)> on_accounts_switch_;
|
||||
};
|
||||
|
||||
int RegistryAccountSubscriber(
|
||||
OS_ACCOUNT_SUBSCRIBE_TYPE type, rust::box<TaskManagerTx> task_manager,
|
||||
rust::fn<void(const int &id, const TaskManagerTx &task_manager)>
|
||||
on_accounts_changed,
|
||||
rust::fn<void(const int &newId, const int &oldId,
|
||||
const TaskManagerTx &task_manager)>
|
||||
on_accounts_switch);
|
||||
int RegistryAccountSubscriber(OS_ACCOUNT_SUBSCRIBE_TYPE type, rust::box<TaskManagerTx> task_manager,
|
||||
rust::fn<void(const int &id, const TaskManagerTx &task_manager)> on_accounts_changed,
|
||||
rust::fn<void(const int &newId, const int &oldId, const TaskManagerTx &task_manager)> on_accounts_switch);
|
||||
|
||||
inline ErrCode GetForegroundOsAccount(int &account) {
|
||||
return OsAccountManager::GetForegroundOsAccountLocalId(account);
|
||||
inline ErrCode GetForegroundOsAccount(int &account)
|
||||
{
|
||||
return OsAccountManager::GetForegroundOsAccountLocalId(account);
|
||||
}
|
||||
|
||||
inline ErrCode GetBackgroundOsAccounts(rust::vec<int> &accounts) {
|
||||
auto v = std::vector<int32_t>();
|
||||
auto ret = OsAccountManager::GetBackgroundOsAccountLocalIds(v);
|
||||
if (ret == 0) {
|
||||
for (auto &account : v) {
|
||||
accounts.push_back(account);
|
||||
};
|
||||
}
|
||||
return ret;
|
||||
inline ErrCode GetBackgroundOsAccounts(rust::vec<int> &accounts)
|
||||
{
|
||||
auto v = std::vector<int32_t>();
|
||||
auto ret = OsAccountManager::GetBackgroundOsAccountLocalIds(v);
|
||||
if (ret == 0) {
|
||||
for (auto &account : v) {
|
||||
accounts.push_back(account);
|
||||
};
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline ErrCode GetOsAccountLocalIdFromUid(const int uid, int &id) {
|
||||
return OsAccountManager::GetOsAccountLocalIdFromUid(uid, id);
|
||||
inline ErrCode GetOsAccountLocalIdFromUid(const int uid, int &id)
|
||||
{
|
||||
return OsAccountManager::GetOsAccountLocalIdFromUid(uid, id);
|
||||
}
|
||||
|
||||
rust::String GetOhosAccountUid();
|
||||
} // namespace OHOS::Request
|
||||
#endif // ACCOUNT_H
|
@ -113,8 +113,9 @@ constexpr const char *REQUEST_TASK_TABLE_ADD_PROXY = "ALTER TABLE request_task A
|
||||
|
||||
constexpr const char *REQUEST_TASK_TABLE_ADD_CERTIFICATE_PINS = "ALTER TABLE request_task ADD COLUMN "
|
||||
"certificate_pins TEXT";
|
||||
constexpr const char *REQUEST_TASK_TABLE_ADD_Bundle_Type = "ALTER TABLE request_task ADD COLUMN bundle_type "
|
||||
"certificate_pins TEXT";
|
||||
constexpr const char *REQUEST_TASK_TABLE_ADD_BUNDLE_TYPE = "ALTER TABLE request_task ADD COLUMN bundle_type TEXT";
|
||||
constexpr const char *REQUEST_TASK_TABLE_ADD_ATOMIC_ACCOUNT = "ALTER TABLE request_task ADD COLUMN atomic_account "
|
||||
"TEXT";
|
||||
|
||||
struct TaskFilter;
|
||||
class RequestDataBase {
|
||||
|
@ -55,6 +55,7 @@ struct CStringMap {
|
||||
struct CTaskConfig {
|
||||
CStringWrapper bundle;
|
||||
uint8_t bundleType;
|
||||
CStringWrapper atomicAccount;
|
||||
CStringWrapper url;
|
||||
CStringWrapper title;
|
||||
CStringWrapper description;
|
||||
@ -80,6 +81,7 @@ struct CTaskConfig {
|
||||
struct TaskConfig {
|
||||
std::string bundle;
|
||||
uint8_t bundleType;
|
||||
std::string atomicAccount;
|
||||
std::string url;
|
||||
std::string title;
|
||||
std::string description;
|
||||
|
@ -66,4 +66,15 @@ int GetForegroundOsAccountLocalId(int &id)
|
||||
return OsAccountManager::GetForegroundOsAccountLocalId(id);
|
||||
}
|
||||
|
||||
rust::String GetOhosAccountUid()
|
||||
{
|
||||
AccountSA::OhosAccountInfo accountInfo;
|
||||
ErrCode errCode = AccountSA::OhosAccountKits::GetInstance().GetOhosAccountInfo(accountInfo);
|
||||
if (errCode != ERR_OK) {
|
||||
REQUEST_HILOGE("GetOhosAccountInfo err: %{public}d, %{public}s", errCode, accountInfo.uid_.c_str());
|
||||
return rust::String("ohosAnonymousUid");
|
||||
}
|
||||
REQUEST_HILOGD("GetOhosAccountInfo ok: %{public}s", accountInfo.uid_.c_str());
|
||||
return rust::String(accountInfo.uid_);
|
||||
}
|
||||
} // namespace OHOS::Request
|
@ -81,8 +81,8 @@ bool RequestDataBase::Update(
|
||||
return ret == OHOS::NativeRdb::E_OK;
|
||||
}
|
||||
|
||||
void Search(rust::vec<rust::u32> &tasks, std::shared_ptr<OHOS::NativeRdb::RdbStore> store_, std::string sql,
|
||||
TaskFilter filter)
|
||||
void Search(
|
||||
rust::vec<rust::u32> &tasks, std::shared_ptr<OHOS::NativeRdb::RdbStore> store_, std::string sql, TaskFilter filter)
|
||||
{
|
||||
sql += "ctime BETWEEN " + std::to_string(filter.after) + " AND " + std::to_string(filter.before);
|
||||
if (filter.state != static_cast<uint8_t>(State::ANY)) {
|
||||
@ -345,12 +345,18 @@ int RequestDBUpgradeFrom41(OHOS::NativeRdb::RdbStore &store)
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = store.ExecuteSql(REQUEST_TASK_TABLE_ADD_Bundle_Type);
|
||||
ret = store.ExecuteSql(OHOS::Request::REQUEST_TASK_TABLE_ADD_BUNDLE_TYPE);
|
||||
if (ret != OHOS::NativeRdb::E_OK && ret != OHOS::NativeRdb::E_SQLITE_ERROR) {
|
||||
REQUEST_HILOGE("add column bundle_type failed, ret: %{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
return OHOS::NativeRdb::E_OK;
|
||||
|
||||
ret = store.ExecuteSql(REQUEST_TASK_TABLE_ADD_ATOMIC_ACCOUNT);
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
REQUEST_HILOGE("add column atomic_account failed, ret: %{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// This function is used to adapt beta version, remove it later.
|
||||
@ -359,7 +365,8 @@ void RequestDBUpgradeFrom50(OHOS::NativeRdb::RdbStore &store)
|
||||
// Ignores these error if these columns already exists.
|
||||
store.ExecuteSql(REQUEST_TASK_TABLE_ADD_PROXY);
|
||||
store.ExecuteSql(REQUEST_TASK_TABLE_ADD_CERTIFICATE_PINS);
|
||||
store.ExecuteSql(REQUEST_TASK_TABLE_ADD_Bundle_Type);
|
||||
store.ExecuteSql(REQUEST_TASK_TABLE_ADD_BUNDLE_TYPE);
|
||||
store.ExecuteSql(REQUEST_TASK_TABLE_ADD_ATOMIC_ACCOUNT);
|
||||
}
|
||||
|
||||
int RequestDBUpgrade(OHOS::NativeRdb::RdbStore &store)
|
||||
@ -813,8 +820,8 @@ void BuildRequestTaskConfigWithInt(std::shared_ptr<OHOS::NativeRdb::ResultSet> s
|
||||
config.commonData.gauge = static_cast<bool>(GetInt(set, 14)); // Line 14 is 'gauge'
|
||||
config.commonData.precise = static_cast<bool>(GetInt(set, 15)); // Line 15 is 'precise'
|
||||
config.commonData.background = static_cast<bool>(GetInt(set, 17)); // Line 17 is 'background'
|
||||
config.version = static_cast<uint8_t>(GetInt(set, 27)); // Line 27 here is 'version'
|
||||
config.bundleType = static_cast<uint8_t>(GetInt(set, 34)); // Line 34 here is 'bundle_type'
|
||||
config.version = static_cast<uint8_t>(GetInt(set, 27)); // Line 27 is 'version'
|
||||
config.bundleType = static_cast<uint8_t>(GetInt(set, 34)); // Line 34 is 'bundle_type'
|
||||
}
|
||||
|
||||
void BuildRequestTaskConfigWithString(std::shared_ptr<OHOS::NativeRdb::ResultSet> set, TaskConfig &config)
|
||||
@ -830,6 +837,7 @@ void BuildRequestTaskConfigWithString(std::shared_ptr<OHOS::NativeRdb::ResultSet
|
||||
set->GetString(26, config.extras); // Line 26 is 'config_extras'
|
||||
set->GetString(32, config.proxy); // Line 32 is 'proxy'
|
||||
set->GetString(33, config.certificatePins); // Line 33 is 'certificate_pins'
|
||||
set->GetString(35, config.atomicAccount); // Line 35 is 'atomic_account'
|
||||
}
|
||||
|
||||
void BuildRequestTaskConfigWithBlob(std::shared_ptr<OHOS::NativeRdb::ResultSet> set, TaskConfig &config)
|
||||
@ -915,6 +923,8 @@ bool RecordRequestTask(CTaskInfo *taskInfo, CTaskConfig *taskConfig)
|
||||
insertValues.PutString("headers", std::string(taskConfig->headers.cStr, taskConfig->headers.len));
|
||||
insertValues.PutString("config_extras", std::string(taskConfig->extras.cStr, taskConfig->extras.len));
|
||||
insertValues.PutInt("bundle_type", taskConfig->bundleType);
|
||||
insertValues.PutString(
|
||||
"atomic_account", std::string(taskConfig->atomicAccount.cStr, taskConfig->atomicAccount.len));
|
||||
if (!WriteMutableData(insertValues, taskInfo, taskConfig)) {
|
||||
REQUEST_HILOGE("write blob data failed");
|
||||
return false;
|
||||
@ -1070,10 +1080,10 @@ CTaskConfig **QueryAllTaskConfig(uint32_t &len)
|
||||
int QueryRequestTaskConfig(const OHOS::NativeRdb::RdbPredicates &rdbPredicates, std::vector<TaskConfig> &taskConfigs)
|
||||
{
|
||||
auto resultSet = OHOS::Request::RequestDataBase::GetInstance().Query(rdbPredicates,
|
||||
{ "task_id", "uid", "token_id", "action", "mode", "cover", "network", "metered", "roaming", "retry",
|
||||
"redirect", "config_idx", "begins", "ends", "gauge", "precise", "priority", "background", "bundle", "url",
|
||||
"title", "description", "method", "headers", "data", "token", "config_extras", "version", "form_items",
|
||||
"file_specs", "body_file_names", "certs_paths", "proxy", "certificate_pins", "bundle_type" });
|
||||
{ "task_id", "uid", "token_id", "action", "mode", "cover", "network", "metered", "roaming", "retry", "redirect",
|
||||
"config_idx", "begins", "ends", "gauge", "precise", "priority", "background", "bundle", "url", "title",
|
||||
"description", "method", "headers", "data", "token", "config_extras", "version", "form_items", "file_specs",
|
||||
"body_file_names", "certs_paths", "proxy", "certificate_pins", "bundle_type", "atomic_account" });
|
||||
int rowCount = 0;
|
||||
if (resultSet == nullptr || resultSet->GetRowCount(rowCount) != OHOS::NativeRdb::E_OK) {
|
||||
REQUEST_HILOGE("TaskConfig result set is nullptr or get row count failed");
|
||||
@ -1106,6 +1116,7 @@ void BuildCTaskConfig(CTaskConfig *cTaskConfig, const TaskConfig &taskConfig)
|
||||
cTaskConfig->certificatePins = WrapperCString(taskConfig.certificatePins);
|
||||
cTaskConfig->version = taskConfig.version;
|
||||
cTaskConfig->bundleType = taskConfig.bundleType;
|
||||
cTaskConfig->atomicAccount = WrapperCString(taskConfig.atomicAccount);
|
||||
|
||||
uint32_t formItemsLen = taskConfig.formItems.size();
|
||||
CFormItem *formItemsPtr = new CFormItem[formItemsLen];
|
||||
@ -1196,10 +1207,10 @@ CTaskConfig *QueryTaskConfig(uint32_t taskId)
|
||||
OHOS::NativeRdb::RdbPredicates rdbPredicates("request_task");
|
||||
rdbPredicates.EqualTo("task_id", std::to_string(taskId));
|
||||
auto resultSet = OHOS::Request::RequestDataBase::GetInstance().Query(rdbPredicates,
|
||||
{ "task_id", "uid", "token_id", "action", "mode", "cover", "network", "metered", "roaming", "retry",
|
||||
"redirect", "config_idx", "begins", "ends", "gauge", "precise", "priority", "background", "bundle", "url",
|
||||
"title", "description", "method", "headers", "data", "token", "config_extras", "version", "form_items",
|
||||
"file_specs", "body_file_names", "certs_paths", "proxy", "certificate_pins", "bundle_type" });
|
||||
{ "task_id", "uid", "token_id", "action", "mode", "cover", "network", "metered", "roaming", "retry", "redirect",
|
||||
"config_idx", "begins", "ends", "gauge", "precise", "priority", "background", "bundle", "url", "title",
|
||||
"description", "method", "headers", "data", "token", "config_extras", "version", "form_items", "file_specs",
|
||||
"body_file_names", "certs_paths", "proxy", "certificate_pins", "bundle_type", "atomic_account" });
|
||||
int rowCount = 0;
|
||||
if (resultSet == nullptr) {
|
||||
REQUEST_HILOGE("QuerySingleTaskConfig failed: result set is nullptr");
|
||||
|
@ -75,6 +75,7 @@ mod ffi {
|
||||
on_accounts_changed: fn(&i32, task_manager: &TaskManagerTx),
|
||||
on_accounts_switch: fn(&i32, &i32, task_manager: &TaskManagerTx),
|
||||
) -> i32;
|
||||
fn GetOhosAccountUid() -> String;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,11 +19,13 @@ use ipc::parcel::MsgParcel;
|
||||
use ipc::{IpcResult, IpcStatusCode};
|
||||
|
||||
use crate::error::ErrorCode;
|
||||
use crate::manage::account::GetOhosAccountUid;
|
||||
use crate::manage::events::TaskManagerEvent;
|
||||
use crate::service::permission::PermissionChecker;
|
||||
use crate::service::{get_calling_bundle, RequestServiceStub};
|
||||
use crate::task::config::{Action, CommonTaskConfig, Network, TaskConfig, Version};
|
||||
use crate::task::info::Mode;
|
||||
use crate::task::ATOMIC_SERVICE;
|
||||
use crate::utils::form_item::{FileSpec, FormItem};
|
||||
|
||||
impl RequestServiceStub {
|
||||
@ -189,9 +191,16 @@ impl RequestServiceStub {
|
||||
extras.insert(key, value);
|
||||
}
|
||||
|
||||
let atomic_account = if bundle_type == ATOMIC_SERVICE {
|
||||
GetOhosAccountUid()
|
||||
} else {
|
||||
"".to_string()
|
||||
};
|
||||
|
||||
let task_config = TaskConfig {
|
||||
bundle,
|
||||
bundle_type,
|
||||
atomic_account,
|
||||
url,
|
||||
title,
|
||||
description,
|
||||
|
@ -176,6 +176,7 @@ pub(crate) fn serialize_task_config(config: TaskConfig, reply: &mut MsgParcel) -
|
||||
reply.write(&(config.common_data.action as u32))?;
|
||||
reply.write(&(config.common_data.mode as u32))?;
|
||||
reply.write(&(config.bundle_type))?;
|
||||
reply.write(&(config.atomic_account))?;
|
||||
reply.write(&(config.common_data.cover))?;
|
||||
reply.write(&(config.common_data.network as u32))?;
|
||||
reply.write(&(config.common_data.metered))?;
|
||||
|
@ -20,7 +20,8 @@ use ylong_http_client::{
|
||||
|
||||
use crate::manage::SystemConfig;
|
||||
use crate::task::config::{Action, TaskConfig};
|
||||
use crate::task::files::convert_path;
|
||||
use crate::task::files::{check_atomic_convert_path, convert_path};
|
||||
use crate::task::ATOMIC_SERVICE;
|
||||
use crate::utils::url_policy::check_url_domain;
|
||||
|
||||
const CONNECT_TIMEOUT: u64 = 60;
|
||||
@ -165,10 +166,13 @@ fn build_task_certs(config: &TaskConfig) -> Result<Vec<Certificate>, Box<dyn Err
|
||||
let uid = config.common_data.uid;
|
||||
let bundle = config.bundle.as_str();
|
||||
let paths = config.certs_path.as_slice();
|
||||
let is_account = config.bundle_type == ATOMIC_SERVICE;
|
||||
let atomic_account = config.atomic_account.as_str();
|
||||
let bundle_and_account = check_atomic_convert_path(is_account, bundle, atomic_account);
|
||||
|
||||
let mut certs = Vec::new();
|
||||
for (idx, path) in paths.iter().enumerate() {
|
||||
let path = convert_path(uid, bundle, path);
|
||||
let path = convert_path(uid, &bundle_and_account, path);
|
||||
let cert = cvt_res_error!(
|
||||
Certificate::from_path(&path).map_err(Box::new),
|
||||
"Parse task cert failed - idx: {}, path: {}",
|
||||
|
@ -79,6 +79,7 @@ pub(crate) struct CommonTaskConfig {
|
||||
pub(crate) struct TaskConfig {
|
||||
pub(crate) bundle: String,
|
||||
pub(crate) bundle_type: u32,
|
||||
pub(crate) atomic_account: String,
|
||||
pub(crate) url: String,
|
||||
pub(crate) title: String,
|
||||
pub(crate) description: String,
|
||||
@ -165,6 +166,7 @@ impl Default for TaskConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
bundle_type: 0,
|
||||
atomic_account: "ohosAnonymousUid".to_string(),
|
||||
bundle: "xxx".to_string(),
|
||||
url: "".to_string(),
|
||||
title: "xxx".to_string(),
|
||||
|
@ -28,6 +28,7 @@ use crate::utils::{build_vec, get_current_timestamp, split_string, string_to_has
|
||||
pub(crate) struct CTaskConfig {
|
||||
pub(crate) bundle: CStringWrapper,
|
||||
pub(crate) bundle_type: u8,
|
||||
pub(crate) atomic_account: CStringWrapper,
|
||||
pub(crate) url: CStringWrapper,
|
||||
pub(crate) title: CStringWrapper,
|
||||
pub(crate) description: CStringWrapper,
|
||||
@ -281,6 +282,7 @@ impl TaskConfig {
|
||||
CTaskConfig {
|
||||
bundle: CStringWrapper::from(&self.bundle),
|
||||
bundle_type: self.bundle_type as u8,
|
||||
atomic_account: CStringWrapper::from(&self.atomic_account),
|
||||
url: CStringWrapper::from(&self.url),
|
||||
title: CStringWrapper::from(&self.title),
|
||||
description: CStringWrapper::from(&self.description),
|
||||
@ -327,6 +329,7 @@ impl TaskConfig {
|
||||
let task_config: TaskConfig = TaskConfig {
|
||||
bundle: c_struct.bundle.to_string(),
|
||||
bundle_type: c_struct.bundle_type as u32,
|
||||
atomic_account: c_struct.atomic_account.to_string(),
|
||||
url: c_struct.url.to_string(),
|
||||
title: c_struct.title.to_string(),
|
||||
description: c_struct.description.to_string(),
|
||||
|
@ -16,9 +16,10 @@ use std::fs::{File, OpenOptions};
|
||||
use std::io;
|
||||
use std::os::fd::FromRawFd;
|
||||
|
||||
use ylong_runtime::fs::File as AsyncFile;
|
||||
|
||||
use crate::task::config::{Action, TaskConfig};
|
||||
use crate::task::ATOMIC_SERVICE;
|
||||
|
||||
use ylong_runtime::fs::File as AsyncFile;
|
||||
|
||||
pub(crate) struct AttachedFiles {
|
||||
pub(crate) files: Files,
|
||||
@ -53,6 +54,9 @@ fn open_task_files(config: &TaskConfig) -> io::Result<(Files, Vec<i64>)> {
|
||||
let tid = config.common_data.task_id;
|
||||
let uid = config.common_data.uid;
|
||||
let bundle = config.bundle.as_str();
|
||||
let is_account = config.bundle_type == ATOMIC_SERVICE;
|
||||
let atomic_account = config.atomic_account.as_str();
|
||||
let bundle_and_account = check_atomic_convert_path(is_account, bundle, atomic_account);
|
||||
|
||||
let mut files = Vec::new();
|
||||
let mut sizes = Vec::new();
|
||||
@ -70,7 +74,7 @@ fn open_task_files(config: &TaskConfig) -> io::Result<(Files, Vec<i64>)> {
|
||||
}
|
||||
} else {
|
||||
cvt_res_error!(
|
||||
open_file_readonly(uid, bundle, &fs.path),
|
||||
open_file_readonly(uid, &bundle_and_account, &fs.path),
|
||||
"Open file RO failed - task_id: {}, idx: {}",
|
||||
tid,
|
||||
idx
|
||||
@ -91,7 +95,7 @@ fn open_task_files(config: &TaskConfig) -> io::Result<(Files, Vec<i64>)> {
|
||||
}
|
||||
Action::Download => {
|
||||
let file = cvt_res_error!(
|
||||
open_file_readwrite(uid, bundle, &fs.path),
|
||||
open_file_readwrite(uid, &bundle_and_account, &fs.path),
|
||||
"Open file RW failed - task_id: {}, idx: {}",
|
||||
tid,
|
||||
idx
|
||||
@ -109,11 +113,14 @@ fn open_body_files(config: &TaskConfig) -> io::Result<Files> {
|
||||
let tid = config.common_data.task_id;
|
||||
let uid = config.common_data.uid;
|
||||
let bundle = config.bundle.as_str();
|
||||
let is_account = config.bundle_type == ATOMIC_SERVICE;
|
||||
let atomic_account = config.atomic_account.as_str();
|
||||
let bundle_and_account = check_atomic_convert_path(is_account, bundle, atomic_account);
|
||||
|
||||
let mut body_files = Vec::new();
|
||||
for (idx, path) in config.body_file_paths.iter().enumerate() {
|
||||
let file = cvt_res_error!(
|
||||
open_file_readwrite(uid, bundle, path),
|
||||
open_file_readwrite(uid, &bundle_and_account, path),
|
||||
"Open body_file failed - task_id: {}, idx: {}",
|
||||
tid,
|
||||
idx
|
||||
@ -134,18 +141,30 @@ fn open_file_readwrite(uid: u64, bundle: &str, path: &str) -> io::Result<File> {
|
||||
))
|
||||
}
|
||||
|
||||
fn open_file_readonly(uid: u64, bundle: &str, path: &str) -> io::Result<File> {
|
||||
fn open_file_readonly(uid: u64, bundle_and_account: &str, path: &str) -> io::Result<File> {
|
||||
Ok(cvt_res_error!(
|
||||
OpenOptions::new()
|
||||
.read(true)
|
||||
.open(convert_path(uid, bundle, path)),
|
||||
.open(convert_path(uid, bundle_and_account, path)),
|
||||
"open_file_readonly failed"
|
||||
))
|
||||
}
|
||||
|
||||
pub(crate) fn convert_path(uid: u64, bundle: &str, path: &str) -> String {
|
||||
pub(crate) fn check_atomic_convert_path(
|
||||
is_account: bool,
|
||||
bundle: &str,
|
||||
atomic_account: &str,
|
||||
) -> String {
|
||||
if is_account {
|
||||
format!("+auid-{}+{}", atomic_account, bundle)
|
||||
} else {
|
||||
bundle.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn convert_path(uid: u64, bundle_and_account: &str, path: &str) -> String {
|
||||
let uuid = uid / 200000;
|
||||
let base_replace = format!("{}/base/{}", uuid, bundle);
|
||||
let base_replace = format!("{}/base/{}", uuid, bundle_and_account);
|
||||
let real_path = path
|
||||
.replacen("storage", "app", 1)
|
||||
.replacen("base", &base_replace, 1);
|
||||
|
@ -24,3 +24,5 @@ pub(crate) mod request_task;
|
||||
#[allow(dead_code)]
|
||||
pub(crate) mod tick;
|
||||
pub(crate) mod upload;
|
||||
|
||||
pub(crate) const ATOMIC_SERVICE: u32 = 1;
|
||||
|
Loading…
Reference in New Issue
Block a user