• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 Huawei Device Co., Ltd. All rights reserved.
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 #include "cloud_file_utils.h"
16 #include "cloud_file_utils_mock.h"
17 #include <fcntl.h>
18 #include <sys/xattr.h>
19 #include <sys/ioctl.h>
20 #include <unistd.h>
21 #include "utils_log.h"
22 
23 namespace OHOS {
24 namespace FileManagement {
25 namespace CloudDisk {
26 using namespace std;
27 
28 const std::string TMP_SUFFIX = ".temp.download";
29 int g_getCloudIdFlag = 0;
30 
GetLocalBucketPath(string cloudId,string bundleName,int32_t userId)31 string CloudFileUtils::GetLocalBucketPath(string cloudId, string bundleName, int32_t userId)
32 {
33     if (userId == 0) {
34         return "";
35     }
36     return "/data/test";
37 }
38 
GetLocalFilePath(string cloudId,string bundleName,int32_t userId)39 string CloudFileUtils::GetLocalFilePath(string cloudId, string bundleName, int32_t userId)
40 {
41     if (userId == 0) {
42         return "false/";
43     }
44     return "true";
45 }
46 
GetPathWithoutTmp(const string & path)47 string CloudFileUtils::GetPathWithoutTmp(const string &path)
48 {
49     return TMP_SUFFIX;
50 }
51 
EndsWith(const string & fullString,const string & ending)52 bool CloudFileUtils::EndsWith(const string &fullString, const string &ending)
53 {
54     return true;
55 }
56 
GetCloudId(const string & path)57 string CloudFileUtils::GetCloudId(const string &path)
58 {
59     string cloudId = "";
60     switch (g_getCloudIdFlag) {
61         case 0:
62             cloudId = "cloud_disk_data_handler_test.txt";
63             break;
64         case 1:
65             cloudId = "cloud_disk_data_handler_test1.txt";
66             break;
67         default:
68             break;
69     }
70     return cloudId;
71 }
72 
CheckIsCloud(const string & key)73 bool CloudFileUtils::CheckIsCloud(const string &key)
74 {
75     return key == CLOUD_CLOUD_ID_XATTR;
76 }
77 
CheckIsCloudLocation(const string & key)78 bool CloudFileUtils::CheckIsCloudLocation(const string &key)
79 {
80     return key == CLOUD_FILE_LOCATION;
81 }
82 
CheckIsHmdfsPermission(const string & key)83 bool CloudFileUtils::CheckIsHmdfsPermission(const string &key)
84 {
85     return key == HMDFS_PERMISSION_XATTR;
86 }
87 
LocalWriteOpen(const string & dfsPath)88 bool CloudFileUtils::LocalWriteOpen(const string &dfsPath)
89 {
90     if (dfsPath.compare("false")) {
91         return false;
92     }
93     if (dfsPath.compare("true")) {
94         return true;
95     }
96     return true;
97 }
98 
99 } // namespace CloudDisk
100 } // namespace FileManagement
101 } // namespace OHOS
102