1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing,
12 // software distributed under the License is distributed on an
13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, either express or implied. See the License for the
15 // specific language governing permissions and limitations
16 // under the License.
17
18 #include "arrow/filesystem/util_internal.h"
19 #include "arrow/buffer.h"
20 #include "arrow/result.h"
21 #include "arrow/status.h"
22
23 namespace arrow {
24 namespace fs {
25 namespace internal {
26
CurrentTimePoint()27 TimePoint CurrentTimePoint() {
28 auto now = std::chrono::system_clock::now();
29 return TimePoint(
30 std::chrono::duration_cast<TimePoint::duration>(now.time_since_epoch()));
31 }
32
CopyStream(const std::shared_ptr<io::InputStream> & src,const std::shared_ptr<io::OutputStream> & dest,int64_t chunk_size,const io::IOContext & io_context)33 Status CopyStream(const std::shared_ptr<io::InputStream>& src,
34 const std::shared_ptr<io::OutputStream>& dest, int64_t chunk_size,
35 const io::IOContext& io_context) {
36 ARROW_ASSIGN_OR_RAISE(auto chunk, AllocateBuffer(chunk_size, io_context.pool()));
37
38 while (true) {
39 ARROW_ASSIGN_OR_RAISE(int64_t bytes_read,
40 src->Read(chunk_size, chunk->mutable_data()));
41 if (bytes_read == 0) {
42 // EOF
43 break;
44 }
45 RETURN_NOT_OK(dest->Write(chunk->data(), bytes_read));
46 }
47
48 return Status::OK();
49 }
50
PathNotFound(const std::string & path)51 Status PathNotFound(const std::string& path) {
52 return Status::IOError("Path does not exist '", path, "'");
53 }
54
NotADir(const std::string & path)55 Status NotADir(const std::string& path) {
56 return Status::IOError("Not a directory: '", path, "'");
57 }
58
NotAFile(const std::string & path)59 Status NotAFile(const std::string& path) {
60 return Status::IOError("Not a regular file: '", path, "'");
61 }
62
InvalidDeleteDirContents(const std::string & path)63 Status InvalidDeleteDirContents(const std::string& path) {
64 return Status::Invalid(
65 "DeleteDirContents called on invalid path '", path, "'. ",
66 "If you wish to delete the root directory's contents, call DeleteRootDirContents.");
67 }
68
69 FileSystemGlobalOptions global_options;
70
71 } // namespace internal
72 } // namespace fs
73 } // namespace arrow
74