Skip to content

Commit ce5f91d

Browse files
committed
[Rust] Make ProjectFile::path_on_disk return Option<PathBuf>
This is what the API is trying to express, we should just Do The Right Thing:tm:
1 parent 8cd9b51 commit ce5f91d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

rust/src/project/file.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use binaryninjacore_sys::{
99
BNProjectFileSetFolder, BNProjectFileSetName,
1010
};
1111
use std::fmt::Debug;
12-
use std::path::Path;
12+
use std::path::{Path, PathBuf};
1313
use std::ptr::{null_mut, NonNull};
1414
use std::time::SystemTime;
1515

@@ -37,8 +37,13 @@ impl ProjectFile {
3737
}
3838

3939
/// Get the path on disk to this file's contents
40-
pub fn path_on_disk(&self) -> String {
41-
unsafe { BnString::into_string(BNProjectFileGetPathOnDisk(self.handle.as_ptr())) }
40+
pub fn path_on_disk(&self) -> Option<PathBuf> {
41+
if !self.exists_on_disk() {
42+
return None;
43+
}
44+
let path_str =
45+
unsafe { BnString::into_string(BNProjectFileGetPathOnDisk(self.handle.as_ptr())) };
46+
Some(PathBuf::from(path_str))
4247
}
4348

4449
/// Check if this file's contents exist on disk

0 commit comments

Comments
 (0)