Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::VirtualFileSystem Class Reference
Inheritance diagram for duckdb::VirtualFileSystem:
Collaboration diagram for duckdb::VirtualFileSystem:

Public Member Functions

 VirtualFileSystem (unique_ptr< FileSystem > &&inner_file_system)
void Read (FileHandle &handle, void *buffer, int64_t nr_bytes, idx_t location) override
void Write (FileHandle &handle, void *buffer, int64_t nr_bytes, idx_t location) override
int64_t Read (FileHandle &handle, void *buffer, int64_t nr_bytes) override
int64_t Write (FileHandle &handle, void *buffer, int64_t nr_bytes) override
 Write nr_bytes from the buffer into the file, moving the file pointer forward by nr_bytes.
int64_t GetFileSize (FileHandle &handle) override
 Returns the file size of a file handle, returns -1 on error.
timestamp_t GetLastModifiedTime (FileHandle &handle) override
 Returns the file last modified time of a file handle, returns timespec with zero on all attributes on error.
string GetVersionTag (FileHandle &handle) override
FileType GetFileType (FileHandle &handle) override
 Returns the file type of the attached handle.
FileMetadata Stats (FileHandle &handle) override
 Returns the file stats of the attached handle.
void Truncate (FileHandle &handle, int64_t new_size) override
void FileSync (FileHandle &handle) override
 Sync a file handle to disk.
bool DirectoryExists (const string &directory, optional_ptr< FileOpener > opener) override
 Check if a directory exists.
void CreateDirectory (const string &directory, optional_ptr< FileOpener > opener) override
 Create a directory if it does not exist.
void RemoveDirectory (const string &directory, optional_ptr< FileOpener > opener) override
 Recursively remove a directory and all files in it.
void MoveFile (const string &source, const string &target, optional_ptr< FileOpener > opener) override
bool FileExists (const string &filename, optional_ptr< FileOpener > opener) override
 Check if a file exists.
bool IsPipe (const string &filename, optional_ptr< FileOpener > opener) override
 Check if path is pipe.
void RemoveFile (const string &filename, optional_ptr< FileOpener > opener) override
 Remove a file from disk.
bool TryRemoveFile (const string &filename, optional_ptr< FileOpener > opener) override
 Remvoe a file from disk if it exists - if it does not exist, return false.
void RemoveFiles (const vector< string > &filenames, optional_ptr< FileOpener > opener) override
 Remove multiple files from disk - does not error if any file does not exist.
void RegisterSubSystem (unique_ptr< FileSystem > fs) override
 registers a sub-file system to handle certain file name prefixes, e.g. http:// etc.
void RegisterSubSystem (FileCompressionType compression_type, unique_ptr< FileSystem > fs) override
void UnregisterSubSystem (const string &name) override
 Unregister a sub-filesystem by name.
unique_ptr< FileSystem > ExtractSubSystem (const string &name) override
vector< string > ListSubSystems () override
 List registered sub-filesystems, including builtin ones.
std::string GetName () const override
 Return the name of the filesytem. Used for forming diagnosis messages.
void SetDisabledFileSystems (const vector< string > &names) override
bool SubSystemIsDisabled (const string &name) override
bool IsDisabledForPath (const string &path) override
 Check if the filesystem that would handle this path is disabled.
string PathSeparator (const string &path) override
 Path separator for path.
string CanonicalizePath (const string &path_p, optional_ptr< FileOpener > opener) override
 Canonicalize a path.
Public Member Functions inherited from duckdb::FileSystem
virtual DUCKDB_API unique_ptr< FileHandle > OpenFile (const string &path, FileOpenFlags flags, optional_ptr< FileOpener > opener=nullptr)
DUCKDB_API unique_ptr< FileHandle > OpenFile (const OpenFileInfo &path, FileOpenFlags flags, optional_ptr< FileOpener > opener=nullptr)
virtual DUCKDB_API bool Trim (FileHandle &handle, idx_t offset_bytes, idx_t length_bytes)
virtual DUCKDB_API void CreateDirectoriesRecursive (const string &path, optional_ptr< FileOpener > opener=nullptr)
 Helper function that uses DirectoryExists and CreateDirectory to ensure all directories in path are created.
