lib/file: Fix isOpen not being set properly when closing and reopening; add destructor
parent
39c5940200
commit
4cb1206839
|
@ -28,9 +28,13 @@ File::File(std::string path, char mode, uint64_t cursorPosition): mode(mode), pa
|
|||
std::filesystem::path filePath = path;
|
||||
this->size = ErrorOr<uint64_t>(std::filesystem::file_size(filePath));
|
||||
this->open();
|
||||
this->isOpen = true;
|
||||
}
|
||||
|
||||
File::~File() {
|
||||
if (this->isOpen) {
|
||||
this->fileStream.close();
|
||||
}
|
||||
}
|
||||
|
||||
void File::open(){
|
||||
switch(this->mode){
|
||||
|
@ -49,6 +53,7 @@ void File::open(){
|
|||
break;
|
||||
}
|
||||
|
||||
this->isOpen = this->fileStream.is_open();
|
||||
}
|
||||
|
||||
void File::close(){
|
||||
|
|
|
@ -45,6 +45,8 @@ class File {
|
|||
ErrorOr<uint64_t> size;
|
||||
|
||||
File() {};
|
||||
~File();
|
||||
|
||||
void open();
|
||||
void close();
|
||||
|
||||
|
|
Loading…
Reference in New Issue