Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add hard_link_or_copy function to MartianRover #419

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions martian/src/stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,23 @@ impl MartianRover {
Ok(())
}
}

/// Creates a hard link (falls back to copy) to the given MartianFileType file
/// within the rover's file directory
///
/// # Arguments
///
/// * `src` - The path to the MartianFileType file
///
/// # Returns
///
/// * The path of the newly created link
pub fn hard_link_or_copy<M: MartianFileType>(&self, src: &M) -> Result<M, Error> {
macklin-10x marked this conversation as resolved.
Show resolved Hide resolved
let stem = src.as_ref().file_name().expect("Could not get file name.");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To aid in debugging, please include the full path contents in the expect message.

let dst: M = self.make_path(stem);
std::fs::hard_link(src, &dst).or_else(|_| std::fs::copy(src, &dst).map(|_| ()))?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here; we should include the input path as context in any error message emanating from here.

Ok(dst)
}
}

/// Two different kinds of marian stages. `MainOnly` stages only have a
Expand Down
Loading