virtual DUCKDB_API bool ListFiles (const string &directory, const std::function< void(const string &, bool)> &callback, FileOpener *opener=nullptr)
 List files in a directory, invoking the callback method for each one with (filename, is_dir).
DUCKDB_API bool ListFiles (const string &directory, const std::function< void(OpenFileInfo &info)> &callback, optional_ptr< FileOpener > opener=nullptr)
virtual DUCKDB_API string GetHomeDirectory ()
 Gets the users home directory.
virtual DUCKDB_API string ExpandPath (const string &path)
 Expands a given path, including e.g. expanding the home directory of the user.
virtual DUCKDB_API bool IsPathAbsolute (const string &path)
 Checks if path is is an absolute path.
DUCKDB_API string JoinPath (const string &a, const string &path)
 Join two paths together.
template<typename... ARGS>
string JoinPath (const string &a, const string &b, ARGS... args)
DUCKDB_API string ConvertSeparators (const string &path)
 Convert separators in a path to the local separators (e.g. convert "/" into \ on windows).
DUCKDB_API string ExtractBaseName (const string &path)
 Extract the base name of a file (e.g. if the input is lib/example.dll the base name is 'example').
DUCKDB_API string ExtractExtension (const string &path)
 Extract the extension of a file (e.g. if the input is lib/example.dll the extension is 'dll').
DUCKDB_API string ExtractName (const string &path)
 Extract the name of a file (e.g if the input is lib/example.dll the name is 'example.dll').
virtual DUCKDB_API vector< OpenFileInfo > Glob (const string &path, FileOpener *opener=nullptr)
 Runs a glob on the file system, returning a list of matching files.
DUCKDB_API unique_ptr< MultiFileList > Glob (const string &path, const FileGlobInput &input, optional_ptr< FileOpener > opener)
DUCKDB_API unique_ptr< MultiFileList > GlobFileList (const string &path, const FileGlobInput &input=FileGlobOptions::DISALLOW_EMPTY)
DUCKDB_API vector< OpenFileInfo > GlobFiles (const string &pattern, const FileGlobInput &input=FileGlobOptions::DISALLOW_EMPTY)
virtual DUCKDB_API bool CanHandleFile (const string &fpath)
 Whether or not a sub-system can handle a specific file path.
virtual DUCKDB_API void Seek (FileHandle &handle, idx_t location)
 Set the file pointer of a file handle to a specified location. Reads and writes will happen from this location.
virtual DUCKDB_API void Reset (FileHandle &handle)
 Reset a file to the beginning (equivalent to Seek(handle, 0) for simple files).
virtual DUCKDB_API idx_t SeekPosition (FileHandle &handle)
virtual DUCKDB_API bool IsManuallySet ()
 If FS was manually set by the user.
virtual DUCKDB_API bool CanSeek ()
 Whether or not we can seek into the file.
virtual DUCKDB_API bool OnDiskFile (FileHandle &handle)
virtual DUCKDB_API unique_ptr< FileHandle > OpenCompressedFile (QueryContext context, unique_ptr< FileHandle > handle, bool write)
template<class TARGET>
TARGET & Cast ()
template<class TARGET>
const TARGET & Cast () const

Protected Member Functions

unique_ptr< FileHandle > OpenFileExtended (const OpenFileInfo &file, FileOpenFlags flags, optional_ptr< FileOpener > opener) override
bool SupportsOpenFileExtended () const override
bool ListFilesExtended (const string &directory, const std::function< void(OpenFileInfo &info)> &callback, optional_ptr< FileOpener > opener) override
bool SupportsListFilesExtended () const override
unique_ptr< MultiFileList > GlobFilesExtended (const string &path, const FileGlobInput &input, optional_ptr< FileOpener > opener) override
bool SupportsGlobExtended () const override

Private Member Functions

FileSystem & FindFileSystem (const string &path, optional_ptr< FileOpener > file_opener)
FileSystem & FindFileSystem (shared_ptr< FileSystemRegistry > &registry, const string &path, optional_ptr< FileOpener > file_opener)
optional_ptr< FileSystem > FindFileSystemInternal (FileSystemRegistry &registry, const string &path)

