• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "command/delete_command_v10.h"
17 #include "constant.h"
18 #include "medialibrary_errno.h"
19 #include "userfile_client_ex.h"
20 
21 namespace OHOS {
22 namespace Media {
23 namespace MediaTool {
DeleteOne(const std::string & uri)24 int32_t DeleteCommandV10::DeleteOne(const std::string &uri)
25 {
26     int32_t ret = UserFileClientEx::Trash(uri);
27     if (ret < 0) {
28         printf("%s trash failed. err:%d\n", STR_FAIL.c_str(), ret);
29         return Media::E_ERR;
30     }
31     ret = UserFileClientEx::Delete(uri);
32     if (ret < 0) {
33         printf("%s delete failed. err:%d\n", STR_FAIL.c_str(), ret);
34         return Media::E_ERR;
35     }
36     printf("%s delete success.\n", STR_SUCCESS.c_str());
37     return Media::E_OK;
38 }
39 
DeleteAll(bool isOnlyDeleteDb)40 int32_t DeleteCommandV10::DeleteAll(bool isOnlyDeleteDb)
41 {
42     return UserFileClientEx::Delete(isOnlyDeleteDb);
43 }
44 
Start(const ExecEnv & env)45 int32_t DeleteCommandV10::Start(const ExecEnv &env)
46 {
47     int32_t ret = 0;
48     if (env.deleteParam.isDeleteAll) {
49         ret = DeleteAll(env.deleteParam.isOnlyDeleteDb);
50     } else {
51         ret = DeleteOne(env.deleteParam.deleteUri);
52     }
53     if (ret != Media::E_OK) {
54         printf("%s delete failed. err:%d\n", STR_FAIL.c_str(), ret);
55         return Media::E_ERR;
56     }
57     return Media::E_OK;
58 }
59 } // MediaTool
60 } // Media
61 } // OHOS