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::FileSystem Class Referenceabstract
Inheritance diagram for duckdb::FileSystem:

Public Member Functions

virtual DUCKDB_API unique_ptr< FileHandleOpenFile (const string &path, FileOpenFlags flags, optional_ptr< FileOpener > opener=nullptr)
 
DUCKDB_API unique_ptr< FileHandleOpenFile (const OpenFileInfo &path, FileOpenFlags flags, optional_ptr< FileOpener > opener=nullptr)
 
virtual DUCKDB_API void Read (FileHandle &handle, void *buffer, int64_t nr_bytes, idx_t location)
 
virtual DUCKDB_API void Write (FileHandle &handle, void *buffer, int64_t nr_bytes, idx_t location)
 
virtual DUCKDB_API int64_t Read (FileHandle &handle, void *buffer, int64_t nr_bytes)
 
virtual DUCKDB_API int64_t Write (FileHandle &handle, void *buffer, int64_t nr_bytes)
 Write nr_bytes from the buffer into the file, moving the file pointer forward by nr_bytes.
 
virtual DUCKDB_API bool Trim (FileHandle &handle, idx_t offset_bytes, idx_t length_bytes)
 
virtual DUCKDB_API int64_t GetFileSize (FileHandle &handle)
 Returns the file size of a file handle, returns -1 on error.
 
virtual DUCKDB_API timestamp_t GetLastModifiedTime (FileHandle &handle)
 Returns the file last modified time of a file handle, returns timespec with zero on all attributes on error.
 
virtual DUCKDB_API string GetVersionTag (FileHandle &handle)
 
virtual DUCKDB_API FileType GetFileType (FileHandle &handle)
 Returns the file type of the attached handle.
 
virtual DUCKDB_API FileMetadata Stats (FileHandle &handle)
 Returns the file stats of the attached handle.
 
virtual DUCKDB_API void Truncate (FileHandle &handle, int64_t new_size)
 
virtual DUCKDB_API bool DirectoryExists (const string &directory, optional_ptr< FileOpener > opener=nullptr)
 Check if a directory exists.
 
virtual DUCKDB_API void CreateDirectory (const string &directory, optional_ptr< FileOpener > opener=nullptr)
 Create a directory if it does not exist.
 
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 void RemoveDirectory (const string &directory, optional_ptr< FileOpener > opener=nullptr)
 Recursively remove a directory and all files in it.
 
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 void MoveFile (const string &source, const string &target, optional_ptr< FileOpener > opener=nullptr)
 
virtual DUCKDB_API bool FileExists (const string &filename, optional_ptr< FileOpener > opener=nullptr)
 Check if a file exists.
 
virtual DUCKDB_API bool IsPipe (const string &filename, optional_ptr< FileOpener > opener=nullptr)
 Check if path is pipe.
 
virtual DUCKDB_API void RemoveFile (const string &filename, optional_ptr< FileOpener > opener=nullptr)
 Remove a file from disk.
 
virtual DUCKDB_API bool TryRemoveFile (const string &filename, optional_ptr< FileOpener > opener=nullptr)
 Remvoe a file from disk if it exists - if it does not exist, return false.
 
virtual DUCKDB_API void RemoveFiles (const vector< string > &filenames, optional_ptr< FileOpener > opener=nullptr)
 Remove multiple files from disk - does not error if any file does not exist.
 
virtual DUCKDB_API void FileSync (FileHandle &handle)
 Sync a file handle to disk.
 
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 string PathSeparator (const string &path)
 Path separator for path.
 
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< OpenFileInfoGlob (const string &path, FileOpener *opener=nullptr)
 Runs a glob on the file system, returning a list of matching files.
 
DUCKDB_API unique_ptr< MultiFileListGlob (const string &path, const FileGlobInput &input, optional_ptr< FileOpener > opener)
 
DUCKDB_API unique_ptr< MultiFileListGlobFileList (const string &path, const FileGlobInput &input=FileGlobOptions::DISALLOW_EMPTY)
 
DUCKDB_API vector< OpenFileInfoGlobFiles (const string &pattern, const FileGlobInput &input=FileGlobOptions::DISALLOW_EMPTY)
 
virtual DUCKDB_API void RegisterSubSystem (unique_ptr< FileSystem > sub_fs)
 registers a sub-file system to handle certain file name prefixes, e.g. http:// etc.
 
virtual DUCKDB_API void RegisterSubSystem (FileCompressionType compression_type, unique_ptr< FileSystem > fs)
 
virtual DUCKDB_API void UnregisterSubSystem (const string &name)
 Unregister a sub-filesystem by name.
 
virtual DUCKDB_API unique_ptr< FileSystemExtractSubSystem (const string &name)
 
virtual DUCKDB_API vector< string > ListSubSystems ()
 List registered sub-filesystems, including builtin ones.
 
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< FileHandleOpenCompressedFile (QueryContext context, unique_ptr< FileHandle > handle, bool write)
 
virtual DUCKDB_API std::string GetName () const =0
 Return the name of the filesytem. Used for forming diagnosis messages.
 
virtual DUCKDB_API void SetDisabledFileSystems (const vector< string > &names)
 
virtual DUCKDB_API bool SubSystemIsDisabled (const string &name)
 