Private Attributes

mutex registry_lock
shared_ptr< FileSystemRegistry > file_system_registry
vector< unique_ptr< FileSystem > > unregistered_file_systems

Additional Inherited Members

Static Public Member Functions inherited from duckdb::FileSystem
static DUCKDB_API FileSystem & GetFileSystem (ClientContext &context)
static DUCKDB_API FileSystem & GetFileSystem (DatabaseInstance &db)
static DUCKDB_API FileSystem & Get (AttachedDatabase &db)
static DUCKDB_API void SetWorkingDirectory (const string &path)
 Sets the working directory.
static DUCKDB_API string GetWorkingDirectory ()
 Gets the working directory.
static DUCKDB_API string GetHomeDirectory (optional_ptr< FileOpener > opener)
 Gets the users home directory.
static DUCKDB_API string ExpandPath (const string &path, optional_ptr< FileOpener > opener)
 Expands a given path, including e.g. expanding the home directory of the user.
static DUCKDB_API optional_idx GetAvailableMemory ()
 Returns the system-available memory in bytes. Returns DConstants::INVALID_INDEX if the system function fails.
static DUCKDB_API optional_idx GetAvailableDiskSpace (const string &path)
 Returns the space available on the disk. Returns DConstants::INVALID_INDEX if the information was not available.
static DUCKDB_API string GetEnvVariable (const string &name)
 Returns the value of an environment variable - or the empty string if it is not set.
static DUCKDB_API bool HasGlob (const string &str)
 Whether there is a glob in the string.
static DUCKDB_API unique_ptr< FileSystem > CreateLocal ()
 Create a LocalFileSystem.
static DUCKDB_API bool IsRemoteFile (const string &path)
 Whether or not a file is remote or local, based only on file path.
static DUCKDB_API bool IsRemoteFile (const string &path, string &extension)
static DUCKDB_API bool IsDirectory (const OpenFileInfo &info)

Constructor & Destructor Documentation

◆ VirtualFileSystem() [1/2]

duckdb::VirtualFileSystem::VirtualFileSystem ( )
145028 : VirtualFileSystem(FileSystem::CreateLocal()) {
145029}
static DUCKDB_API unique_ptr< FileSystem > CreateLocal()
Create a LocalFileSystem.
Definition duckdb.cpp:80214

◆ VirtualFileSystem() [2/2]

duckdb::VirtualFileSystem::VirtualFileSystem ( unique_ptr< FileSystem > && inner_file_system)
explicit
145032 : file_system_registry(make_shared_ptr<FileSystemRegistry>(std::move(inner))) {
145033 VirtualFileSystem::RegisterSubSystem(FileCompressionType::GZIP, make_uniq<GZipFileSystem>());
145034}
void RegisterSubSystem(unique_ptr< FileSystem > fs) override
registers a sub-file system to handle certain file name prefixes, e.g. http:// etc.
Definition duckdb.cpp:145203

◆ ~VirtualFileSystem()

duckdb::VirtualFileSystem::~VirtualFileSystem ( )
override
145036 {
145037}

Member Function Documentation

◆ Read() [1/2]

void duckdb::VirtualFileSystem::Read ( FileHandle & handle,
void * buffer,
int64_t nr_bytes,
idx_t location )
overridevirtual

Read exactly nr_bytes from the specified location in the file. Fails if nr_bytes could not be read. This is equivalent to calling SetFilePointer(location) followed by calling Read().

Reimplemented from duckdb::FileSystem.

145101 {
145102 handle.file_system.Read(handle, buffer, nr_bytes, location);
145103}
Here is the call graph for this function:

◆ Write() [1/2]

void duckdb::VirtualFileSystem::Write ( FileHandle & handle,
void * buffer,
int64_t nr_bytes,
idx_t location )
overridevirtual

Write exactly nr_bytes to the specified location in the file. Fails if nr_bytes could not be written. This is equivalent to calling SetFilePointer(location) followed by calling Write().

Reimplemented from duckdb::FileSystem.

145105 {
145106 handle.file_system.Write(handle, buffer, nr_bytes, location);
145107}
Here is the call graph for this function:

