26 char *outputPtr =
nullptr;
27 auto outputPtrGuard = qScopeGuard(
31 auto getUriResult = ::OH_FileUri_GetUriFromPath(inputPath.c_str(), inputPath.size(), &outputPtr);
33 std::optional<
std::string> outputOhosUri;
34 if (getUriResult == FileManagement_ErrCode::ERR_OK && outputPtr !=
nullptr) {
35 outputOhosUri.emplace(outputPtr);
38 "%s: path to OHOS URI conversion failed for input path '%s', retval: %d",
39 Q_FUNC_INFO, inputPath.c_str(),
static_cast<
int>(getUriResult));
47 return QOhosJsThreadGateway::evalWithConsumer<
bool>(
48 [&](QOhosJsState &jsState, QOhosConsumer<
bool> resultConsumer) {
49 auto optFileOhosUri = tryMapPathToOhosUri(filePath.toStdString());
50 if (!optFileOhosUri.has_value()) {
51 resultConsumer(
false);
55 QNapi::Value deletePromiseOrValue;
57 deletePromiseOrValue = jsState.eval(
58 "@kit.FileManagerServiceKit.fileManagerService.deleteToTrash(*)",
59 {optFileOhosUri.value()});
60 }
catch (
const Napi::Error &error) {
62 "deleteToTrash('%s') failed with error: %s",
63 optFileOhosUri.value().c_str(), error.what());
66 if (deletePromiseOrValue.IsPromise()) {
67 QNapi::checkedCast<QNapi::Promise>(deletePromiseOrValue)
68 .withContext(std::move(resultConsumer))
70 [](
const QOhosCallbackInfo &cbInfo,
auto &resultConsumer) {
71 std::string deletedPath = cbInfo.getFirstArg<QNapi::String>(Q_FUNC_INFO);
72 resultConsumer(!deletedPath.empty());
75 [](
const QOhosCallbackInfo &cbInfo,
auto &resultConsumer) {
76 QtOhos::logJsCallbackError(cbInfo,
"Got error from deleteToTrash()");
77 resultConsumer(
false);
80 qOhosPrintfWarning(
"Got non-Promise from deleteToTrash()");
81 resultConsumer(
false);
93bool QFileSystemEngine::moveFileToTrash(
const QFileSystemEntry &source,