@@ -173,20 +173,19 @@ Result<FileStats> StatFile(const std::string& path) {
173173
174174Status StatSelector (const PlatformFilename& dir_fn, const Selector& select,
175175 int32_t nesting_depth, std::vector<FileStats>* out) {
176- std::vector<PlatformFilename> children ;
177- Status status = ListDir (dir_fn, &children);
178- if (! status. ok ()) {
176+ auto result = ListDir (dir_fn) ;
177+ if (!result. ok ()) {
178+ auto status = result. status ();
179179 if (select.allow_non_existent && status.IsIOError ()) {
180- bool exists;
181- RETURN_NOT_OK (FileExists (dir_fn, &exists));
180+ ARROW_ASSIGN_OR_RAISE (bool exists, FileExists (dir_fn));
182181 if (!exists) {
183182 return Status::OK ();
184183 }
185184 }
186185 return status;
187186 }
188187
189- for (const auto & child_fn : children ) {
188+ for (const auto & child_fn : *result ) {
190189 PlatformFilename full_fn = dir_fn.Join (child_fn);
191190 ARROW_ASSIGN_OR_RAISE (FileStats st, StatFile (full_fn.ToNative ()));
192191 if (st.type () != FileType::NonExistent) {
@@ -214,34 +213,29 @@ LocalFileSystem::LocalFileSystem(const LocalFileSystemOptions& options)
214213LocalFileSystem::~LocalFileSystem () {}
215214
216215Result<FileStats> LocalFileSystem::GetTargetStats (const std::string& path) {
217- PlatformFilename fn;
218- RETURN_NOT_OK (PlatformFilename::FromString (path, &fn));
216+ ARROW_ASSIGN_OR_RAISE (auto fn, PlatformFilename::FromString (path));
219217 return StatFile (fn.ToNative ());
220218}
221219
222220Result<std::vector<FileStats>> LocalFileSystem::GetTargetStats (const Selector& select) {
223- PlatformFilename fn;
224- RETURN_NOT_OK (PlatformFilename::FromString (select.base_dir , &fn));
221+ ARROW_ASSIGN_OR_RAISE (auto fn, PlatformFilename::FromString (select.base_dir ));
225222 std::vector<FileStats> results;
226223 RETURN_NOT_OK (StatSelector (fn, select, 0 , &results));
227224 return results;
228225}
229226
230227Status LocalFileSystem::CreateDir (const std::string& path, bool recursive) {
231- PlatformFilename fn;
232- RETURN_NOT_OK (PlatformFilename::FromString (path, &fn));
228+ ARROW_ASSIGN_OR_RAISE (auto fn, PlatformFilename::FromString (path));
233229 if (recursive) {
234- return ::arrow::internal::CreateDirTree (fn);
230+ return ::arrow::internal::CreateDirTree (fn). status () ;
235231 } else {
236- return ::arrow::internal::CreateDir (fn);
232+ return ::arrow::internal::CreateDir (fn). status () ;
237233 }
238234}
239235
240236Status LocalFileSystem::DeleteDir (const std::string& path) {
241- bool deleted = false ;
242- PlatformFilename fn;
243- RETURN_NOT_OK (PlatformFilename::FromString (path, &fn));
244- RETURN_NOT_OK (::arrow::internal::DeleteDirTree (fn, &deleted));
237+ ARROW_ASSIGN_OR_RAISE (auto fn, PlatformFilename::FromString (path));
238+ ARROW_ASSIGN_OR_RAISE (bool deleted, ::arrow::internal::DeleteDirTree (fn));
245239 if (deleted) {
246240 return Status::OK ();
247241 } else {
@@ -250,10 +244,8 @@ Status LocalFileSystem::DeleteDir(const std::string& path) {
250244}
251245
252246Status LocalFileSystem::DeleteDirContents (const std::string& path) {
253- bool deleted = false ;
254- PlatformFilename fn;
255- RETURN_NOT_OK (PlatformFilename::FromString (path, &fn));
256- RETURN_NOT_OK (::arrow::internal::DeleteDirContents (fn, &deleted));
247+ ARROW_ASSIGN_OR_RAISE (auto fn, PlatformFilename::FromString (path));
248+ ARROW_ASSIGN_OR_RAISE (bool deleted, ::arrow::internal::DeleteDirContents (fn));
257249 if (deleted) {
258250 return Status::OK ();
259251 } else {
@@ -262,10 +254,8 @@ Status LocalFileSystem::DeleteDirContents(const std::string& path) {
262254}
263255
264256Status LocalFileSystem::DeleteFile (const std::string& path) {
265- bool deleted = false ;
266- PlatformFilename fn;
267- RETURN_NOT_OK (PlatformFilename::FromString (path, &fn));
268- RETURN_NOT_OK (::arrow::internal::DeleteFile (fn, &deleted));
257+ ARROW_ASSIGN_OR_RAISE (auto fn, PlatformFilename::FromString (path));
258+ ARROW_ASSIGN_OR_RAISE (bool deleted, arrow::internal::DeleteFile (fn));
269259 if (deleted) {
270260 return Status::OK ();
271261 } else {
@@ -274,9 +264,8 @@ Status LocalFileSystem::DeleteFile(const std::string& path) {
274264}
275265
276266Status LocalFileSystem::Move (const std::string& src, const std::string& dest) {
277- PlatformFilename sfn, dfn;
278- RETURN_NOT_OK (PlatformFilename::FromString (src, &sfn));
279- RETURN_NOT_OK (PlatformFilename::FromString (dest, &dfn));
267+ ARROW_ASSIGN_OR_RAISE (auto sfn, PlatformFilename::FromString (src));
268+ ARROW_ASSIGN_OR_RAISE (auto dfn, PlatformFilename::FromString (dest));
280269
281270#ifdef _WIN32
282271 if (!MoveFileExW (sfn.ToNative ().c_str (), dfn.ToNative ().c_str (),
@@ -294,9 +283,8 @@ Status LocalFileSystem::Move(const std::string& src, const std::string& dest) {
294283}
295284
296285Status LocalFileSystem::CopyFile (const std::string& src, const std::string& dest) {
297- PlatformFilename sfn, dfn;
298- RETURN_NOT_OK (PlatformFilename::FromString (src, &sfn));
299- RETURN_NOT_OK (PlatformFilename::FromString (dest, &dfn));
286+ ARROW_ASSIGN_OR_RAISE (auto sfn, PlatformFilename::FromString (src));
287+ ARROW_ASSIGN_OR_RAISE (auto dfn, PlatformFilename::FromString (dest));
300288 // XXX should we use fstat() to compare inodes?
301289 if (sfn.ToNative () == dfn.ToNative ()) {
302290 return Status::OK ();
@@ -351,12 +339,11 @@ namespace {
351339Result<std::shared_ptr<io::OutputStream>> OpenOutputStreamGeneric (const std::string& path,
352340 bool truncate,
353341 bool append) {
354- PlatformFilename fn;
355342 int fd;
356343 bool write_only = true ;
357- RETURN_NOT_OK ( PlatformFilename::FromString (path, &fn ));
358- RETURN_NOT_OK (
359- ::arrow::internal::FileOpenWritable (fn, write_only, truncate, append, &fd ));
344+ ARROW_ASSIGN_OR_RAISE ( auto fn, PlatformFilename::FromString (path));
345+ ARROW_ASSIGN_OR_RAISE (
346+ fd, ::arrow::internal::FileOpenWritable (fn, write_only, truncate, append));
360347 std::shared_ptr<io::OutputStream> stream;
361348 Status st = io::FileOutputStream::Open (fd, &stream);
362349 if (!st.ok ()) {
0 commit comments