◆ Read() [2/2]

int64_t duckdb::VirtualFileSystem::Read ( FileHandle & handle,
void * buffer,
int64_t nr_bytes )
overridevirtual

Read nr_bytes from the specified file into the buffer, moving the file pointer forward by nr_bytes. Returns the amount of bytes read.

Reimplemented from duckdb::FileSystem.

145109 {
145110 return handle.file_system.Read(handle, buffer, nr_bytes);
145111}
Here is the call graph for this function:

◆ Write() [2/2]

int64_t duckdb::VirtualFileSystem::Write ( FileHandle & handle,
void * buffer,
int64_t nr_bytes )
overridevirtual

Write nr_bytes from the buffer into the file, moving the file pointer forward by nr_bytes.

Reimplemented from duckdb::FileSystem.

145113 {
145114 return handle.file_system.Write(handle, buffer, nr_bytes);
145115}
Here is the call graph for this function:

◆ GetFileSize()

int64_t duckdb::VirtualFileSystem::GetFileSize ( FileHandle & handle)
overridevirtual

Returns the file size of a file handle, returns -1 on error.

Reimplemented from duckdb::FileSystem.

145117 {
145118 return handle.file_system.GetFileSize(handle);
145119}
Here is the call graph for this function:

◆ GetLastModifiedTime()

timestamp_t duckdb::VirtualFileSystem::GetLastModifiedTime ( FileHandle & handle)
overridevirtual

Returns the file last modified time of a file handle, returns timespec with zero on all attributes on error.

Reimplemented from duckdb::FileSystem.

145120 {
145121 return handle.file_system.GetLastModifiedTime(handle);
145122}
Here is the call graph for this function:

◆ GetVersionTag()

string duckdb::VirtualFileSystem::GetVersionTag ( FileHandle & handle)
overridevirtual

Returns a tag that uniquely identifies the version of the file, used for checking cache invalidation for CachingFileSystem httpfs files

Reimplemented from duckdb::FileSystem.

145123 {
145124 return handle.file_system.GetVersionTag(handle);
145125}
Here is the call graph for this function:

◆ GetFileType()

FileType duckdb::VirtualFileSystem::GetFileType ( FileHandle & handle)
overridevirtual

Returns the file type of the attached handle.

Reimplemented from duckdb::FileSystem.

145126 {
145127 return handle.file_system.GetFileType(handle);
145128}
Here is the call graph for this function:

◆ Stats()

FileMetadata duckdb::VirtualFileSystem::Stats ( FileHandle & handle)
overridevirtual

Returns the file stats of the attached handle.

Reimplemented from duckdb::FileSystem.

145129 {
145130 return handle.file_system.Stats(handle);
145131}
Here is the call graph for this function:

◆ Truncate()

void duckdb::VirtualFileSystem::Truncate ( FileHandle & handle,
int64_t new_size )
overridevirtual

Truncate a file to a maximum size of new_size, new_size should be smaller than or equal to the current size of the file

Reimplemented from duckdb::FileSystem.

145133 {
145134 handle.file_system.Truncate(handle, new_size);
145135}
Here is the call graph for this function:

◆ FileSync()

void duckdb::VirtualFileSystem::FileSync ( FileHandle & handle)
overridevirtual

Sync a file handle to disk.

Reimplemented from duckdb::FileSystem.

145137 {
145138 handle.file_system.FileSync(handle);
145139}
Here is the call graph for this function:

◆ DirectoryExists()

bool duckdb::VirtualFileSystem::DirectoryExists ( const string & directory,
optional_ptr< FileOpener > opener )
overridevirtual

Check if a directory exists.

Reimplemented from duckdb::FileSystem.

145142 {
145143 return FindFileSystem(directory, opener).DirectoryExists(directory, opener);
145144}

◆ CreateDirectory()

void duckdb::VirtualFileSystem::CreateDirectory ( const string & directory,
optional_ptr< FileOpener > opener )
overridevirtual

Create a directory if it does not exist.

Reimplemented from duckdb::FileSystem.

145145 {
145146 FindFileSystem(directory, opener).CreateDirectory(directory, opener);
145147}

◆ RemoveDirectory()

