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 #pragma once 19 20 #include <memory> 21 #include <string> 22 #include <vector> 23 24 #include "arrow/filesystem/filesystem.h" 25 26 namespace arrow { 27 namespace internal { 28 29 class Uri; 30 31 } 32 33 namespace fs { 34 35 /// Options for the LocalFileSystem implementation. 36 struct ARROW_EXPORT LocalFileSystemOptions { 37 /// Whether OpenInputStream and OpenInputFile return a mmap'ed file, 38 /// or a regular one. 39 bool use_mmap = false; 40 41 /// \brief Initialize with defaults 42 static LocalFileSystemOptions Defaults(); 43 44 bool Equals(const LocalFileSystemOptions& other) const; 45 46 static Result<LocalFileSystemOptions> FromUri(const ::arrow::internal::Uri& uri, 47 std::string* out_path); 48 }; 49 50 /// \brief A FileSystem implementation accessing files on the local machine. 51 /// 52 /// This class handles only `/`-separated paths. If desired, conversion 53 /// from Windows backslash-separated paths should be done by the caller. 54 /// Details such as symlinks are abstracted away (symlinks are always 55 /// followed, except when deleting an entry). 56 class ARROW_EXPORT LocalFileSystem : public FileSystem { 57 public: 58 explicit LocalFileSystem(const io::IOContext& = io::default_io_context()); 59 explicit LocalFileSystem(const LocalFileSystemOptions&, 60 const io::IOContext& = io::default_io_context()); 61 ~LocalFileSystem() override; 62 type_name()63 std::string type_name() const override { return "local"; } 64 65 Result<std::string> NormalizePath(std::string path) override; 66 67 bool Equals(const FileSystem& other) const override; 68 options()69 LocalFileSystemOptions options() const { return options_; } 70 71 /// \cond FALSE 72 using FileSystem::GetFileInfo; 73 /// \endcond 74 Result<FileInfo> GetFileInfo(const std::string& path) override; 75 Result<std::vector<FileInfo>> GetFileInfo(const FileSelector& select) override; 76 77 Status CreateDir(const std::string& path, bool recursive = true) override; 78 79 Status DeleteDir(const std::string& path) override; 80 Status DeleteDirContents(const std::string& path) override; 81 Status DeleteRootDirContents() override; 82 83 Status DeleteFile(const std::string& path) override; 84 85 Status Move(const std::string& src, const std::string& dest) override; 86 87 Status CopyFile(const std::string& src, const std::string& dest) override; 88 89 Result<std::shared_ptr<io::InputStream>> OpenInputStream( 90 const std::string& path) override; 91 Result<std::shared_ptr<io::RandomAccessFile>> OpenInputFile( 92 const std::string& path) override; 93 Result<std::shared_ptr<io::OutputStream>> OpenOutputStream( 94 const std::string& path, 95 const std::shared_ptr<const KeyValueMetadata>& metadata = {}) override; 96 Result<std::shared_ptr<io::OutputStream>> OpenAppendStream( 97 const std::string& path, 98 const std::shared_ptr<const KeyValueMetadata>& metadata = {}) override; 99 100 protected: 101 LocalFileSystemOptions options_; 102 }; 103 104 namespace internal { 105 106 // Return whether the string is detected as a local absolute path. 107 ARROW_EXPORT 108 bool DetectAbsolutePath(const std::string& s); 109 110 } // namespace internal 111 112 } // namespace fs 113 } // namespace arrow 114