forked from duckdb/duckdb-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilesystem_object.hpp
More file actions
39 lines (34 loc) · 1.23 KB
/
Copy pathfilesystem_object.hpp
File metadata and controls
39 lines (34 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//===----------------------------------------------------------------------===//
// DuckDB
//
// duckdb_python/filesystem_object.hpp
//
//
//===----------------------------------------------------------------------===//
#pragma once
#include "duckdb_python/registered_py_object.hpp"
#include "duckdb_python/pyfilesystem.hpp"
namespace duckdb {
class FileSystemObject : public RegisteredObject {
public:
explicit FileSystemObject(nb::object fs, vector<string> filenames_p)
: RegisteredObject(std::move(fs)), filenames(std::move(filenames_p)) {
}
~FileSystemObject() override {
nb::gil_scoped_acquire acquire;
// Assert that the 'obj' is a filesystem
D_ASSERT(duckdb::PyUtil::IsInstance(
obj, DuckDBPyConnection::ImportCache()->duckdb.filesystem.ModifiedMemoryFileSystem()));
// Destructors are implicitly noexcept: a Python exception escaping here (fsspec `_rm` raises
// KeyError for a missing entry) would std::terminate the process. Swallow it, mirroring
// ~PythonFileHandle / ~PythonFilesystem.
try {
for (auto &file : filenames) {
obj.attr("delete")(file);
}
} catch (...) { // NOLINT: intentional catch-all in a destructor
}
}
vector<string> filenames;
};
} // namespace duckdb