void duckdb::VirtualFileSystem::RemoveDirectory ( const string & directory,
optional_ptr< FileOpener > opener )
overridevirtual

Recursively remove a directory and all files in it.

Reimplemented from duckdb::FileSystem.

145149 {
145150 FindFileSystem(directory, opener).RemoveDirectory(directory, opener);
145151}

◆ MoveFile()

void duckdb::VirtualFileSystem::MoveFile ( const string & source,
const string & target,
optional_ptr< FileOpener > opener )
overridevirtual

Move a file from source path to the target, StorageManager relies on this being an atomic action for ACID properties

Reimplemented from duckdb::FileSystem.

145159 {
145160 FindFileSystem(source, opener).MoveFile(source, target, opener);
145161}

◆ FileExists()

bool duckdb::VirtualFileSystem::FileExists ( const string & filename,
optional_ptr< FileOpener > opener )
overridevirtual

Check if a file exists.

Reimplemented from duckdb::FileSystem.

145163 {
145164 return FindFileSystem(filename, opener).FileExists(filename, opener);
145165}

◆ IsPipe()

bool duckdb::VirtualFileSystem::IsPipe ( const string & filename,
optional_ptr< FileOpener > opener )
overridevirtual

Check if path is pipe.

Reimplemented from duckdb::FileSystem.

145167 {
145168 return FindFileSystem(filename, opener).IsPipe(filename, opener);
145169}

◆ RemoveFile()

void duckdb::VirtualFileSystem::RemoveFile ( const string & filename,
optional_ptr< FileOpener > opener )
overridevirtual

Remove a file from disk.

Reimplemented from duckdb::FileSystem.

145171 {
145172 FindFileSystem(filename, opener).RemoveFile(filename, opener);
145173}

◆ TryRemoveFile()

bool duckdb::VirtualFileSystem::TryRemoveFile ( const string & filename,
optional_ptr< FileOpener > opener )
overridevirtual

Remvoe a file from disk if it exists - if it does not exist, return false.

Reimplemented from duckdb::FileSystem.

145175 {
145176 return FindFileSystem(filename, opener).TryRemoveFile(filename, opener);
145177}

◆ RemoveFiles()

void duckdb::VirtualFileSystem::RemoveFiles ( const vector< string > & filenames,
optional_ptr< FileOpener > opener )
overridevirtual

Remove multiple files from disk - does not error if any file does not exist.

Reimplemented from duckdb::FileSystem.

145179 {
145180 reference_map_t<FileSystem, vector<string>> files_by_fs;
145181 for (const auto &filename : filenames) {
145182 auto &fs = FindFileSystem(filename, opener);
145183 files_by_fs[fs].push_back(filename);
145184 }
145185 for (auto &entry : files_by_fs) {
145186 entry.first.get().RemoveFiles(entry.second, opener);
145187 }
145188}

◆ RegisterSubSystem() [1/2]

void duckdb::VirtualFileSystem::RegisterSubSystem ( unique_ptr< FileSystem > sub_fs)
overridevirtual

registers a sub-file system to handle certain file name prefixes, e.g. http:// etc.

Reimplemented from duckdb::FileSystem.

145203 {
145204 lock_guard<mutex> guard(registry_lock);
145205 auto new_registry = file_system_registry->RegisterSubSystem(std::move(fs));
145206 file_system_registry.atomic_store(new_registry);
145207}

◆ RegisterSubSystem() [2/2]

void duckdb::VirtualFileSystem::RegisterSubSystem ( FileCompressionType compression_type,
unique_ptr< FileSystem > fs )
overridevirtual

Reimplemented from duckdb::FileSystem.

145209 {
145210 lock_guard<mutex> guard(registry_lock);
145211 auto new_registry = file_system_registry->RegisterSubSystem(compression_type, std::move(fs));
145212 file_system_registry.atomic_store(new_registry);
145213}

◆ UnregisterSubSystem()

void duckdb::VirtualFileSystem::UnregisterSubSystem ( const string & name)
overridevirtual

Unregister a sub-filesystem by name.

Reimplemented from duckdb::FileSystem.