virtual DUCKDB_API bool IsDisabledForPath (const string &path)
 Check if the filesystem that would handle this path is disabled.
 
virtual DUCKDB_API string CanonicalizePath (const string &path, optional_ptr< FileOpener > opener=nullptr)
 Canonicalize a path.
 
template<class TARGET >
TARGETCast ()
 
template<class TARGET >
const TARGETCast () const
 

Static Public Member Functions

static DUCKDB_API FileSystemGetFileSystem (ClientContext &context)
 
static DUCKDB_API FileSystemGetFileSystem (DatabaseInstance &db)
 
static DUCKDB_API FileSystemGet (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< FileSystemCreateLocal ()
 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)
 

Protected Member Functions

virtual DUCKDB_API unique_ptr< FileHandleOpenFileExtended (const OpenFileInfo &path, FileOpenFlags flags, optional_ptr< FileOpener > opener)
 
virtual DUCKDB_API bool SupportsOpenFileExtended () const
 
virtual DUCKDB_API bool ListFilesExtended (const string &directory, const std::function< void(OpenFileInfo &info)> &callback, optional_ptr< FileOpener > opener)
 
virtual DUCKDB_API bool SupportsListFilesExtended () const
 
virtual DUCKDB_API unique_ptr< MultiFileListGlobFilesExtended (const string &path, const FileGlobInput &input, optional_ptr< FileOpener > opener=nullptr)
 
virtual DUCKDB_API bool SupportsGlobExtended () const
 

Constructor & Destructor Documentation

◆ ~FileSystem()

duckdb::FileSystem::~FileSystem ( )
virtual
73614 {
73615}

Member Function Documentation

◆ GetFileSystem()

FileSystem & duckdb::FileSystem::GetFileSystem ( ClientContext context)
static
73617 {
73618 auto &client_data = ClientData::Get(context);
73619 return *client_data.client_file_system;
73620}

◆ OpenFile() [1/2]

unique_ptr< FileHandle > duckdb::FileSystem::OpenFile ( const string &  path,
FileOpenFlags  flags,
optional_ptr< FileOpener opener = nullptr 
)
virtual
73939 {
73940 if (SupportsOpenFileExtended()) {
73941 return OpenFileExtended(OpenFileInfo(path), flags, opener);
73942 }
73943 throw NotImplementedException("%s: OpenFile is not implemented!", GetName());
73944}
virtual DUCKDB_API std::string GetName() const =0
Return the name of the filesytem. Used for forming diagnosis messages.

◆ OpenFile() [2/2]

unique_ptr< FileHandle > duckdb::FileSystem::OpenFile ( const OpenFileInfo path,
FileOpenFlags  flags,
optional_ptr< FileOpener opener = nullptr 
)
73947 {
73948 if (SupportsOpenFileExtended()) {
73949 return OpenFileExtended(file, flags, opener);
73950 } else {
73951 return OpenFile(file.path, flags, opener);
73952 }
73953}

◆ Read() [1/2]

void duckdb::FileSystem::Read ( FileHandle handle,
void buffer,
int64_t  nr_bytes,
idx_t  location 
)
virtual

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 in duckdb::LocalFileSystem.

73967 {
73968 throw NotImplementedException("%s: Read (with location) is not implemented!", GetName());
73969}
Here is the call graph for this function:

◆ Write() [1/2]

void duckdb::FileSystem::Write ( FileHandle handle,
void buffer,
int64_t  nr_bytes,
idx_t  location 
)
virtual

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 in duckdb::LocalFileSystem.

73971 {
73972 throw NotImplementedException("%s: Write (with location) is not implemented!", GetName());
73973}
Here is the call graph for this function:

◆ Read() [2/2]

int64_t duckdb::FileSystem::Read ( FileHandle handle,
void buffer,
int64_t  nr_bytes 
)
virtual

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 in duckdb::CompressedFileSystem, and duckdb::LocalFileSystem.

73975 {
73976 throw NotImplementedException("%s: Read is not implemented!", GetName());
73977}
Here is the call graph for this function:

◆ Write() [2/2]

int64_t duckdb::FileSystem::Write ( FileHandle handle,
void buffer,
int64_t  nr_bytes 
)
virtual

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

Reimplemented in duckdb::CompressedFileSystem, and duckdb::LocalFileSystem.

73979 {
73980 throw NotImplementedException("%s: Write is not implemented!", GetName());
73981}
Here is the call graph for this function:

◆ Trim()

bool duckdb::FileSystem::Trim ( FileHandle handle,
idx_t  offset_bytes,
idx_t  length_bytes 
)
virtual

Excise a range of the file. The OS can drop pages from the page-cache, and the file-system is free to deallocate this range (sparse file support). Reads to the range will succeed but will return undefined data.

Reimplemented in duckdb::LocalFileSystem.

73983 {
73984 // This is not a required method. Derived FileSystems may optionally override/implement.
73985 return false;
73986}

◆ GetFileSize()

int64_t duckdb::FileSystem::GetFileSize ( FileHandle handle)
virtual

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

Reimplemented in duckdb::CompressedFileSystem, and duckdb::LocalFileSystem.

73988 {
73989 throw NotImplementedException("%s: GetFileSize is not implemented!", GetName());
73990}
Here is the call graph for this function:

◆ GetLastModifiedTime()

