]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/cpp/src/arrow/filesystem/util_internal.cc
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / cpp / src / arrow / filesystem / util_internal.cc
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
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
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
51 Status PathNotFound(const std::string& path) {
52 return Status::IOError("Path does not exist '", path, "'");
53 }
54
55 Status NotADir(const std::string& path) {
56 return Status::IOError("Not a directory: '", path, "'");
57 }
58
59 Status NotAFile(const std::string& path) {
60 return Status::IOError("Not a regular file: '", path, "'");
61 }
62
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