145215 {
145216 auto sub_system = ExtractSubSystem(name);
145217
145218 lock_guard<mutex> guard(registry_lock);
145219 unregistered_file_systems.push_back(std::move(sub_system));
145220}

◆ ExtractSubSystem()

unique_ptr< FileSystem > duckdb::VirtualFileSystem::ExtractSubSystem ( const string & name)
overridevirtual

Reimplemented from duckdb::FileSystem.

145227 {
145228 lock_guard<mutex> guard(registry_lock);
145229 unique_ptr<FileSystem> result;
145230 auto new_registry = file_system_registry->ExtractSubSystem(name, result);
145231 if (new_registry) {
145232 file_system_registry.atomic_store(new_registry);
145233 }
145234 return result;
145235}

◆ ListSubSystems()

vector< string > duckdb::VirtualFileSystem::ListSubSystems ( )
overridevirtual

List registered sub-filesystems, including builtin ones.

Reimplemented from duckdb::FileSystem.

145237 {
145238 auto registry = file_system_registry.atomic_load();
145239 auto &sub_systems = registry->sub_systems;
145240 vector<string> names;
145241 for (auto &sub_system : sub_systems) {
145242 names.push_back(sub_system->file_system->GetName());
145243 }
145244 return names;
145245}

◆ GetName()

std::string duckdb::VirtualFileSystem::GetName ( ) const
overridevirtual

Return the name of the filesytem. Used for forming diagnosis messages.

Implements duckdb::FileSystem.

145247 {
145248 return "VirtualFileSystem";
145249}

◆ SetDisabledFileSystems()

void duckdb::VirtualFileSystem::SetDisabledFileSystems ( const vector< string > & names)
overridevirtual

Reimplemented from duckdb::FileSystem.

145222 {
145223 lock_guard<mutex> guard(registry_lock);
145224 auto new_registry = file_system_registry->SetDisabledFileSystems(names);
145225 file_system_registry.atomic_store(new_registry);
145226}

◆ SubSystemIsDisabled()

bool duckdb::VirtualFileSystem::SubSystemIsDisabled ( const string & name)
overridevirtual

Reimplemented from duckdb::FileSystem.

145251 {
145252 auto registry = file_system_registry.atomic_load();
145253 auto &disabled_file_systems = registry->disabled_file_systems;
145254 return disabled_file_systems.find(name) != disabled_file_systems.end();
145255}

◆ IsDisabledForPath()

bool duckdb::VirtualFileSystem::IsDisabledForPath ( const string & path)
overridevirtual

Check if the filesystem that would handle this path is disabled.

Reimplemented from duckdb::FileSystem.

145257 {
145258 auto registry = file_system_registry.atomic_load();
145259 auto &disabled_file_systems = registry->disabled_file_systems;
145260 if (disabled_file_systems.empty()) {
145261 return false;
145262 }
145263 auto fs = FindFileSystemInternal(*registry, path);
145264 if (!fs) {
145265 fs = registry->default_fs->file_system;
145266 }
145267 return disabled_file_systems.find(fs->GetName()) != disabled_file_systems.end();
145268}

◆ PathSeparator()

string duckdb::VirtualFileSystem::PathSeparator ( const string & path)
overridevirtual

Path separator for path.

Reimplemented from duckdb::FileSystem.

145190 {
145191 return FindFileSystem(path, nullptr).PathSeparator(path);
145192}

◆ CanonicalizePath()

string duckdb::VirtualFileSystem::CanonicalizePath ( const string & path,
optional_ptr< FileOpener > opener )
overridevirtual

Canonicalize a path.

Reimplemented from duckdb::FileSystem.

145194 {
145195 return FindFileSystem(path_p, opener).CanonicalizePath(path_p, opener);
145196}

◆ OpenFileExtended()

unique_ptr< FileHandle > duckdb::VirtualFileSystem::OpenFileExtended ( const OpenFileInfo & file,
FileOpenFlags flags,
optional_ptr< FileOpener > opener )
overrideprotectedvirtual

Reimplemented from duckdb::FileSystem.

