3131namespace paimon {
3232
3333Result<bool > LocalFileSystem::Exists (const std::string& path) const {
34- PAIMON_ASSIGN_OR_RAISE (LocalFile file, LocalFile::Create (path));
35- return file. Exists ();
34+ PAIMON_ASSIGN_OR_RAISE (std::unique_ptr< LocalFile> file, LocalFile::Create (path));
35+ return file-> Exists ();
3636}
3737
3838Result<std::unique_ptr<InputStream>> LocalFileSystem::Open (const std::string& path) const {
3939 PAIMON_ASSIGN_OR_RAISE (bool is_exist, Exists (path));
4040 if (!is_exist) {
4141 return Status::NotExist (fmt::format (" File '{}' not exists" , path));
4242 }
43- PAIMON_ASSIGN_OR_RAISE (LocalFile file, LocalFile::Create (path));
44- PAIMON_ASSIGN_OR_RAISE (std::unique_ptr<LocalInputStream> in, LocalInputStream::Create (file));
43+ PAIMON_ASSIGN_OR_RAISE (std::unique_ptr< LocalFile> file, LocalFile::Create (path));
44+ PAIMON_ASSIGN_OR_RAISE (std::unique_ptr<LocalInputStream> in, LocalInputStream::Create (* file));
4545 return in;
4646}
4747
@@ -52,16 +52,17 @@ Result<std::unique_ptr<OutputStream>> LocalFileSystem::Create(const std::string&
5252 return Status::Invalid (
5353 fmt::format (" do not allow overwrite, but the file {} already exists" , path));
5454 }
55- PAIMON_ASSIGN_OR_RAISE (LocalFile file, LocalFile::Create (path));
56- LocalFile parent = file. GetParentFile ();
55+ PAIMON_ASSIGN_OR_RAISE (std::unique_ptr< LocalFile> file, LocalFile::Create (path));
56+ LocalFile parent = file-> GetParentFile ();
5757 PAIMON_RETURN_NOT_OK (Mkdirs (parent.GetPath ()));
58- PAIMON_ASSIGN_OR_RAISE (std::unique_ptr<LocalOutputStream> out, LocalOutputStream::Create (file));
58+ PAIMON_ASSIGN_OR_RAISE (std::unique_ptr<LocalOutputStream> out,
59+ LocalOutputStream::Create (*file));
5960 return out;
6061}
6162
6263Status LocalFileSystem::Mkdirs (const std::string& path) const {
63- PAIMON_ASSIGN_OR_RAISE (LocalFile file, LocalFile::Create (path));
64- return MkdirsInternal (file);
64+ PAIMON_ASSIGN_OR_RAISE (std::unique_ptr< LocalFile> file, LocalFile::Create (path));
65+ return MkdirsInternal (* file);
6566}
6667
6768Status LocalFileSystem::MkdirsInternal (const LocalFile& file) const {
@@ -96,33 +97,33 @@ Status LocalFileSystem::MkdirsInternal(const LocalFile& file) const {
9697}
9798
9899Result<std::unique_ptr<FileStatus>> LocalFileSystem::GetFileStatus (const std::string& path) const {
99- PAIMON_ASSIGN_OR_RAISE (LocalFile file, LocalFile::Create (path));
100- PAIMON_ASSIGN_OR_RAISE (bool is_exist, file. Exists ());
100+ PAIMON_ASSIGN_OR_RAISE (std::unique_ptr< LocalFile> file, LocalFile::Create (path));
101+ PAIMON_ASSIGN_OR_RAISE (bool is_exist, file-> Exists ());
101102 if (is_exist) {
102- return file. GetFileStatus ();
103+ return file-> GetFileStatus ();
103104 } else {
104105 return Status::NotExist (
105106 fmt::format (" File {} does not exist or the user running "
106107 " Paimon has insufficient permissions to access it." ,
107- file. GetPath ()));
108+ file-> GetPath ()));
108109 }
109110}
110111
111112Status LocalFileSystem::ListDir (
112113 const std::string& directory,
113114 std::vector<std::unique_ptr<BasicFileStatus>>* file_status_list) const {
114- PAIMON_ASSIGN_OR_RAISE (LocalFile file, LocalFile::Create (directory));
115- PAIMON_ASSIGN_OR_RAISE (bool is_exist, file. Exists ());
115+ PAIMON_ASSIGN_OR_RAISE (std::unique_ptr< LocalFile> file, LocalFile::Create (directory));
116+ PAIMON_ASSIGN_OR_RAISE (bool is_exist, file-> Exists ());
116117 if (!is_exist) {
117118 return Status::OK ();
118119 }
119- PAIMON_ASSIGN_OR_RAISE (bool is_file, file. IsFile ());
120+ PAIMON_ASSIGN_OR_RAISE (bool is_file, file-> IsFile ());
120121 if (is_file) {
121122 return Status::IOError (
122- fmt::format (" file {} already exists and is not a directory" , file. GetPath ()));
123+ fmt::format (" file {} already exists and is not a directory" , file-> GetPath ()));
123124 } else {
124125 std::vector<std::string> file_list;
125- PAIMON_RETURN_NOT_OK (file. List (&file_list));
126+ PAIMON_RETURN_NOT_OK (file-> List (&file_list));
126127 file_status_list->reserve (file_status_list->size () + file_list.size ());
127128 for (const auto & f : file_list) {
128129 Result<std::unique_ptr<FileStatus>> file_status =
@@ -140,18 +141,18 @@ Status LocalFileSystem::ListDir(
140141
141142Status LocalFileSystem::ListFileStatus (
142143 const std::string& path, std::vector<std::unique_ptr<FileStatus>>* file_status_list) const {
143- PAIMON_ASSIGN_OR_RAISE (LocalFile file, LocalFile::Create (path));
144- PAIMON_ASSIGN_OR_RAISE (bool is_exist, file. Exists ());
144+ PAIMON_ASSIGN_OR_RAISE (std::unique_ptr< LocalFile> file, LocalFile::Create (path));
145+ PAIMON_ASSIGN_OR_RAISE (bool is_exist, file-> Exists ());
145146 if (!is_exist) {
146147 return Status::OK ();
147148 }
148- PAIMON_ASSIGN_OR_RAISE (bool is_file, file. IsFile ());
149+ PAIMON_ASSIGN_OR_RAISE (bool is_file, file-> IsFile ());
149150 if (is_file) {
150- PAIMON_ASSIGN_OR_RAISE (std::unique_ptr<FileStatus> file_status, file. GetFileStatus ());
151+ PAIMON_ASSIGN_OR_RAISE (std::unique_ptr<FileStatus> file_status, file-> GetFileStatus ());
151152 file_status_list->emplace_back (std::move (file_status));
152153 } else {
153154 std::vector<std::string> file_list;
154- PAIMON_RETURN_NOT_OK (file. List (&file_list));
155+ PAIMON_RETURN_NOT_OK (file-> List (&file_list));
155156 file_status_list->reserve (file_status_list->size () + file_list.size ());
156157 for (const auto & f : file_list) {
157158 Result<std::unique_ptr<FileStatus>> file_status =
@@ -167,12 +168,12 @@ Status LocalFileSystem::ListFileStatus(
167168}
168169
169170Status LocalFileSystem::Delete (const std::string& path, bool recursive) const {
170- PAIMON_ASSIGN_OR_RAISE (LocalFile file, LocalFile::Create (path));
171- PAIMON_ASSIGN_OR_RAISE (bool is_file, file. IsFile ());
171+ PAIMON_ASSIGN_OR_RAISE (std::unique_ptr< LocalFile> file, LocalFile::Create (path));
172+ PAIMON_ASSIGN_OR_RAISE (bool is_file, file-> IsFile ());
172173 if (is_file) {
173- return file. Delete ();
174+ return file-> Delete ();
174175 }
175- return Delete (file, recursive);
176+ return Delete (* file, recursive);
176177}
177178
178179Status LocalFileSystem::Delete (const LocalFile& f, bool recursive) const {
@@ -202,17 +203,17 @@ Status LocalFileSystem::Rename(const std::string& src, const std::string& dst) c
202203 if (is_dst_exist) {
203204 return Status::Invalid (err_msg, " dst file already exist" );
204205 }
205- PAIMON_ASSIGN_OR_RAISE (LocalFile src_file, LocalFile::Create (src));
206- PAIMON_ASSIGN_OR_RAISE (bool is_file, src_file. IsFile ());
206+ PAIMON_ASSIGN_OR_RAISE (std::unique_ptr< LocalFile> src_file, LocalFile::Create (src));
207+ PAIMON_ASSIGN_OR_RAISE (bool is_file, src_file-> IsFile ());
207208 std::string new_file_name = dst;
208209
209210 if (is_file && new_file_name[new_file_name.length () - 1 ] == ' /' ) {
210211 return Status::Invalid (err_msg, " src file is not a dir" );
211212 }
212- PAIMON_ASSIGN_OR_RAISE (LocalFile dst_file, LocalFile::Create (dst));
213- auto parent = dst_file. GetParentFile ();
213+ PAIMON_ASSIGN_OR_RAISE (std::unique_ptr< LocalFile> dst_file, LocalFile::Create (dst));
214+ auto parent = dst_file-> GetParentFile ();
214215 PAIMON_RETURN_NOT_OK (Mkdirs (parent.GetPath ()));
215- if (::rename (src_file. GetPath ().c_str (), dst_file. GetPath ().c_str ()) != 0 ) {
216+ if (::rename (src_file-> GetPath ().c_str (), dst_file-> GetPath ().c_str ()) != 0 ) {
216217 int32_t cur_errno = errno;
217218 return Status::IOError (err_msg, std::strerror (cur_errno));
218219 }
0 commit comments