File tree Expand file tree Collapse file tree 4 files changed +29
-1
lines changed
Expand file tree Collapse file tree 4 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 22name : posix
33" on " :
44 push :
5- branches : [main]
5+ branches : [main, file-path ]
66 pull_request :
77
88env :
Original file line number Diff line number Diff line change @@ -75,6 +75,14 @@ public:
7575 /// @returns The underlying implementation-defined handle
7676 native_handle_type native_handle() const noexcept;
7777
78+ /// Returns the managed path
79+ /// @returns The full path this entry manages
80+ operator std::filesystem::path() const noexcept;
81+
82+ /// Returns the managed path
83+ /// @returns The full path this entry manages
84+ std::filesystem::path path() const noexcept;
85+
7886 /// Moves the managed file to a given target, releasing
7987 /// ownership of the managed file; behaves like `std::filesystem::rename`
8088 /// even when moving between filesystems
Original file line number Diff line number Diff line change @@ -202,6 +202,18 @@ file::native_handle_type file::native_handle() const noexcept {
202202#endif
203203}
204204
205+ file::operator fs::path () const noexcept {
206+ #ifdef __linux__
207+ return fs::path (" /proc/self/fd" ) / std::to_string (native_handle ());
208+ #else
209+ return fs::path (" /dev/fd" ) / std::to_string (native_handle ());
210+ #endif
211+ }
212+
213+ fs::path file::path () const noexcept {
214+ return *this ;
215+ }
216+
205217void file::move (const fs::path& to) {
206218 // TODO: I couldn't figure out how to create a hard link to a file without
207219 // other hard links, so I just copy it even within the same file system
Original file line number Diff line number Diff line change @@ -87,6 +87,14 @@ TEST(file, create) {
8787 EXPECT_EQ (file_stat.st_mode & S_IFMT, S_IFREG); // Is a regular file
8888 EXPECT_EQ (file_stat.st_nlink , 0 ); // Has no hardlinks
8989#endif
90+
91+ EXPECT_TRUE (fs::exists (tmpfile));
92+ std::ofstream (tmpfile.path (), std::ios::binary) << " Hello, world!" ;
93+
94+ tmpfile.seekp (0 , std::ios::beg);
95+
96+ std::string content = std::string (std::istreambuf_iterator (tmpfile), {});
97+ EXPECT_EQ (content, " Hello, world!" );
9098}
9199
92100// / Tests multiple file creation
You can’t perform that action at this time.
0 commit comments