145040 {
145041 auto compression = flags.Compression();
145042 if (compression == FileCompressionType::AUTO_DETECT) {
145043 // auto-detect compression settings based on file name
145044 auto lower_path = StringUtil::Lower(file.path);
145045 if (StringUtil::EndsWith(lower_path, ".tmp")) {
145046 // strip .tmp
145047 lower_path = lower_path.substr(0, lower_path.length() - 4);
145048 }
145049 if (IsFileCompressed(file.path, FileCompressionType::GZIP)) {
145050 compression = FileCompressionType::GZIP;
145051 } else if (IsFileCompressed(file.path, FileCompressionType::ZSTD)) {
145052 compression = FileCompressionType::ZSTD;
145053 } else {
145054 compression = FileCompressionType::UNCOMPRESSED;
145055 }
145056 }
145057
145058 // open the base file handle in UNCOMPRESSED mode
145059 flags.SetCompression(FileCompressionType::UNCOMPRESSED);
145060
145061 auto registry = file_system_registry.atomic_load();
145062 auto &internal_filesystem = FindFileSystem(registry, file.path, opener);
145063
145064 // File handle gets created.
145065 unique_ptr<FileHandle> file_handle = nullptr;
145066
145067 // Handle caching logic.
145068 if (flags.GetCachingMode() != CachingMode::NO_CACHING) {
145069 auto caching_filesystem =
145070 make_shared_ptr<CachingFileSystemWrapper>(internal_filesystem, opener, flags.GetCachingMode());
145071 // caching filesystem's lifecycle is extended inside of caching file handle.
145072 file_handle = caching_filesystem->OpenFile(file, flags, opener);
145073 } else {
145074 file_handle = internal_filesystem.OpenFile(file, flags, opener);
145075 }
145076 if (!file_handle) {
145077 return nullptr;
145078 }
145079
145080 // Evaluate and apply compression option then.
145081 const auto context = !flags.MultiClientAccess() ? FileOpener::TryGetClientContext(opener) : QueryContext();
145082 if (file_handle->GetType() == FileType::FILE_TYPE_FIFO) {
145083 file_handle = PipeFileSystem::OpenPipe(context, std::move(file_handle));
145084 } else if (compression != FileCompressionType::UNCOMPRESSED) {
145085 auto entry = registry->compressed_fs.find(compression);
145086 if (entry == registry->compressed_fs.end()) {
145087 if (compression == FileCompressionType::ZSTD) {
145088 throw NotImplementedException(
145089 "Attempting to open a compressed file, but the compression type is not supported.\nConsider "
145090 "explicitly \"INSTALL parquet; LOAD parquet;\" to support this compression scheme");
145091 }
145092 throw NotImplementedException(
145093 "Attempting to open a compressed file, but the compression type is not supported");
145094 }
145095 auto &compressed_fs = *entry->second->file_system;
145096 file_handle = compressed_fs.OpenCompressedFile(context, std::move(file_handle), flags.OpenForWriting());
145097 }
145098 return file_handle;
145099}
static DUCKDB_API string Lower(const string &str)
Convert a string to lowercase.
Definition duckdb.cpp:109630
static DUCKDB_API bool EndsWith(const string &str, const string &suffix)
Returns true if the target string ends with the given suffix.
Definition duckdb.cpp:109384
@ FILE_TYPE_FIFO
FIFO named pipe.
Definition duckdb.hpp:8116

◆ SupportsOpenFileExtended()

bool duckdb::VirtualFileSystem::SupportsOpenFileExtended ( ) const
inlineoverrideprotectedvirtual

Reimplemented from duckdb::FileSystem.

144494 {
144495 return true;
144496 }

◆ ListFilesExtended()

bool duckdb::VirtualFileSystem::ListFilesExtended ( const string & directory,
const std::function< void(OpenFileInfo &info)> & callback,
optional_ptr< FileOpener > opener )
overrideprotectedvirtual

Reimplemented from duckdb::FileSystem.

145155 {
145156 return FindFileSystem(directory, opener).ListFiles(directory, callback, opener);
145157}

◆ SupportsListFilesExtended()

bool duckdb::VirtualFileSystem::SupportsListFilesExtended ( ) const
inlineoverrideprotectedvirtual

Reimplemented from duckdb::FileSystem.

144501 {
144502 return true;
144503 }

