From e39ce55e4cc232d0d73b20d490c69bb6dd9a88a3 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Sun, 22 Jun 2025 18:57:26 -0400 Subject: [Rust] Make `ProjectFile::path_on_disk` return `Option` This is what the API is trying to express, we should just Do The Right Thing:tm: --- rust/src/project/file.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'rust/src/project') diff --git a/rust/src/project/file.rs b/rust/src/project/file.rs index 3b3e48f7..c06057d2 100644 --- a/rust/src/project/file.rs +++ b/rust/src/project/file.rs @@ -9,7 +9,7 @@ use binaryninjacore_sys::{ BNProjectFileSetFolder, BNProjectFileSetName, }; use std::fmt::Debug; -use std::path::Path; +use std::path::{Path, PathBuf}; use std::ptr::{null_mut, NonNull}; use std::time::SystemTime; @@ -37,8 +37,13 @@ impl ProjectFile { } /// Get the path on disk to this file's contents - pub fn path_on_disk(&self) -> String { - unsafe { BnString::into_string(BNProjectFileGetPathOnDisk(self.handle.as_ptr())) } + pub fn path_on_disk(&self) -> Option { + if !self.exists_on_disk() { + return None; + } + let path_str = + unsafe { BnString::into_string(BNProjectFileGetPathOnDisk(self.handle.as_ptr())) }; + Some(PathBuf::from(path_str)) } /// Check if this file's contents exist on disk -- cgit v1.3.1