• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 UDMF_COPY_FILE_H
17 #define UDMF_COPY_FILE_H
18 
19 #include <string>
20 #include <vector>
21 
22 #include "unified_data.h"
23 #include "async_task_params.h"
24 
25 namespace OHOS {
26 namespace UDMF {
27 
28 class UdmfCopyFile {
29 public:
30     static UdmfCopyFile &GetInstance();
31     Status Copy(std::unique_ptr<AsyncHelper> &asyncHelper);
32 
33 private:
34     struct CopyContext {
35         std::unique_ptr<AsyncHelper> &asyncHelper;
36         uint64_t finishSize = 0;
37         uint64_t totalSize = 0;
38         Status status = E_OK;
39         std::shared_ptr<UnifiedData> processedData;
40 
CopyContextCopyContext41         explicit CopyContext(std::unique_ptr<AsyncHelper> &helper)
42             : asyncHelper(helper),
43             totalSize(UdmfCopyFile::GetInstance().GetTotalSize(helper->data->GetFileUris())),
44             processedData(std::make_shared<UnifiedData>()) {}
45     };
46 
47     UdmfCopyFile() = default;
48     ~UdmfCopyFile() = default;
49 
50     bool HandleRecord(const std::shared_ptr<UnifiedRecord> &record, CopyContext &context);
51     void HandleUris(CopyContext &context);
52     void UpdateUriInfo(const std::string &destUri, const std::shared_ptr<UnifiedRecord> &record,
53         UriInfo uri);
54     bool CopyFile(const std::string &srcUri, const std::string &destFileUri,
55         const std::shared_ptr<UnifiedRecord> &record, CopyContext &context);
56     void HandleProgress(const std::string &srcUri, const std::string &destFileUri,
57         CopyContext &context, uint64_t processSize);
58     std::string ConstructDestUri(const std::string &destUri, const std::string &srcUri);
59     uint64_t GetTotalSize(const std::vector<std::string> &uris);
60     bool IsDirectory(const std::string &uri, bool isSource);
61     std::string GetFileName(const std::string &path);
62     bool IsRemote(const std::string &uri);
63     bool IsFile(const std::string &uri, bool isSource);
64     uint64_t GetFileSize(const std::string &uri, bool isSource);
65 };
66 
67 } // namespace UDMF
68 } // namespace OHOS
69 #endif /* UDMF_COPY_FILE_H */