Support file renaming and support relative path in NtQueryAttributesFile

This commit is contained in:
Igor Pissolati
2025-10-19 17:48:14 -03:00
parent 9453123db0
commit 887b02c240
6 changed files with 64 additions and 5 deletions

View File

@@ -7,6 +7,12 @@ namespace utils
{
class file_handle
{
struct rename_information
{
std::filesystem::path old_filepath;
std::filesystem::path new_filepath;
};
public:
file_handle() = default;
@@ -80,8 +86,14 @@ namespace utils
return _ftelli64(this->file_);
}
void defer_rename(std::filesystem::path oldname, std::filesystem::path newname)
{
deferred_rename_ = {.old_filepath = std::move(oldname), .new_filepath = std::move(newname)};
}
private:
FILE* file_{};
std::optional<rename_information> deferred_rename_;
void release()
{
@@ -90,6 +102,13 @@ namespace utils
(void)fclose(this->file_);
this->file_ = {};
}
if (this->deferred_rename_)
{
std::error_code ec{};
std::filesystem::rename(this->deferred_rename_->old_filepath, this->deferred_rename_->new_filepath, ec);
this->deferred_rename_ = {};
}
}
};
}