timestamp_t duckdb::FileSystem::GetLastModifiedTime ( FileHandle handle)
virtual

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

Reimplemented in duckdb::LocalFileSystem.

73992 {
73993 throw NotImplementedException("%s: GetLastModifiedTime is not implemented!", GetName());
73994}
Here is the call graph for this function:

◆ GetVersionTag()

string duckdb::FileSystem::GetVersionTag ( FileHandle handle)
virtual

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

Reimplemented in duckdb::LocalFileSystem.

73996 {
73997 // Used to check cache invalidation for httpfs files with an ETag in CachingFileSystem
73998 return "";
73999}

◆ GetFileType()

FileType duckdb::FileSystem::GetFileType ( FileHandle handle)
virtual

Returns the file type of the attached handle.

Reimplemented in duckdb::LocalFileSystem.

74001 {
74003}
@ FILE_TYPE_INVALID
Unknown or invalid file handle.

◆ Stats()

FileMetadata duckdb::FileSystem::Stats ( FileHandle handle)
virtual

Returns the file stats of the attached handle.

Reimplemented in duckdb::LocalFileSystem.

74005 {
74006 throw NotImplementedException("%s: Stats is not implemented!", GetName());
74007}
Here is the call graph for this function:

◆ Truncate()

void duckdb::FileSystem::Truncate ( FileHandle handle,
int64_t  new_size 
)
virtual

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 in duckdb::LocalFileSystem.

74009 {
74010 throw NotImplementedException("%s: Truncate is not implemented!", GetName());
74011}
Here is the call graph for this function:

◆ DirectoryExists()

bool duckdb::FileSystem::DirectoryExists ( const string &  directory,
optional_ptr< FileOpener opener = nullptr 
)
virtual

Check if a directory exists.

Reimplemented in duckdb::LocalFileSystem.

74013 {
74014 throw NotImplementedException("%s: DirectoryExists is not implemented!", GetName());
74015}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateDirectory()

void duckdb::FileSystem::CreateDirectory ( const string &  directory,
optional_ptr< FileOpener opener = nullptr 
)
virtual

Create a directory if it does not exist.

Reimplemented in duckdb::LocalFileSystem.

74017 {
74018 throw NotImplementedException("%s: CreateDirectory is not implemented!", GetName());
74019}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateDirectoriesRecursive()

void duckdb::FileSystem::CreateDirectoriesRecursive ( const string &  path,
optional_ptr< FileOpener opener = nullptr 
)
virtual

Helper function that uses DirectoryExists and CreateDirectory to ensure all directories in path are created.

74021 {
74022 // To avoid hitting directories we have no permission for when using allowed_directories + enable_external_access,
74023 // we construct the list of directories to be created depth-first. This avoids calling DirectoryExists on a parent
74024 // dir that is not in the allowed_directories list
74025
74026 // Walk up from the full path until we find a prefix that already exists, collecting
74027 // non-existing ancestors along the way. Stop descending when segments are exhausted
74028 // (to avoid Path::Parent() generating ".." paths past the root/base).
74029 auto parsed = Path::FromString(path);
74030 vector<string> dirs_to_create;
74031 while (!parsed.GetPathSegments().empty() && !DirectoryExists(parsed.ToString())) {
74032 dirs_to_create.push_back(parsed.ToString());
74033 parsed = parsed.Parent();
74034 }
74035 // If all segments were non-existing, also check the base itself (e.g. "C:/" on an unknown drive)
74036 if (!parsed.GetPathSegments().empty()) {
74037 // broke because DirectoryExists returned true — nothing more needed
74038 } else if (!DirectoryExists(parsed.ToString())) {
74039 dirs_to_create.push_back(parsed.ToString());
74040 }
74041
74042 // Create directories shallowest to deepest
74043 for (auto riter = dirs_to_create.rbegin(); riter != dirs_to_create.rend(); ++riter) {
74044 CreateDirectory(*riter);
74045 }
74046}
virtual DUCKDB_API void CreateDirectory(const string &directory, optional_ptr< FileOpener > opener=nullptr)
Create a directory if it does not exist.
Definition duckdb.cpp:74017
virtual DUCKDB_API bool DirectoryExists(const string &directory, optional_ptr< FileOpener > opener=nullptr)
Check if a directory exists.
Definition duckdb.cpp:74013
Here is the call graph for this function:

◆ RemoveDirectory()

void duckdb::FileSystem::RemoveDirectory ( const string &  directory,
optional_ptr< FileOpener opener = nullptr 
)
virtual

Recursively remove a directory and all files in it.

Reimplemented in duckdb::LocalFileSystem.

74048 {
74049 throw NotImplementedException("%s: RemoveDirectory is not implemented!", GetName());
74050}
Here is the call graph for this function:

◆ ListFiles() [1/2]

bool duckdb::FileSystem::ListFiles ( const string &  directory,
const std::function< void(const string &, bool)> &  callback,
FileOpener opener = nullptr 
)
virtual

List files in a directory, invoking the callback method for each one with (filename, is_dir)

74064 {
74065 if (SupportsListFilesExtended()) {
74066 return ListFilesExtended(
74067 directory,
74068 [&](const OpenFileInfo &info) {
74069 bool is_dir = IsDirectory(info);
74070 callback(info.path, is_dir);
74071 },
74072 opener);
74073 }
74074 throw NotImplementedException("%s: ListFiles is not implemented!", GetName());
74075}
Here is the call graph for this function:

