• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 #ifndef FRAMEWORKS_INNERKITSIMPL_MEDIALIBRARY_DATA_ABILITY_INCLUDE_MEDIALIBRARY_DIR_OPERATIONS_H_
17 #define FRAMEWORKS_INNERKITSIMPL_MEDIALIBRARY_DATA_ABILITY_INCLUDE_MEDIALIBRARY_DIR_OPERATIONS_H_
18 
19 #include <string>
20 #include <variant>
21 #include <grp.h>
22 #include <securec.h>
23 #include <unistd.h>
24 #include <unordered_map>
25 
26 #include "dir_asset.h"
27 #include "datashare_values_bucket.h"
28 #include "medialibrary_db_const.h"
29 #include "medialibrary_dir_db.h"
30 #include "rdb_store.h"
31 #include "rdb_utils.h"
32 #include "values_bucket.h"
33 
34 
35 namespace OHOS {
36 namespace Media {
37 class MediaLibraryDirOperations {
38 public:
39     const std::string DIR_PARENT_WHERECLAUSE = MEDIA_DATA_DB_PARENT_ID + " = ?";
40     const std::string DIR_DIRECTORY_WHERECLAUSE = CATEGORY_MEDIATYPE_DIRECTORY_DB_DIRECTORY + " = ?";
41     const std::string DIR_DIRECTORY_TYPE_WHERECLAUSE = CATEGORY_MEDIATYPE_DIRECTORY_DB_DIRECTORY_TYPE + " = ?";
42     const std::string DIR_FILE_WHERECLAUSE = MEDIA_DATA_DB_ID + " = ?";
43     const std::string DIR_RELATIVEPATH_WHERECLAUSE = MEDIA_DATA_DB_RELATIVE_PATH +
44         " LIKE ? OR " + MEDIA_DATA_DB_FILE_PATH + " = ? AND " + MEDIA_DATA_DB_IS_TRASH + " = 0";
45 
46     int32_t HandleDirOperations(const std::string &oprn,
47                                 const NativeRdb::ValuesBucket &values,
48                                 const std::shared_ptr<NativeRdb::RdbStore> &rdbStore,
49                                 const std::unordered_map
50                                 <std::string, DirAsset> &dirQuerySetMap = {});
51 
52     int32_t HandleDeleteDir(const NativeRdb::ValuesBucket &values,
53                             const std::shared_ptr<NativeRdb::RdbStore> &rdbStore);
54 
55     int32_t HandleCheckDirExtension(const NativeRdb::ValuesBucket &values,
56                                     const std::shared_ptr<NativeRdb::RdbStore> &rdbStore,
57                                     const std::unordered_map
58                                     <std::string, DirAsset> &dirQuerySetMap);
59 
60     int32_t HandleFMSDeleteDir(const NativeRdb::ValuesBucket &values,
61                                const std::shared_ptr<NativeRdb::RdbStore> &rdbStore);
62 
63     int32_t HandleFMSTrashDir(const NativeRdb::ValuesBucket &values,
64                               const std::shared_ptr<NativeRdb::RdbStore> &rdbStore,
65                               const std::unordered_map
66                               <std::string, DirAsset> &dirQuerySetMap);
67 
68 private:
69     int32_t DeleteDirInfoUtil(const int &parent,
70                               const std::shared_ptr<NativeRdb::RdbStore> &rdbStore,
71                               const MediaLibraryDirDb &dirDbOprn);
72 
73     int32_t DeleteFMSDirInfoUtil(const std::string &relativePath,
74                                  const std::shared_ptr<NativeRdb::RdbStore> &rdbStore,
75                                  const MediaLibraryDirDb &dirDbOprn);
76 
77     int32_t CheckDirInfoUtil(const NativeRdb::ValuesBucket &values,
78                              const std::shared_ptr<RdbStore> &rdbStore,
79                              const std::unordered_map
80                              <std::string, DirAsset> &dirQuerySetMap);
81 
82     int32_t GetRootDirAndExtension(std::string &displayName, std::string &relativePath,
83                                    int mediaType, NativeRdb::ValuesBucket &outValues);
84 
85     int32_t CheckFileExtension(const int mediaType, string extension, const string &dstMediaType);
86 
87     DirAsset GetDirQuerySet(const NativeRdb::ValuesBucket &values,
88         const std::shared_ptr<RdbStore> &rdbStore,
89         const std::unordered_map<std::string, DirAsset> &dirQuerySetMap);
90 };
91 } // namespace Media
92 } // namespace OHOS
93 
94 #endif // FRAMEWORKS_INNERKITSIMPL_MEDIALIBRARY_DATA_ABILITY_INCLUDE_MEDIALIBRARY_DIR_OPERATIONS_H_
95