• 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 INTERFACES_KITS_JS_SRC_MOD_FS_CLASS_FILE_FS_FILE_H
17 #define INTERFACES_KITS_JS_SRC_MOD_FS_CLASS_FILE_FS_FILE_H
18 
19 #include "file_entity.h"
20 #include "filemgmt_libfs.h"
21 
22 namespace OHOS {
23 namespace FileManagement {
24 namespace ModuleFileIO {
25 using namespace std;
26 
27 class FsFile {
28 public:
29     inline static const string className_ = "File";
30 
GetFileEntity()31     FileEntity *GetFileEntity() const
32     {
33         return fileEntity.get();
34     }
35 
36     FsFile(const FsFile &other) = delete;
37     FsFile &operator=(const FsFile &other) = delete;
38 
FsFile(FsFile && other)39     FsFile(FsFile &&other) noexcept : fileEntity(move(other.fileEntity))
40     {
41         other.fileEntity = nullptr;
42     }
43 
44     FsFile &operator=(FsFile &&other) noexcept
45     {
46         if (this != &other) {
47             fileEntity = move(other.fileEntity);
48             other.fileEntity = nullptr;
49         }
50         return *this;
51     }
52 
53     ~FsFile() = default;
54 
55 #if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM)
56     FsResult<string> GetPath() const;
57     FsResult<string> GetName() const;
58     FsResult<string> GetParent() const;
59     FsResult<void> Lock(bool exclusive = false) const;
60     FsResult<void> TryLock(bool exclusive = false) const;
61     FsResult<void> UnLock() const;
62 #endif
63     static FsResult<FsFile *> Constructor();
64     FsResult<int32_t> GetFD() const;
65     void RemoveEntity();
66 
67 private:
68     unique_ptr<FileEntity> fileEntity;
FsFile(unique_ptr<FileEntity> entity)69     explicit FsFile(unique_ptr<FileEntity> entity) : fileEntity(move(entity)) {}
70 };
71 
72 const string PROCEDURE_LOCK_NAME = "FileIOFileLock";
73 } // namespace ModuleFileIO
74 } // namespace FileManagement
75 } // namespace OHOS
76 #endif // INTERFACES_KITS_JS_SRC_MOD_FS_CLASS_FILE_FS_FILE_H