◆ ListFiles() [2/2]

bool duckdb::FileSystem::ListFiles ( const string &  directory,
const std::function< void(OpenFileInfo &info)> &  callback,
optional_ptr< FileOpener opener = nullptr 
)
74078 {
74079 if (SupportsListFilesExtended()) {
74080 return ListFilesExtended(directory, callback, opener);
74081 } else {
74082 return ListFiles(
74083 directory,
74084 [&](const string &path, bool is_dir) {
74085 OpenFileInfo info(path);
74086 if (is_dir) {
74087 info.extended_info = make_shared_ptr<ExtendedOpenFileInfo>();
74088 info.extended_info->options["type"] = "directory";
74089 }
74090 callback(info);
74091 },
74092 opener.get());
74093 }
74094}
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,...
Definition duckdb.cpp:74063

◆ MoveFile()

void duckdb::FileSystem::MoveFile ( const string &  source,
const string &  target,
optional_ptr< FileOpener opener = nullptr 
)
virtual

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

Reimplemented in duckdb::LocalFileSystem.

74096 {
74097 throw NotImplementedException("%s: MoveFile is not implemented!", GetName());
74098}
Here is the call graph for this function:

◆ FileExists()

bool duckdb::FileSystem::FileExists ( const string &  filename,
optional_ptr< FileOpener opener = nullptr 
)
virtual

Check if a file exists.

Reimplemented in duckdb::LocalFileSystem.

74100 {
74101 throw NotImplementedException("%s: FileExists is not implemented!", GetName());
74102}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsPipe()

bool duckdb::FileSystem::IsPipe ( const string &  filename,
optional_ptr< FileOpener opener = nullptr 
)
virtual

Check if path is pipe.

Reimplemented in duckdb::LocalFileSystem.

74104 {
74105 return false;
74106}

◆ RemoveFile()

void duckdb::FileSystem::RemoveFile ( const string &  filename,
optional_ptr< FileOpener opener = nullptr 
)
virtual

Remove a file from disk.

Reimplemented in duckdb::LocalFileSystem.

74108 {
74109 throw NotImplementedException("%s: RemoveFile is not implemented!", GetName());
74110}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TryRemoveFile()

bool duckdb::FileSystem::TryRemoveFile ( const string &  filename,
optional_ptr< FileOpener opener = nullptr 
)
virtual

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

74112 {
74113 if (FileExists(filename, opener)) {
74114 RemoveFile(filename, opener);
74115 return true;
74116 }
74117 return false;
74118}
virtual DUCKDB_API void RemoveFile(const string &filename, optional_ptr< FileOpener > opener=nullptr)
Remove a file from disk.
Definition duckdb.cpp:74108
virtual DUCKDB_API bool FileExists(const string &filename, optional_ptr< FileOpener > opener=nullptr)
Check if a file exists.
Definition duckdb.cpp:74100
Here is the call graph for this function:
Here is the caller graph for this function:

◆ RemoveFiles()

void duckdb::FileSystem::RemoveFiles ( const vector< string > &  filenames,
optional_ptr< FileOpener opener = nullptr 
)
virtual

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

74120 {
74121 for (const auto &filename : filenames) {
74122 TryRemoveFile(filename, opener);
74123 }
74124}
virtual DUCKDB_API bool TryRemoveFile(const string &filename, optional_ptr< FileOpener > opener=nullptr)
Remvoe a file from disk if it exists - if it does not exist, return false.
Definition duckdb.cpp:74112
Here is the call graph for this function:

◆ FileSync()

void duckdb::FileSystem::FileSync ( FileHandle handle)
virtual

Sync a file handle to disk.

Reimplemented in duckdb::LocalFileSystem.

74126 {
74127 throw NotImplementedException("%s: FileSync is not implemented!", GetName());
74128}
Here is the call graph for this function:

◆ SetWorkingDirectory()

void duckdb::FileSystem::SetWorkingDirectory ( const string &  path)
static

Sets the working directory.

73645 {
73646 if (chdir(path.c_str()) != 0) {
73647 throw IOException("Could not change working directory!");
73648 }
73649}

◆ GetWorkingDirectory()

string duckdb::FileSystem::GetWorkingDirectory ( )
static

Gets the working directory.

73685 {
73686 auto buffer = make_unsafe_uniq_array<char>(PATH_MAX);
73687 char *ret = getcwd(buffer.get(), PATH_MAX);
73688 if (!ret) {
73689 throw IOException("Could not get working directory!");
73690 }
73691 return string(buffer.get());
73692}
cv::String getcwd()
Here is the call graph for this function:

◆ GetHomeDirectory() [1/2]

string duckdb::FileSystem::GetHomeDirectory ( optional_ptr< FileOpener opener)
static

Gets the users home directory.