◆ GlobFilesExtended()

unique_ptr< MultiFileList > duckdb::VirtualFileSystem::GlobFilesExtended ( const string & path,
const FileGlobInput & input,
optional_ptr< FileOpener > opener )
overrideprotectedvirtual

Reimplemented from duckdb::FileSystem.

145199 {
145200 return FindFileSystem(path, opener).Glob(path, input, opener);
145201}

◆ SupportsGlobExtended()

bool duckdb::VirtualFileSystem::SupportsGlobExtended ( ) const
inlineoverrideprotectedvirtual

Reimplemented from duckdb::FileSystem.

144507 {
144508 return true;
144509 }

◆ FindFileSystem() [1/2]

FileSystem & duckdb::VirtualFileSystem::FindFileSystem ( const string & path,
optional_ptr< FileOpener > file_opener )
private
145270 {
145271 auto registry = file_system_registry.atomic_load();
145272 return FindFileSystem(registry, path, opener);
145273}

◆ FindFileSystem() [2/2]

FileSystem & duckdb::VirtualFileSystem::FindFileSystem ( shared_ptr< FileSystemRegistry > & registry,
const string & path,
optional_ptr< FileOpener > file_opener )
private
145276 {
145277 auto db_instance = FileOpener::TryGetDatabase(opener);
145278 auto fs = FindFileSystemInternal(*registry, path);
145279
145280 if (!fs && db_instance) {
145281 string required_extension;
145282
145283 for (const auto &entry : EXTENSION_FILE_PREFIXES) {
145284 if (StringUtil::StartsWith(path, entry.name)) {
145285 required_extension = entry.extension;
145286 }
145287 }
145288 if (!required_extension.empty() && db_instance && !db_instance->ExtensionIsLoaded(required_extension)) {
145289 if (!ExtensionHelper::CanAutoloadExtension(required_extension) ||
145290 !Settings::Get<AutoloadKnownExtensionsSetting>(*db_instance)) {
145291 auto error_message = "File " + path + " requires the extension " + required_extension + " to be loaded";
145292 error_message =
145293 ExtensionHelper::AddExtensionInstallHintToErrorMsg(*db_instance, error_message, required_extension);
145294 throw MissingExtensionException(error_message);
145295 }
145296 // an extension is required to read this file, but it is not loaded - try to load it
145297 ExtensionHelper::AutoLoadExtension(*db_instance, required_extension);
145298 }
145299 // refresh the registry after loading extensions
145300 registry = file_system_registry.atomic_load();
145301
145302 // Retry after having autoloaded
145303 fs = FindFileSystemInternal(*registry, path);
145304 }
145305
145306 if (!fs) {
145307 fs = registry->default_fs->file_system;
145308 }
145309 auto &disabled_file_systems = registry->disabled_file_systems;
145310 if (!disabled_file_systems.empty() && disabled_file_systems.find(fs->GetName()) != disabled_file_systems.end()) {
145311 throw PermissionException("File system %s has been disabled by configuration", fs->GetName());
145312 }
145313 return *fs;
145314}
static bool CanAutoloadExtension(const string &ext_name)
Definition duckdb.cpp:278428
static void AutoLoadExtension(ClientContext &context, const string &extension_name)
Autoload an extension (depending on config, potentially a nop. Throws when installation fails).
Definition duckdb.cpp:278659
static DUCKDB_API bool StartsWith(string str, string prefix)
Returns true if the target string starts with the given prefix.
Definition duckdb.cpp:109377

◆ FindFileSystemInternal()

optional_ptr< FileSystem > duckdb::VirtualFileSystem::FindFileSystemInternal ( FileSystemRegistry & registry,
const string & path )
private
145316 {
145317 optional_ptr<FileSystem> fs;
145318 for (auto &sub_system : registry.sub_systems) {
145319 auto &sub_fs = *sub_system->file_system;
145320 if (sub_fs.CanHandleFile(path)) {
145321 if (sub_fs.IsManuallySet()) {
145322 return sub_fs;
145323 }
145324 fs = sub_fs;
145325 }
145326 }
145327 return fs;
145328}

The documentation for this class was generated from the following file: