From 803cd2808741acc12ba5f23d51aac5ee6a3b407c Mon Sep 17 00:00:00 2001
From: Gary Talent <gary@drinkingtea.net>
Date: Thu, 24 Mar 2022 20:45:22 -0500
Subject: [PATCH] [ox/fs] Add FileAddress::FileAddress(ox::String) and
 FileAddress::operator==(ox::String)

---
 deps/ox/src/ox/fs/filesystem/filelocation.cpp | 15 +++++++++++++++
 deps/ox/src/ox/fs/filesystem/filelocation.hpp |  4 ++++
 2 files changed, 19 insertions(+)

diff --git a/deps/ox/src/ox/fs/filesystem/filelocation.cpp b/deps/ox/src/ox/fs/filesystem/filelocation.cpp
index 76d76bd3..4290beed 100644
--- a/deps/ox/src/ox/fs/filesystem/filelocation.cpp
+++ b/deps/ox/src/ox/fs/filesystem/filelocation.cpp
@@ -28,6 +28,13 @@ FileAddress::FileAddress(uint64_t inode) noexcept {
 	m_type = FileAddressType::Inode;
 }
 
+FileAddress::FileAddress(const ox::String &path) noexcept {
+	auto pathSize = path.bytes() + 1;
+	m_data.path = new char[pathSize];
+	memcpy(m_data.path, path.c_str(), pathSize);
+	m_type = FileAddressType::Path;
+}
+
 FileAddress::FileAddress(char *path) noexcept {
 	auto pathSize = ox_strlen(path) + 1;
 	m_data.path = new char[pathSize];
@@ -93,6 +100,14 @@ FileAddress &FileAddress::operator=(FileAddress &&other) noexcept {
 	return *this;
 }
 
+bool FileAddress::operator==(const ox::String &path) const noexcept {
+	auto [p, err] = getPath();
+	if (err) {
+		return false;
+	}
+	return path == p;
+}
+
 void FileAddress::cleanup() noexcept {
 	if (m_type == FileAddressType::Path) {
 		safeDeleteArray(m_data.path);
diff --git a/deps/ox/src/ox/fs/filesystem/filelocation.hpp b/deps/ox/src/ox/fs/filesystem/filelocation.hpp
index 414c5e2b..20441f64 100644
--- a/deps/ox/src/ox/fs/filesystem/filelocation.hpp
+++ b/deps/ox/src/ox/fs/filesystem/filelocation.hpp
@@ -54,6 +54,8 @@ class FileAddress {
 
 		FileAddress(uint64_t inode) noexcept;
 
+		FileAddress(const ox::String &path) noexcept;
+
 		FileAddress(char *path) noexcept;
 
 		FileAddress(const char *path) noexcept;
@@ -64,6 +66,8 @@ class FileAddress {
 
 		FileAddress &operator=(FileAddress &&other) noexcept;
 
+		bool operator==(const ox::String &path) const noexcept;
+
 		[[nodiscard]]
 		constexpr FileAddressType type() const noexcept {
 			switch (m_type) {