73850 {
73851 // read the home_directory setting first, if it is set
73852 if (opener) {
73853 Value result;
73854 if (opener->TryGetCurrentSetting("home_directory", result)) {
73855 if (!result.IsNull() && !result.ToString().empty()) {
73856 return result.ToString();
73857 }
73858 }
73859 }
73860 // fallback to the default home directories for the specified system
73861#ifdef DUCKDB_WINDOWS
73862 return FileSystem::GetEnvVariable("USERPROFILE");
73863#else
73864 return FileSystem::GetEnvVariable("HOME");
73865#endif
73866}
static DUCKDB_API string GetEnvVariable(const string &name)
Returns the value of an environment variable - or the empty string if it is not set.
Definition duckdb.cpp:73628
Here is the call graph for this function:

◆ GetHomeDirectory() [2/2]

string duckdb::FileSystem::GetHomeDirectory ( )
virtual

Gets the users home directory.

73868 {
73869 return GetHomeDirectory(nullptr);
73870}
virtual DUCKDB_API string GetHomeDirectory()
Gets the users home directory.
Definition duckdb.cpp:73868
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ExpandPath() [1/2]

string duckdb::FileSystem::ExpandPath ( const string &  path,
optional_ptr< FileOpener opener 
)
static

Expands a given path, including e.g. expanding the home directory of the user.

73909 {
73910 if (path.empty()) {
73911 return path;
73912 }
73913 if (path[0] == '~') {
73914 return GetHomeDirectory(opener) + path.substr(1);
73915 }
73916 // handle file URIs
73917 auto file_offset = GetFileUrlOffset(path);
73918 if (file_offset > 0) {
73919 return path.substr(file_offset);
73920 }
73921 return path;
73922}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ExpandPath() [2/2]

string duckdb::FileSystem::ExpandPath ( const string &  path)
virtual

Expands a given path, including e.g. expanding the home directory of the user.

73924 {
73925 return FileSystem::ExpandPath(path, nullptr);
73926}
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.
Definition duckdb.cpp:73909
Here is the call graph for this function:

◆ GetAvailableMemory()

optional_idx duckdb::FileSystem::GetAvailableMemory ( )
static

Returns the system-available memory in bytes. Returns DConstants::INVALID_INDEX if the system function fails.

73651 {
73652 errno = 0;
73653
73654#ifdef __MVS__
73655 struct rlimit limit;
73656 int rlim_rc = getrlimit(RLIMIT_AS, &limit);
73657 idx_t max_memory = MinValue<idx_t>(limit.rlim_max, UINTPTR_MAX);
73658#else
73659 idx_t max_memory = MinValue<idx_t>((idx_t)sysconf(_SC_PHYS_PAGES) * (idx_t)sysconf(_SC_PAGESIZE), UINTPTR_MAX);
73660#endif
73661 if (errno != 0) {
73662 return optional_idx();
73663 }
73664 return max_memory;
73665}

◆ GetAvailableDiskSpace()

optional_idx duckdb::FileSystem::GetAvailableDiskSpace ( const string &  path)
static

Returns the space available on the disk. Returns DConstants::INVALID_INDEX if the information was not available.

73667 {
73668 struct statvfs vfs;
73669
73670 auto ret = statvfs(path.c_str(), &vfs);
73671 if (ret == -1) {
73672 return optional_idx();
73673 }
73674 auto block_size = vfs.f_frsize;
73675 // These are the blocks available for creating new files or extending existing ones
73676 auto available_blocks = vfs.f_bfree;
73677 idx_t available_disk_space = DConstants::INVALID_INDEX;
73678 if (!TryMultiplyOperator::Operation(static_cast<idx_t>(block_size), static_cast<idx_t>(available_blocks),
73679 available_disk_space)) {
73680 return optional_idx();
73681 }
73682 return available_disk_space;
73683}
static constexpr const idx_t INVALID_INDEX
The value used to signify an invalid index entry.
Definition duckdb.hpp:1117

◆ PathSeparator()

string duckdb::FileSystem::PathSeparator ( const string &  path)
virtual

Path separator for path.

73641 {
73642 return "/";
73643}
Here is the caller graph for this function:

◆ IsPathAbsolute()

bool duckdb::FileSystem::IsPathAbsolute ( const string &  path)
virtual

Checks if path is is an absolute path.

Reimplemented in duckdb::LocalFileSystem.

73636 {
73637 auto path_separator = PathSeparator(path);
73638 return PathMatched(path, path_separator) || StringUtil::StartsWith(path, "file:/");
73639}
virtual DUCKDB_API string PathSeparator(const string &path)
Path separator for path.
Definition duckdb.cpp:73641
static DUCKDB_API bool StartsWith(string str, string prefix)
Returns true if the target string starts with the given prefix.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ JoinPath() [1/2]

string duckdb::FileSystem::JoinPath ( const string &  a,
const string &  path 
)

Join two paths together.

73803 {
73804 // FIXME: sanitize paths
73805 return a.empty() ? b : a + PathSeparator(a) + b;
73806}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ JoinPath() [2/2]

template<typename... ARGS>
string duckdb::FileSystem::JoinPath ( const string &  a,
const string &  b,
ARGS...  args 
)
inline
8305 {
8306 return JoinPath(JoinPath(a, b), args...);
8307 }
DUCKDB_API string JoinPath(const string &a, const string &path)
Join two paths together.
Definition duckdb.cpp:73803

◆ ConvertSeparators()

string duckdb::FileSystem::ConvertSeparators ( const string &  path)

Convert separators in a path to the local separators (e.g. convert "/" into \ on windows)

73808 {
73809 auto separator_str = PathSeparator(path);
73810 char separator = separator_str[0];
73811 if (separator == '/') {
73812 // on unix-based systems we only accept / as a separator
73813 return path;
73814 }
73815 // on windows-based systems we accept both
73816 return StringUtil::Replace(path, "/", separator_str);
73817}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ExtractBaseName()

string duckdb::FileSystem::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')

73830 {
73831 if (path.empty()) {
73832 return string();
73833 }
73834 auto vec = StringUtil::Split(ExtractName(path), ".");
73835 D_ASSERT(!vec.empty());
73836 return vec[0];
73837}
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....
Definition duckdb.cpp:73819
static DUCKDB_API vector< string > Split(const string &str, char delimiter)
Split the input string based on newline char.
Here is the call graph for this function:

◆ ExtractExtension()

string duckdb::FileSystem::ExtractExtension ( const string &  path)

Extract the extension of a file (e.g. if the input is lib/example.dll the extension is 'dll')

73839 {
73840 if (path.empty()) {
73841 return string();
73842 }
73843 auto vec = StringUtil::Split(ExtractName(path), ".");
73844 if (vec.size() < 2) {
73845 return string();
73846 }
73847 return vec.back();
73848}
Here is the call graph for this function:

◆ ExtractName()

string duckdb::FileSystem::ExtractName ( const string &  path)

Extract the name of a file (e.g if the input is lib/example.dll the name is 'example.dll')

73819 {
73820 if (path.empty()) {
73821 return string();
73822 }
73823 auto normalized_path = ConvertSeparators(path);
73824 auto sep = PathSeparator(path);
73825 auto splits = StringUtil::Split(normalized_path, sep);
73826 D_ASSERT(!splits.empty());
73827 return splits.back();
73828}
DUCKDB_API string ConvertSeparators(const string &path)
Convert separators in a path to the local separators (e.g. convert "/" into \ on windows)
Definition duckdb.cpp:73808
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetEnvVariable()

string duckdb::FileSystem::GetEnvVariable ( const string &  name)
static

Returns the value of an environment variable - or the empty string if it is not set.

73628 {
73629 const char *env = getenv(name.c_str());
73630 if (!env) {
73631 return string();
73632 }
73633 return env;
73634}
Here is the caller graph for this function:

◆ HasGlob()

bool duckdb::FileSystem::HasGlob ( const string &  str)
static

Whether there is a glob in the string.

74130 {
74131 for (idx_t i = 0; i < str.size(); i++) {
74132 switch (str[i]) {
74133 case '*':
74134 case '?':
74135 case '[':
74136 return true;
74137 default:
74138 break;
74139 }
74140 }
74141 return false;
74142}

◆ Glob() [1/2]

vector< OpenFileInfo > duckdb::FileSystem::Glob ( const string &  path,
FileOpener opener = nullptr 
)
virtual

Runs a glob on the file system, returning a list of matching files.

74144 {
74145 if (SupportsGlobExtended()) {
74146 auto result = GlobFilesExtended(path, FileGlobOptions::ALLOW_EMPTY, opener);
74147 return result->GetAllFiles();
74148 }
74149 throw NotImplementedException("%s: Glob is not implemented!", GetName());
74150}
Here is the call graph for this function:

◆ Glob() [2/2]

unique_ptr< MultiFileList > duckdb::FileSystem::Glob ( const string &  path,
const FileGlobInput input,
optional_ptr< FileOpener opener 
)
74153 {
74154 if (!SupportsGlobExtended()) {
74155 auto result = Glob(path, opener.get());
74156 return make_uniq<SimpleMultiFileList>(std::move(result));
74157 } else {
74158 return GlobFilesExtended(path, input, opener);
74159 }
74160}
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.
Definition duckdb.cpp:74144

◆ GlobFileList()

unique_ptr< MultiFileList > duckdb::FileSystem::GlobFileList ( const string &  path,
const FileGlobInput input = FileGlobOptions::DISALLOW_EMPTY 
)
74203 {
74204 auto result = GlobFilesExtended(pattern, input);
74205 if (result->IsEmpty()) {
74206 if (input.behavior == FileGlobOptions::FALLBACK_GLOB && !HasGlob(pattern)) {
74207 // if we have no glob in the pattern and we have an extension, we try to glob
74208 if (!HasGlob(pattern)) {
74209 if (input.extension.empty()) {
74210 throw InternalException("FALLBACK_GLOB requires an extension to be specified");
74211 }
74212 string new_pattern = JoinPath(JoinPath(pattern, "**"), "*." + input.extension);
74213 result = GlobFileList(new_pattern, FileGlobOptions::ALLOW_EMPTY);
74214 if (!result->IsEmpty()) {
74215 // we found files by globbing the target as if it was a directory - return them
74216 return result;
74217 }
74218 }
74219 }
74220 if (input.behavior == FileGlobOptions::FALLBACK_GLOB || input.behavior == FileGlobOptions::DISALLOW_EMPTY) {
74221 throw IOException("No files found that match the pattern \"%s\"", pattern);
74222 }
74223 }
74224 return result;
74225}
static DUCKDB_API bool HasGlob(const string &str)
Whether there is a glob in the string.
Definition duckdb.cpp:74130

◆ GlobFiles()

vector< OpenFileInfo > duckdb::FileSystem::GlobFiles ( const string &  pattern,
const FileGlobInput input = FileGlobOptions::DISALLOW_EMPTY 
)
74227 {
74228 auto file_list = GlobFileList(pattern, input);
74229 return file_list->GetAllFiles();
74230}

◆ RegisterSubSystem() [1/2]

void duckdb::FileSystem::RegisterSubSystem ( unique_ptr< FileSystem sub_fs)
virtual

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

74167 {
74168 throw NotImplementedException("%s: Can't register a sub system on a non-virtual file system", GetName());
74169}
Here is the call graph for this function:

◆ RegisterSubSystem() [2/2]

void duckdb::FileSystem::RegisterSubSystem ( FileCompressionType  compression_type,
unique_ptr< FileSystem fs 
)
virtual
74171 {
74172 throw NotImplementedException("%s: Can't register a sub system on a non-virtual file system", GetName());
74173}

◆ UnregisterSubSystem()

void duckdb::FileSystem::UnregisterSubSystem ( const string &  name)
virtual

Unregister a sub-filesystem by name.

74175 {
74176 throw NotImplementedException("%s: Can't unregister a sub system on a non-virtual file system", GetName());
74177}
Here is the call graph for this function:

◆ ExtractSubSystem()

unique_ptr< FileSystem > duckdb::FileSystem::ExtractSubSystem ( const string &  name)
virtual
74179 {
74180 throw NotImplementedException("%s: Can't extract a sub system on a non-virtual file system", GetName());
74181}

◆ ListSubSystems()

vector< string > duckdb::FileSystem::ListSubSystems ( )
virtual

List registered sub-filesystems, including builtin ones.

74195 {
74196 throw NotImplementedException("%s: Can't list sub systems on a non-virtual file system", GetName());
74197}
Here is the call graph for this function:

◆ CanHandleFile()

bool duckdb::FileSystem::CanHandleFile ( const string &  fpath)
virtual

Whether or not a sub-system can handle a specific file path.

Reimplemented in duckdb::LocalFileSystem.

74199 {
74200 throw NotImplementedException("%s: CanHandleFile is not implemented!", GetName());
74201}
Here is the call graph for this function:

◆ Seek()

void duckdb::FileSystem::Seek ( FileHandle handle,
idx_t  location 
)
virtual

Set the file pointer of a file handle to a specified location. Reads and writes will happen from this location.

Reimplemented in duckdb::LocalFileSystem.

74232 {
74233 throw NotImplementedException("%s: Seek is not implemented!", GetName());
74234}
Here is the call graph for this function:

◆ Reset()

void duckdb::FileSystem::Reset ( FileHandle handle)
virtual

Reset a file to the beginning (equivalent to Seek(handle, 0) for simple files)

Reimplemented in duckdb::CompressedFileSystem.

74236 {
74237 handle.Seek(0);
74238}

◆ SeekPosition()

idx_t duckdb::FileSystem::SeekPosition ( FileHandle handle)
virtual

Reimplemented in duckdb::LocalFileSystem.

74240 {
74241 throw NotImplementedException("%s: SeekPosition is not implemented!", GetName());
74242}

◆ IsManuallySet()

bool duckdb::FileSystem::IsManuallySet ( )
virtual

If FS was manually set by the user.

74248 {
74249 return false;
74250}

◆ CanSeek()

bool duckdb::FileSystem::CanSeek ( )
virtual

Whether or not we can seek into the file.

Reimplemented in duckdb::CompressedFileSystem, and duckdb::LocalFileSystem.

74244 {
74245 throw NotImplementedException("%s: CanSeek is not implemented!", GetName());
74246}
Here is the call graph for this function:

◆ OnDiskFile()

bool duckdb::FileSystem::OnDiskFile ( FileHandle handle)
virtual

Whether or not the FS handles plain files on disk. This is relevant for certain optimizations, as random reads in a file on-disk are much cheaper than e.g. random reads in a file over the network

Reimplemented in duckdb::CompressedFileSystem, and duckdb::LocalFileSystem.

74256 {
74257 throw NotImplementedException("%s: OnDiskFile is not implemented!", GetName());
74258}
Here is the call graph for this function:

◆ OpenCompressedFile()

unique_ptr< FileHandle > duckdb::FileSystem::OpenCompressedFile ( QueryContext  context,
unique_ptr< FileHandle handle,
bool  write 
)
virtual
74252 {
74253 throw NotImplementedException("%s: OpenCompressedFile is not implemented!", GetName());
74254}

◆ CreateLocal()

unique_ptr< FileSystem > duckdb::FileSystem::CreateLocal ( )
static

Create a LocalFileSystem.

80214 {
80215 return make_uniq<LocalFileSystem>();
80216}

◆ GetName()

virtual DUCKDB_API std::string duckdb::FileSystem::GetName ( ) const
pure virtual

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

Implemented in duckdb::GZipFileSystem, and duckdb::LocalFileSystem.

Here is the caller graph for this function:

◆ IsRemoteFile() [1/2]

bool duckdb::FileSystem::IsRemoteFile ( const string &  path)
static

Whether or not a file is remote or local, based only on file path.

74413 {
74414 string extension = "";
74415 return IsRemoteFile(path, extension);
74416}
static DUCKDB_API bool IsRemoteFile(const string &path)
Whether or not a file is remote or local, based only on file path.
Definition duckdb.cpp:74413
Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsRemoteFile() [2/2]

bool duckdb::FileSystem::IsRemoteFile ( const string &  path,
string &  extension 
)
static
74418 {
74419 for (const auto &entry : EXTENSION_FILE_PREFIXES) {
74420 if (StringUtil::StartsWith(path, entry.name)) {
74421 extension = entry.extension;
74422 return true;
74423 }
74424 }
74425 return false;
74426}

◆ SetDisabledFileSystems()

void duckdb::FileSystem::SetDisabledFileSystems ( const vector< string > &  names)
virtual
74183 {
74184 throw NotImplementedException("%s: Can't disable file systems on a non-virtual file system", GetName());
74185}

◆ SubSystemIsDisabled()

bool duckdb::FileSystem::SubSystemIsDisabled ( const string &  name)
virtual
74187 {
74188 throw NotImplementedException("%s: Non-virtual file system does not have subsystems", GetName());
74189}

◆ IsDisabledForPath()

bool duckdb::FileSystem::IsDisabledForPath ( const string &  path)
virtual

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

74191 {
74192 throw NotImplementedException("%s: Non-virtual file system does not have subsystems", GetName());
74193}
Here is the call graph for this function:

◆ IsDirectory()

bool duckdb::FileSystem::IsDirectory ( const OpenFileInfo info)
static
74052 {
74053 if (!info.extended_info) {
74054 return false;
74055 }
74056 auto entry = info.extended_info->options.find("type");
74057 if (entry == info.extended_info->options.end()) {
74058 return false;
74059 }
74060 return StringValue::Get(entry->second) == "directory";
74061}

◆ CanonicalizePath()

string duckdb::FileSystem::CanonicalizePath ( const string &  path,
optional_ptr< FileOpener opener = nullptr 
)
virtual

Canonicalize a path.

Reimplemented in duckdb::LocalFileSystem.

74428 {
74429 if (IsRemoteFile(path_p)) {
74430 // don't canonicalize remote paths
74431 return path_p;
74432 }
74433 auto path_sep = PathSeparator(path_p);
74434 auto elements = StringUtil::Split(path_p, path_sep);
74435
74436 deque<string> path_stack;
74437 string result;
74438 for (idx_t i = 0; i < elements.size(); i++) {
74439 if (elements[i].empty() || elements[i] == ".") {
74440 // we ignore empty and `.`
74441 continue;
74442 }
74443 if (elements[i] == "..") {
74444 // .. pops from stack if possible, if already at root its ignored
74445 if (!path_stack.empty()) {
74446 path_stack.pop_back();
74447 }
74448 } else {
74449 path_stack.push_back(elements[i]);
74450 }
74451 }
74452 // we lost the leading / in the split/loop so lets put it back
74453 if (path_p[0] == '/') {
74454 result = "/";
74455 }
74456 while (!path_stack.empty()) {
74457 result += path_stack.front();
74458 path_stack.pop_front();
74459 if (!path_stack.empty()) {
74460 result += path_sep;
74461 }
74462 }
74463
74464 return result;
74465}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ OpenFileExtended()

unique_ptr< FileHandle > duckdb::FileSystem::OpenFileExtended ( const OpenFileInfo path,
FileOpenFlags  flags,
optional_ptr< FileOpener opener 
)
protectedvirtual
73930 {
73931 throw NotImplementedException("%s: OpenFileExtended is not implemented!", GetName());
73932}

◆ SupportsOpenFileExtended()

bool duckdb::FileSystem::SupportsOpenFileExtended ( ) const
protectedvirtual
73955 {
73956 return false;
73957}

◆ ListFilesExtended()

bool duckdb::FileSystem::ListFilesExtended ( const string &  directory,
const std::function< void(OpenFileInfo &info)> &  callback,
optional_ptr< FileOpener opener 
)
protectedvirtual
73935 {
73936 throw NotImplementedException("%s: ListFilesExtended is not implemented!", GetName());
73937}

◆ SupportsListFilesExtended()

bool duckdb::FileSystem::SupportsListFilesExtended ( ) const
protectedvirtual
73959 {
73960 return false;
73961}

◆ GlobFilesExtended()

unique_ptr< MultiFileList > duckdb::FileSystem::GlobFilesExtended ( const string &  path,
const FileGlobInput input,
optional_ptr< FileOpener opener = nullptr 
)
protectedvirtual
74163 {
74164 throw NotImplementedException("%s: GlobFilesExtended is not implemented!", GetName());
74165}

◆ SupportsGlobExtended()

bool duckdb::FileSystem::SupportsGlobExtended ( ) const
protectedvirtual
73963 {
73964 return false;
73965}

◆ Cast() [1/2]

template<class TARGET >
TARGET & duckdb::FileSystem::Cast ( )
inline
8401 {
8402 DynamicCastCheck<TARGET>(this);
8403 return reinterpret_cast<TARGET &>(*this);
8404 }

◆ Cast() [2/2]

template<class TARGET >
const TARGET & duckdb::FileSystem::Cast ( ) const
inline
8407 {
8408 DynamicCastCheck<TARGET>(this);
8409 return reinterpret_cast<const TARGET &>(*this);
8410 }

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